19e0fc027SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
39e0fc027SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
49e0fc027SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
59e0fc027SAndrew Rist  * distributed with this work for additional information
69e0fc027SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
79e0fc027SAndrew Rist  * to you under the Apache License, Version 2.0 (the
89e0fc027SAndrew Rist  * "License"); you may not use this file except in compliance
99e0fc027SAndrew Rist  * with the License.  You may obtain a copy of the License at
109e0fc027SAndrew Rist  *
119e0fc027SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
129e0fc027SAndrew Rist  *
139e0fc027SAndrew Rist  * Unless required by applicable law or agreed to in writing,
149e0fc027SAndrew Rist  * software distributed under the License is distributed on an
159e0fc027SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
169e0fc027SAndrew Rist  * KIND, either express or implied.  See the License for the
179e0fc027SAndrew Rist  * specific language governing permissions and limitations
189e0fc027SAndrew Rist  * under the License.
199e0fc027SAndrew Rist  *
209e0fc027SAndrew Rist  *************************************************************/
219e0fc027SAndrew Rist 
229e0fc027SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_filter.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <vcl/graph.hxx>
28cdf0e10cSrcweir #include <vcl/bmpacc.hxx>
29cdf0e10cSrcweir #include <svtools/fltcall.hxx>
30cdf0e10cSrcweir 
31cdf0e10cSrcweir //============================ PBMReader ==================================
32cdf0e10cSrcweir 
33cdf0e10cSrcweir class PBMReader {
34cdf0e10cSrcweir 
35cdf0e10cSrcweir private:
36cdf0e10cSrcweir 
37cdf0e10cSrcweir 	SvStream*			mpPBM;			// Die einzulesende PBM-Datei
38cdf0e10cSrcweir 
39cdf0e10cSrcweir 	sal_Bool				mbStatus;
40cdf0e10cSrcweir 	sal_Bool				mbRemark;		// sal_False wenn sich stream in einem Kommentar befindet
41cdf0e10cSrcweir 	sal_Bool				mbRaw;			// RAW/ASCII MODE
42cdf0e10cSrcweir 	sal_uLong				mnMode;			// 0->PBM, 1->PGM, 2->PPM
43cdf0e10cSrcweir 	Bitmap				maBmp;
44cdf0e10cSrcweir 	BitmapWriteAccess*	mpAcc;
45cdf0e10cSrcweir 	sal_uLong				mnWidth, mnHeight;	// Bildausmass in Pixeln
46cdf0e10cSrcweir 	sal_uLong				mnCol;
47cdf0e10cSrcweir 	sal_uLong				mnMaxVal;			// maximaler wert in den
48cdf0e10cSrcweir 	sal_Bool				ImplCallback( sal_uInt16 nPercent );
49cdf0e10cSrcweir 	sal_Bool				ImplReadBody();
50cdf0e10cSrcweir 	sal_Bool				ImplReadHeader();
51cdf0e10cSrcweir 
52cdf0e10cSrcweir public:
53cdf0e10cSrcweir 						PBMReader();
54cdf0e10cSrcweir 						~PBMReader();
55cdf0e10cSrcweir 	sal_Bool				ReadPBM( SvStream & rPBM, Graphic & rGraphic );
56cdf0e10cSrcweir };
57cdf0e10cSrcweir 
58cdf0e10cSrcweir //=================== Methoden von PBMReader ==============================
59cdf0e10cSrcweir 
PBMReader()60cdf0e10cSrcweir PBMReader::PBMReader() :
61cdf0e10cSrcweir 	mbStatus	( sal_True ),
62cdf0e10cSrcweir 	mbRemark	( sal_False ),
63cdf0e10cSrcweir 	mbRaw		( sal_True ),
64cdf0e10cSrcweir 	mpAcc		( NULL )
65cdf0e10cSrcweir {
66cdf0e10cSrcweir }
67cdf0e10cSrcweir 
~PBMReader()68cdf0e10cSrcweir PBMReader::~PBMReader()
69cdf0e10cSrcweir {
70cdf0e10cSrcweir }
71cdf0e10cSrcweir 
ImplCallback(sal_uInt16)72cdf0e10cSrcweir sal_Bool PBMReader::ImplCallback( sal_uInt16 /*nPercent*/ )
73cdf0e10cSrcweir {
74cdf0e10cSrcweir /*
75cdf0e10cSrcweir 	if ( pCallback != NULL )
76cdf0e10cSrcweir 	{
77cdf0e10cSrcweir 		if ( ( (*pCallback)( pCallerData, nPercent ) ) == sal_True )
78cdf0e10cSrcweir 		{
79cdf0e10cSrcweir 			mpPBM->SetError( SVSTREAM_FILEFORMAT_ERROR );
80cdf0e10cSrcweir 			return sal_True;
81cdf0e10cSrcweir 		}
82cdf0e10cSrcweir 	}
83cdf0e10cSrcweir */
84cdf0e10cSrcweir 	return sal_False;
85cdf0e10cSrcweir }
86cdf0e10cSrcweir 
ReadPBM(SvStream & rPBM,Graphic & rGraphic)87cdf0e10cSrcweir sal_Bool PBMReader::ReadPBM( SvStream & rPBM, Graphic & rGraphic )
88cdf0e10cSrcweir {
89cdf0e10cSrcweir 	sal_uInt16 i;
90cdf0e10cSrcweir 
91cdf0e10cSrcweir 	if ( rPBM.GetError() )
92cdf0e10cSrcweir 		return sal_False;
93cdf0e10cSrcweir 
94cdf0e10cSrcweir 	mpPBM = &rPBM;
95cdf0e10cSrcweir 	mpPBM->SetNumberFormatInt( NUMBERFORMAT_INT_LITTLEENDIAN );
96cdf0e10cSrcweir 
97cdf0e10cSrcweir 	// Kopf einlesen:
98cdf0e10cSrcweir 
99cdf0e10cSrcweir 	if ( ( mbStatus = ImplReadHeader() ) == sal_False )
100cdf0e10cSrcweir 		return sal_False;
101cdf0e10cSrcweir 
102cdf0e10cSrcweir 	if ( ( mnMaxVal == 0 ) || ( mnWidth == 0 ) || ( mnHeight == 0 ) )
103cdf0e10cSrcweir 		return sal_False;
104cdf0e10cSrcweir 
105cdf0e10cSrcweir 	// 0->PBM, 1->PGM, 2->PPM
106cdf0e10cSrcweir 	switch ( mnMode )
107cdf0e10cSrcweir 	{
108cdf0e10cSrcweir 		case 0 :
109cdf0e10cSrcweir 			maBmp = Bitmap( Size( mnWidth, mnHeight ), 1 );
110*0af288bdSJuergen Schmidt 			mpAcc = maBmp.AcquireWriteAccess();
111*0af288bdSJuergen Schmidt 			if ( !mpAcc )
112cdf0e10cSrcweir 				return sal_False;
113cdf0e10cSrcweir 			mpAcc->SetPaletteEntryCount( 2 );
114cdf0e10cSrcweir 			mpAcc->SetPaletteColor( 0, BitmapColor( 0xff, 0xff, 0xff ) );
115cdf0e10cSrcweir 			mpAcc->SetPaletteColor( 1, BitmapColor( 0x00, 0x00, 0x00 ) );
116cdf0e10cSrcweir 			break;
117cdf0e10cSrcweir 
118cdf0e10cSrcweir 		case 1 :
119cdf0e10cSrcweir 			if ( mnMaxVal <= 1 )
120cdf0e10cSrcweir 				maBmp = Bitmap( Size( mnWidth, mnHeight ), 1);
121cdf0e10cSrcweir 			else if ( mnMaxVal <= 15 )
122cdf0e10cSrcweir 				maBmp = Bitmap( Size( mnWidth, mnHeight ), 4);
123cdf0e10cSrcweir 			else
124cdf0e10cSrcweir 				maBmp = Bitmap( Size( mnWidth, mnHeight ), 8);
125cdf0e10cSrcweir 
126*0af288bdSJuergen Schmidt 			mpAcc = maBmp.AcquireWriteAccess();
127*0af288bdSJuergen Schmidt 			if ( !mpAcc )
128cdf0e10cSrcweir 				return sal_False;
129cdf0e10cSrcweir 			mnCol = (sal_uInt16)mnMaxVal + 1;
130cdf0e10cSrcweir 			if ( mnCol > 256 )
131cdf0e10cSrcweir 				mnCol = 256;
132cdf0e10cSrcweir 
133cdf0e10cSrcweir 			mpAcc->SetPaletteEntryCount( 256 );
134cdf0e10cSrcweir 			for ( i = 0; i < mnCol; i++ )
135cdf0e10cSrcweir 			{
136cdf0e10cSrcweir 				sal_uLong nCount = 255 * i / mnCol;
137cdf0e10cSrcweir 				mpAcc->SetPaletteColor( i, BitmapColor( (sal_uInt8)nCount, (sal_uInt8)nCount, (sal_uInt8)nCount ) );
138cdf0e10cSrcweir 			}
139cdf0e10cSrcweir 			break;
140cdf0e10cSrcweir 		case 2 :
141cdf0e10cSrcweir 			maBmp = Bitmap( Size( mnWidth, mnHeight ), 24 );
142*0af288bdSJuergen Schmidt 			mpAcc = maBmp.AcquireWriteAccess();
143*0af288bdSJuergen Schmidt 			if ( !mpAcc )
144cdf0e10cSrcweir 				return sal_False;
145cdf0e10cSrcweir 			break;
146cdf0e10cSrcweir 	}
147cdf0e10cSrcweir 
148cdf0e10cSrcweir 	// Bitmap-Daten einlesen
149cdf0e10cSrcweir 	mbStatus = ImplReadBody();
150cdf0e10cSrcweir 
151cdf0e10cSrcweir 	if ( mpAcc )
152cdf0e10cSrcweir 	{
153cdf0e10cSrcweir 		maBmp.ReleaseAccess( mpAcc ), mpAcc = NULL;
154cdf0e10cSrcweir 	}
155cdf0e10cSrcweir 	if ( mbStatus )
156cdf0e10cSrcweir 		rGraphic = maBmp;
157cdf0e10cSrcweir 
158cdf0e10cSrcweir 	return mbStatus;
159cdf0e10cSrcweir }
160cdf0e10cSrcweir 
ImplReadHeader()161cdf0e10cSrcweir sal_Bool PBMReader::ImplReadHeader()
162cdf0e10cSrcweir {
163cdf0e10cSrcweir 	sal_uInt8	nID[ 2 ];
164cdf0e10cSrcweir 	sal_uInt8	nDat;
165cdf0e10cSrcweir 	sal_uInt8	nMax, nCount = 0;
166cdf0e10cSrcweir 	sal_Bool	bFinished = sal_False;
167cdf0e10cSrcweir 
168cdf0e10cSrcweir 	*mpPBM >> nID[ 0 ] >> nID[ 1 ];
169cdf0e10cSrcweir 	if ( nID[ 0 ] != 'P' )
170cdf0e10cSrcweir 		return sal_False;
171cdf0e10cSrcweir 	mnMaxVal = mnWidth = mnHeight = 0;
172cdf0e10cSrcweir 	switch ( nID[ 1 ] )
173cdf0e10cSrcweir 	{
174cdf0e10cSrcweir 		case '1' :
175cdf0e10cSrcweir 			mbRaw = sal_False;
176cdf0e10cSrcweir 		case '4' :
177cdf0e10cSrcweir 			mnMode = 0;
178cdf0e10cSrcweir 			nMax = 2;				// number of parameters in Header
179cdf0e10cSrcweir 			mnMaxVal = 1;
180cdf0e10cSrcweir 			break;
181cdf0e10cSrcweir 		case '2' :
182cdf0e10cSrcweir 			mbRaw = sal_False;
183cdf0e10cSrcweir 		case '5' :
184cdf0e10cSrcweir 			mnMode = 1;
185cdf0e10cSrcweir 			nMax = 3;
186cdf0e10cSrcweir 			break;
187cdf0e10cSrcweir 		case '3' :
188cdf0e10cSrcweir 			mbRaw = sal_False;
189cdf0e10cSrcweir 		case '6' :
190cdf0e10cSrcweir 			mnMode = 2;
191cdf0e10cSrcweir 			nMax = 3;
192cdf0e10cSrcweir 			break;
193cdf0e10cSrcweir 		default:
194cdf0e10cSrcweir 			return sal_False;
195cdf0e10cSrcweir 	}
196cdf0e10cSrcweir 	while ( bFinished == sal_False )
197cdf0e10cSrcweir 	{
198cdf0e10cSrcweir 		if ( mpPBM->GetError() )
199cdf0e10cSrcweir 			return sal_False;
200cdf0e10cSrcweir 
201cdf0e10cSrcweir 		*mpPBM >> nDat;
202cdf0e10cSrcweir 
203cdf0e10cSrcweir 		if ( nDat == '#' )
204cdf0e10cSrcweir 		{
205cdf0e10cSrcweir 			mbRemark = sal_True;
206cdf0e10cSrcweir 			continue;
207cdf0e10cSrcweir 		}
208cdf0e10cSrcweir 		else if ( ( nDat == 0x0d ) || ( nDat == 0x0a ) )
209cdf0e10cSrcweir 		{
210cdf0e10cSrcweir 			mbRemark = sal_False;
211cdf0e10cSrcweir 			nDat = 0x20;
212cdf0e10cSrcweir 		}
213cdf0e10cSrcweir 		if ( mbRemark )
214cdf0e10cSrcweir 			continue;
215cdf0e10cSrcweir 
216cdf0e10cSrcweir 		if ( ( nDat == 0x20 ) || ( nDat == 0x09 ) )
217cdf0e10cSrcweir 		{
218cdf0e10cSrcweir 			if ( ( nCount == 0 ) && mnWidth )
219cdf0e10cSrcweir 				nCount++;
220cdf0e10cSrcweir 			else if ( ( nCount == 1 ) && mnHeight )
221cdf0e10cSrcweir 			{
222cdf0e10cSrcweir 				if ( ++nCount == nMax )
223cdf0e10cSrcweir 					bFinished = sal_True;
224cdf0e10cSrcweir 			}
225cdf0e10cSrcweir 			else if ( ( nCount == 2 ) && mnMaxVal )
226cdf0e10cSrcweir 			{
227cdf0e10cSrcweir 				bFinished = sal_True;
228cdf0e10cSrcweir 			}
229cdf0e10cSrcweir 			continue;
230cdf0e10cSrcweir 		}
231cdf0e10cSrcweir 		if ( ( nDat >= '0' ) && ( nDat <= '9' ) )
232cdf0e10cSrcweir 		{
233cdf0e10cSrcweir 			nDat -= '0';
234cdf0e10cSrcweir 			if ( nCount == 0 )
235cdf0e10cSrcweir 			{
236cdf0e10cSrcweir 				mnWidth *= 10;
237cdf0e10cSrcweir 				mnWidth += nDat;
238cdf0e10cSrcweir 			}
239cdf0e10cSrcweir 			else if ( nCount == 1 )
240cdf0e10cSrcweir 			{
241cdf0e10cSrcweir 				mnHeight *= 10;
242cdf0e10cSrcweir 				mnHeight += nDat;
243cdf0e10cSrcweir 			}
244cdf0e10cSrcweir 			else if ( nCount == 2 )
245cdf0e10cSrcweir 			{
246cdf0e10cSrcweir 				mnMaxVal *= 10;
247cdf0e10cSrcweir 				mnMaxVal += nDat;
248cdf0e10cSrcweir 			}
249cdf0e10cSrcweir 		}
250cdf0e10cSrcweir 		else
251cdf0e10cSrcweir 			return sal_False;
252cdf0e10cSrcweir 	}
253cdf0e10cSrcweir 	return mbStatus;
254cdf0e10cSrcweir }
255cdf0e10cSrcweir 
ImplReadBody()256cdf0e10cSrcweir sal_Bool PBMReader::ImplReadBody()
257cdf0e10cSrcweir {
258cdf0e10cSrcweir 	sal_Bool	bPara, bFinished = sal_False;
259cdf0e10cSrcweir 	sal_uInt8	nDat = 0, nCount;
260cdf0e10cSrcweir 	sal_uLong	nGrey, nRGB[3];
261cdf0e10cSrcweir 	sal_uLong	nWidth = 0;
262cdf0e10cSrcweir 	sal_uLong	nHeight = 0;
263cdf0e10cSrcweir 	signed char	nShift = 0;
264cdf0e10cSrcweir 
265cdf0e10cSrcweir 	if ( mbRaw )
266cdf0e10cSrcweir 	{
267cdf0e10cSrcweir 		switch ( mnMode )
268cdf0e10cSrcweir 		{
269cdf0e10cSrcweir 
270cdf0e10cSrcweir 			// PBM
271cdf0e10cSrcweir 			case 0 :
272cdf0e10cSrcweir 				while ( nHeight != mnHeight )
273cdf0e10cSrcweir 				{
274cdf0e10cSrcweir 					if ( mpPBM->IsEof() || mpPBM->GetError() )
275cdf0e10cSrcweir 						return sal_False;
276cdf0e10cSrcweir 
277cdf0e10cSrcweir 					if ( --nShift < 0 )
278cdf0e10cSrcweir 					{
279cdf0e10cSrcweir 						*mpPBM >> nDat;
280cdf0e10cSrcweir 						nShift = 7;
281cdf0e10cSrcweir 					}
28287bc88d3SHerbert Dürr 					mpAcc->SetPixelIndex( nHeight, nWidth, nDat >> nShift );
283cdf0e10cSrcweir 					if ( ++nWidth == mnWidth )
284cdf0e10cSrcweir 					{
285cdf0e10cSrcweir 						nShift = 0;
286cdf0e10cSrcweir 						nWidth = 0;
287cdf0e10cSrcweir 						nHeight++;
288cdf0e10cSrcweir 						ImplCallback( (sal_uInt16)( ( 100 * nHeight ) / mnHeight ) );	// processing output in percent
289cdf0e10cSrcweir 					}
290cdf0e10cSrcweir 				}
291cdf0e10cSrcweir 				break;
292cdf0e10cSrcweir 
293cdf0e10cSrcweir 			// PGM
294cdf0e10cSrcweir 			case 1 :
295cdf0e10cSrcweir 				while ( nHeight != mnHeight )
296cdf0e10cSrcweir 				{
297cdf0e10cSrcweir 					if ( mpPBM->IsEof() || mpPBM->GetError() )
298cdf0e10cSrcweir 						return sal_False;
299cdf0e10cSrcweir 
300cdf0e10cSrcweir 					*mpPBM >> nDat;
30187bc88d3SHerbert Dürr 					mpAcc->SetPixelIndex( nHeight, nWidth++, nDat);
302cdf0e10cSrcweir 
303cdf0e10cSrcweir 					if ( nWidth == mnWidth )
304cdf0e10cSrcweir 					{
305cdf0e10cSrcweir 						nWidth = 0;
306cdf0e10cSrcweir 						nHeight++;
307cdf0e10cSrcweir 						ImplCallback( (sal_uInt16)( ( 100 * nHeight ) / mnHeight ) );	// processing output in percent
308cdf0e10cSrcweir 					}
309cdf0e10cSrcweir 				}
310cdf0e10cSrcweir 				break;
311cdf0e10cSrcweir 
312cdf0e10cSrcweir 			// PPM
313cdf0e10cSrcweir 			case 2 :
314cdf0e10cSrcweir 				while ( nHeight != mnHeight )
315cdf0e10cSrcweir 				{
316cdf0e10cSrcweir 					if ( mpPBM->IsEof() || mpPBM->GetError() )
317cdf0e10cSrcweir 						return sal_False;
318cdf0e10cSrcweir 
319cdf0e10cSrcweir 					sal_uInt8	nR, nG, nB;
320cdf0e10cSrcweir 					sal_uLong	nRed, nGreen, nBlue;
321cdf0e10cSrcweir 					*mpPBM >> nR >> nG >> nB;
322cdf0e10cSrcweir 					nRed = 255 * nR / mnMaxVal;
323cdf0e10cSrcweir 					nGreen = 255 * nG / mnMaxVal;
324cdf0e10cSrcweir 					nBlue = 255 * nB / mnMaxVal;
325cdf0e10cSrcweir 					mpAcc->SetPixel( nHeight, nWidth++, BitmapColor( (sal_uInt8)nRed, (sal_uInt8)nGreen, (sal_uInt8)nBlue ) );
326cdf0e10cSrcweir 					if ( nWidth == mnWidth )
327cdf0e10cSrcweir 					{
328cdf0e10cSrcweir 						nWidth = 0;
329cdf0e10cSrcweir 						nHeight++;
330cdf0e10cSrcweir 						ImplCallback( (sal_uInt16) ( ( 100 * nHeight ) / mnHeight ) );	// processing output in percent
331cdf0e10cSrcweir 					}
332cdf0e10cSrcweir 				}
333cdf0e10cSrcweir 				break;
334cdf0e10cSrcweir 		}
335cdf0e10cSrcweir 	}
336cdf0e10cSrcweir 	else switch  ( mnMode )
337cdf0e10cSrcweir 	{
338cdf0e10cSrcweir 		// PBM
339cdf0e10cSrcweir 		case 0 :
340cdf0e10cSrcweir 			while ( bFinished == sal_False )
341cdf0e10cSrcweir 			{
342cdf0e10cSrcweir 				if ( mpPBM->IsEof() || mpPBM->GetError() )
343cdf0e10cSrcweir 					return sal_False;
344cdf0e10cSrcweir 
345cdf0e10cSrcweir 				*mpPBM >> nDat;
346cdf0e10cSrcweir 
347cdf0e10cSrcweir 				if ( nDat == '#' )
348cdf0e10cSrcweir 				{
349cdf0e10cSrcweir 					mbRemark = sal_True;
350cdf0e10cSrcweir 					continue;
351cdf0e10cSrcweir 				}
352cdf0e10cSrcweir 				else if ( ( nDat == 0x0d ) || ( nDat == 0x0a ) )
353cdf0e10cSrcweir 				{
354cdf0e10cSrcweir 					mbRemark = sal_False;
355cdf0e10cSrcweir 					continue;
356cdf0e10cSrcweir 				}
357cdf0e10cSrcweir 				if ( mbRemark || nDat == 0x20 || nDat == 0x09 )
358cdf0e10cSrcweir 					continue;
359cdf0e10cSrcweir 
360cdf0e10cSrcweir 				if ( nDat == '0' || nDat == '1' )
361cdf0e10cSrcweir 				{
36287bc88d3SHerbert Dürr 					mpAcc->SetPixelIndex( nHeight, nWidth, static_cast<sal_uInt8>(nDat - '0') );
363cdf0e10cSrcweir 					nWidth++;
364cdf0e10cSrcweir 					if ( nWidth == mnWidth )
365cdf0e10cSrcweir 					{
366cdf0e10cSrcweir 						nWidth = 0;
367cdf0e10cSrcweir 						if ( ++nHeight == mnHeight )
368cdf0e10cSrcweir 							bFinished = sal_True;
369cdf0e10cSrcweir 						ImplCallback( (sal_uInt16) ( ( 100 * nHeight ) / mnHeight ) );	// processing output in percent
370cdf0e10cSrcweir 					}
371cdf0e10cSrcweir 				}
372cdf0e10cSrcweir 				else
373cdf0e10cSrcweir 					return sal_False;
374cdf0e10cSrcweir 			}
375cdf0e10cSrcweir 			break;
376cdf0e10cSrcweir 
377cdf0e10cSrcweir 		// PGM
378cdf0e10cSrcweir 		case 1 :
379cdf0e10cSrcweir 
380cdf0e10cSrcweir 			bPara = sal_False;
381cdf0e10cSrcweir 			nCount = 0;
382cdf0e10cSrcweir 			nGrey = 0;
383cdf0e10cSrcweir 
384cdf0e10cSrcweir 			while ( bFinished == sal_False )
385cdf0e10cSrcweir 			{
386cdf0e10cSrcweir 				if ( nCount )
387cdf0e10cSrcweir 				{
388cdf0e10cSrcweir 					nCount--;
389cdf0e10cSrcweir 					if ( nGrey <= mnMaxVal )
390cdf0e10cSrcweir 						nGrey = 255 * nGrey / mnMaxVal;
39187bc88d3SHerbert Dürr 						mpAcc->SetPixelIndex( nHeight, nWidth++, static_cast<sal_uInt8>(nGrey) );
392cdf0e10cSrcweir 					nGrey = 0;
393cdf0e10cSrcweir 					if ( nWidth == mnWidth )
394cdf0e10cSrcweir 					{
395cdf0e10cSrcweir 						nWidth = 0;
396cdf0e10cSrcweir 						if ( ++nHeight == mnHeight )
397cdf0e10cSrcweir 							bFinished = sal_True;
398cdf0e10cSrcweir 						ImplCallback( (sal_uInt16) ( ( 100 * nHeight ) / mnHeight ) );	// processing output in percent
399cdf0e10cSrcweir 					}
400cdf0e10cSrcweir 					continue;
401cdf0e10cSrcweir 				}
402cdf0e10cSrcweir 
403cdf0e10cSrcweir 				if ( mpPBM->IsEof() || mpPBM->GetError() )
404cdf0e10cSrcweir 					return sal_False;
405cdf0e10cSrcweir 
406cdf0e10cSrcweir 				*mpPBM >> nDat;
407cdf0e10cSrcweir 
408cdf0e10cSrcweir 				if ( nDat == '#' )
409cdf0e10cSrcweir 				{
410cdf0e10cSrcweir 					mbRemark = sal_True;
411cdf0e10cSrcweir 					if ( bPara )
412cdf0e10cSrcweir 					{
413cdf0e10cSrcweir 						bPara = sal_False;
414cdf0e10cSrcweir 						nCount++;
415cdf0e10cSrcweir 					}
416cdf0e10cSrcweir 					continue;
417cdf0e10cSrcweir 				}
418cdf0e10cSrcweir 				else if ( ( nDat == 0x0d ) || ( nDat == 0x0a ) )
419cdf0e10cSrcweir 				{
420cdf0e10cSrcweir 					mbRemark = sal_False;
421cdf0e10cSrcweir 					if ( bPara )
422cdf0e10cSrcweir 					{
423cdf0e10cSrcweir 						bPara = sal_False;
424cdf0e10cSrcweir 						nCount++;
425cdf0e10cSrcweir 					}
426cdf0e10cSrcweir 					continue;
427cdf0e10cSrcweir 				}
428cdf0e10cSrcweir 
429cdf0e10cSrcweir 				if ( nDat == 0x20 || nDat == 0x09 )
430cdf0e10cSrcweir 				{
431cdf0e10cSrcweir 					if ( bPara )
432cdf0e10cSrcweir 					{
433cdf0e10cSrcweir 						bPara = sal_False;
434cdf0e10cSrcweir 						nCount++;
435cdf0e10cSrcweir 					}
436cdf0e10cSrcweir 					continue;
437cdf0e10cSrcweir 				}
438cdf0e10cSrcweir 				if ( nDat >= '0' && nDat <= '9' )
439cdf0e10cSrcweir 				{
440cdf0e10cSrcweir 					bPara = sal_True;
441cdf0e10cSrcweir 					nGrey *= 10;
442cdf0e10cSrcweir 					nGrey += nDat-'0';
443cdf0e10cSrcweir 					continue;
444cdf0e10cSrcweir 				}
445cdf0e10cSrcweir 				else
446cdf0e10cSrcweir 					return sal_False;
447cdf0e10cSrcweir 			}
448cdf0e10cSrcweir 			break;
449cdf0e10cSrcweir 
450cdf0e10cSrcweir 
451cdf0e10cSrcweir 
452cdf0e10cSrcweir 		// PPM
453cdf0e10cSrcweir 		case 2 :
454cdf0e10cSrcweir 
455cdf0e10cSrcweir 			bPara = sal_False;
456cdf0e10cSrcweir 			nCount = 0;
457cdf0e10cSrcweir 			nRGB[ 0 ] = nRGB[ 1 ] = nRGB[ 2 ] = 0;
458cdf0e10cSrcweir 
459cdf0e10cSrcweir 			while ( bFinished == sal_False )
460cdf0e10cSrcweir 			{
461cdf0e10cSrcweir 				if ( nCount == 3 )
462cdf0e10cSrcweir 				{
463cdf0e10cSrcweir 					nCount = 0;
464cdf0e10cSrcweir 					mpAcc->SetPixel( nHeight, nWidth++, BitmapColor( static_cast< sal_uInt8 >( ( nRGB[ 0 ] * 255 ) / mnMaxVal ),
465cdf0e10cSrcweir 																	 static_cast< sal_uInt8 >( ( nRGB[ 1 ] * 255 ) / mnMaxVal ),
466cdf0e10cSrcweir 																	 static_cast< sal_uInt8 >( ( nRGB[ 2 ] * 255 ) / mnMaxVal ) ) );
467cdf0e10cSrcweir 					nCount = 0;
468cdf0e10cSrcweir 					nRGB[ 0 ] = nRGB[ 1 ] = nRGB[ 2 ] = 0;
469cdf0e10cSrcweir 					if ( nWidth == mnWidth )
470cdf0e10cSrcweir 					{
471cdf0e10cSrcweir 						nWidth = 0;
472cdf0e10cSrcweir 						if ( ++nHeight == mnHeight )
473cdf0e10cSrcweir 							bFinished = sal_True;
474cdf0e10cSrcweir 						ImplCallback( (sal_uInt16) ( ( 100 * nHeight ) / mnHeight ) );	// processing output in percent
475cdf0e10cSrcweir 					}
476cdf0e10cSrcweir 					continue;
477cdf0e10cSrcweir 				}
478cdf0e10cSrcweir 
479cdf0e10cSrcweir 				if ( mpPBM->IsEof() || mpPBM->GetError() )
480cdf0e10cSrcweir 					return sal_False;
481cdf0e10cSrcweir 
482cdf0e10cSrcweir 				*mpPBM >> nDat;
483cdf0e10cSrcweir 
484cdf0e10cSrcweir 				if ( nDat == '#' )
485cdf0e10cSrcweir 				{
486cdf0e10cSrcweir 					mbRemark = sal_True;
487cdf0e10cSrcweir 					if ( bPara )
488cdf0e10cSrcweir 					{
489cdf0e10cSrcweir 						bPara = sal_False;
490cdf0e10cSrcweir 						nCount++;
491cdf0e10cSrcweir 					}
492cdf0e10cSrcweir 					continue;
493cdf0e10cSrcweir 				}
494cdf0e10cSrcweir 				else if ( ( nDat == 0x0d ) || ( nDat == 0x0a ) )
495cdf0e10cSrcweir 				{
496cdf0e10cSrcweir 					mbRemark = sal_False;
497cdf0e10cSrcweir 					if ( bPara )
498cdf0e10cSrcweir 					{
499cdf0e10cSrcweir 						bPara = sal_False;
500cdf0e10cSrcweir 						nCount++;
501cdf0e10cSrcweir 					}
502cdf0e10cSrcweir 					continue;
503cdf0e10cSrcweir 				}
504cdf0e10cSrcweir 
505cdf0e10cSrcweir 				if ( nDat == 0x20 || nDat == 0x09 )
506cdf0e10cSrcweir 				{
507cdf0e10cSrcweir 					if ( bPara )
508cdf0e10cSrcweir 					{
509cdf0e10cSrcweir 						bPara = sal_False;
510cdf0e10cSrcweir 						nCount++;
511cdf0e10cSrcweir 					}
512cdf0e10cSrcweir 					continue;
513cdf0e10cSrcweir 				}
514cdf0e10cSrcweir 				if ( nDat >= '0' && nDat <= '9' )
515cdf0e10cSrcweir 				{
516cdf0e10cSrcweir 					bPara = sal_True;
517cdf0e10cSrcweir 					nRGB[ nCount ] *= 10;
518cdf0e10cSrcweir 					nRGB[ nCount ] += nDat-'0';
519cdf0e10cSrcweir 					continue;
520cdf0e10cSrcweir 				}
521cdf0e10cSrcweir 				else
522cdf0e10cSrcweir 					return sal_False;
523cdf0e10cSrcweir 			}
524cdf0e10cSrcweir 			break;
525cdf0e10cSrcweir 	}
526cdf0e10cSrcweir 	return mbStatus;
527cdf0e10cSrcweir }
528cdf0e10cSrcweir 
529cdf0e10cSrcweir //================== GraphicImport - die exportierte Funktion ================
530cdf0e10cSrcweir 
GraphicImport(SvStream & rStream,Graphic & rGraphic,FilterConfigItem *,sal_Bool)531cdf0e10cSrcweir extern "C" sal_Bool __LOADONCALLAPI GraphicImport(SvStream & rStream, Graphic & rGraphic, FilterConfigItem*, sal_Bool )
532cdf0e10cSrcweir {
533cdf0e10cSrcweir 	PBMReader aPBMReader;
534cdf0e10cSrcweir 
535cdf0e10cSrcweir 	return aPBMReader.ReadPBM( rStream, rGraphic );
536cdf0e10cSrcweir }
537cdf0e10cSrcweir 
538