xref: /aoo41x/main/vcl/unx/generic/dtrans/bmp.cxx (revision c82f2877)
1*c82f2877SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*c82f2877SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*c82f2877SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*c82f2877SAndrew Rist  * distributed with this work for additional information
6*c82f2877SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*c82f2877SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*c82f2877SAndrew Rist  * "License"); you may not use this file except in compliance
9*c82f2877SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*c82f2877SAndrew Rist  *
11*c82f2877SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*c82f2877SAndrew Rist  *
13*c82f2877SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*c82f2877SAndrew Rist  * software distributed under the License is distributed on an
15*c82f2877SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*c82f2877SAndrew Rist  * KIND, either express or implied.  See the License for the
17*c82f2877SAndrew Rist  * specific language governing permissions and limitations
18*c82f2877SAndrew Rist  * under the License.
19*c82f2877SAndrew Rist  *
20*c82f2877SAndrew Rist  *************************************************************/
21*c82f2877SAndrew Rist 
22*c82f2877SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_vcl.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <unistd.h>
28cdf0e10cSrcweir #include <cstdio>
29cdf0e10cSrcweir #include <cstring>
30cdf0e10cSrcweir 
31cdf0e10cSrcweir #include <bmp.hxx>
32cdf0e10cSrcweir 
33cdf0e10cSrcweir #include <X11_selection.hxx>
34cdf0e10cSrcweir 
35cdf0e10cSrcweir using namespace x11;
36cdf0e10cSrcweir using namespace com::sun::star::uno;
37cdf0e10cSrcweir using namespace com::sun::star::script;
38cdf0e10cSrcweir using namespace com::sun::star::awt;
39cdf0e10cSrcweir using namespace rtl;
40cdf0e10cSrcweir 
41cdf0e10cSrcweir /*
42cdf0e10cSrcweir  *  helper functions
43cdf0e10cSrcweir  */
44cdf0e10cSrcweir 
writeLE(sal_uInt16 nNumber,sal_uInt8 * pBuffer)45cdf0e10cSrcweir inline void writeLE( sal_uInt16 nNumber, sal_uInt8* pBuffer )
46cdf0e10cSrcweir {
47cdf0e10cSrcweir     pBuffer[ 0 ] = (nNumber & 0xff);
48cdf0e10cSrcweir     pBuffer[ 1 ] = ((nNumber>>8)&0xff);
49cdf0e10cSrcweir }
50cdf0e10cSrcweir 
writeLE(sal_uInt32 nNumber,sal_uInt8 * pBuffer)51cdf0e10cSrcweir inline void writeLE( sal_uInt32 nNumber, sal_uInt8* pBuffer )
52cdf0e10cSrcweir {
53cdf0e10cSrcweir     pBuffer[ 0 ] = (nNumber & 0xff);
54cdf0e10cSrcweir     pBuffer[ 1 ] = ((nNumber>>8)&0xff);
55cdf0e10cSrcweir     pBuffer[ 2 ] = ((nNumber>>16)&0xff);
56cdf0e10cSrcweir     pBuffer[ 3 ] = ((nNumber>>24)&0xff);
57cdf0e10cSrcweir }
58cdf0e10cSrcweir 
readLE16(const sal_uInt8 * pBuffer)59cdf0e10cSrcweir inline sal_uInt16 readLE16( const sal_uInt8* pBuffer )
60cdf0e10cSrcweir {
61cdf0e10cSrcweir     return (((sal_uInt16)pBuffer[1]) << 8 ) | pBuffer[0];
62cdf0e10cSrcweir }
63cdf0e10cSrcweir 
readLE32(const sal_uInt8 * pBuffer)64cdf0e10cSrcweir inline sal_uInt16 readLE32( const sal_uInt8* pBuffer )
65cdf0e10cSrcweir {
66cdf0e10cSrcweir     return
67cdf0e10cSrcweir         (((sal_uInt32)pBuffer[3]) << 24 ) |
68cdf0e10cSrcweir         (((sal_uInt32)pBuffer[2]) << 16 ) |
69cdf0e10cSrcweir         (((sal_uInt32)pBuffer[1]) <<  8 ) |
70cdf0e10cSrcweir         pBuffer[0];
71cdf0e10cSrcweir }
72cdf0e10cSrcweir 
73cdf0e10cSrcweir 
74cdf0e10cSrcweir /*
75cdf0e10cSrcweir  * BmpTransporter
76cdf0e10cSrcweir  */
77cdf0e10cSrcweir 
BmpTransporter(const Sequence<sal_Int8> & rBmp)78cdf0e10cSrcweir BmpTransporter::BmpTransporter( const Sequence<sal_Int8>& rBmp ) :
79cdf0e10cSrcweir         m_aBM( rBmp )
80cdf0e10cSrcweir {
81cdf0e10cSrcweir     const sal_uInt8* pData = (const sal_uInt8*)rBmp.getConstArray();
82cdf0e10cSrcweir 
83cdf0e10cSrcweir     if( pData[0] == 'B' || pData[1] == 'M' )
84cdf0e10cSrcweir     {
85cdf0e10cSrcweir         pData = pData+14;
86cdf0e10cSrcweir         m_aSize.Width	= readLE32( pData+4 );
87cdf0e10cSrcweir         m_aSize.Height	= readLE32( pData+8 );
88cdf0e10cSrcweir     }
89cdf0e10cSrcweir     else
90cdf0e10cSrcweir         m_aSize.Width = m_aSize.Height = 0;
91cdf0e10cSrcweir }
92cdf0e10cSrcweir 
~BmpTransporter()93cdf0e10cSrcweir BmpTransporter::~BmpTransporter()
94cdf0e10cSrcweir {
95cdf0e10cSrcweir }
96cdf0e10cSrcweir 
getSize()97cdf0e10cSrcweir com::sun::star::awt::Size SAL_CALL BmpTransporter::getSize() throw()
98cdf0e10cSrcweir {
99cdf0e10cSrcweir     return m_aSize;
100cdf0e10cSrcweir }
101cdf0e10cSrcweir 
getDIB()102cdf0e10cSrcweir Sequence< sal_Int8 > SAL_CALL BmpTransporter::getDIB() throw()
103cdf0e10cSrcweir {
104cdf0e10cSrcweir     return m_aBM;
105cdf0e10cSrcweir }
106cdf0e10cSrcweir 
getMaskDIB()107cdf0e10cSrcweir Sequence< sal_Int8 > SAL_CALL BmpTransporter::getMaskDIB() throw()
108cdf0e10cSrcweir {
109cdf0e10cSrcweir     return Sequence< sal_Int8 >();
110cdf0e10cSrcweir }
111cdf0e10cSrcweir 
112cdf0e10cSrcweir /*
113cdf0e10cSrcweir  * scanline helpers
114cdf0e10cSrcweir  */
115cdf0e10cSrcweir 
X11_writeScanlinePixel(unsigned long nColor,sal_uInt8 * pScanline,int depth,int x)116cdf0e10cSrcweir inline void X11_writeScanlinePixel( unsigned long nColor, sal_uInt8* pScanline, int depth, int x )
117cdf0e10cSrcweir {
118cdf0e10cSrcweir     switch( depth )
119cdf0e10cSrcweir     {
120cdf0e10cSrcweir         case 1:
121cdf0e10cSrcweir             pScanline[ x/8 ] &= ~(1 << (x&7));
122cdf0e10cSrcweir             pScanline[ x/8 ] |= ((nColor & 1) << (x&7));
123cdf0e10cSrcweir             break;
124cdf0e10cSrcweir         case 4:
125cdf0e10cSrcweir             pScanline[ x/2 ] &= ((x&1) ? 0x0f : 0xf0);
126cdf0e10cSrcweir             pScanline[ x/2 ] |= ((x&1) ? (nColor & 0x0f) : ((nColor & 0x0f) << 4));
127cdf0e10cSrcweir             break;
128cdf0e10cSrcweir         default:
129cdf0e10cSrcweir         case 8:
130cdf0e10cSrcweir             pScanline[ x ] = (nColor & 0xff);
131cdf0e10cSrcweir             break;
132cdf0e10cSrcweir     }
133cdf0e10cSrcweir }
134cdf0e10cSrcweir 
X11_getPaletteBmpFromImage(Display * pDisplay,XImage * pImage,Colormap aColormap,sal_Int32 & rOutSize)135cdf0e10cSrcweir static sal_uInt8* X11_getPaletteBmpFromImage(
136cdf0e10cSrcweir                                              Display* pDisplay,
137cdf0e10cSrcweir                                              XImage* pImage,
138cdf0e10cSrcweir                                              Colormap aColormap,
139cdf0e10cSrcweir                                              sal_Int32& rOutSize
140cdf0e10cSrcweir                                              )
141cdf0e10cSrcweir {
142cdf0e10cSrcweir     sal_uInt32 nColors = 0;
143cdf0e10cSrcweir 
144cdf0e10cSrcweir     rOutSize = 0;
145cdf0e10cSrcweir 
146cdf0e10cSrcweir     sal_uInt8* pBuffer = 0;
147cdf0e10cSrcweir     sal_uInt32 nHeaderSize, nScanlineSize;
148cdf0e10cSrcweir     sal_uInt16 nBitCount;
149cdf0e10cSrcweir     // determine header and scanline size
150cdf0e10cSrcweir     switch( pImage->depth )
151cdf0e10cSrcweir     {
152cdf0e10cSrcweir         case 1:
153cdf0e10cSrcweir             nHeaderSize = 64;
154cdf0e10cSrcweir             nScanlineSize = (pImage->width+31)/32;
155cdf0e10cSrcweir             nBitCount = 1;
156cdf0e10cSrcweir             break;
157cdf0e10cSrcweir         case 4:
158cdf0e10cSrcweir             nHeaderSize = 72;
159cdf0e10cSrcweir             nScanlineSize = (pImage->width+1)/2;
160cdf0e10cSrcweir             nBitCount = 4;
161cdf0e10cSrcweir             break;
162cdf0e10cSrcweir         default:
163cdf0e10cSrcweir         case 8:
164cdf0e10cSrcweir             nHeaderSize = 1084;
165cdf0e10cSrcweir             nScanlineSize = pImage->width;
166cdf0e10cSrcweir             nBitCount = 8;
167cdf0e10cSrcweir             break;
168cdf0e10cSrcweir     }
169cdf0e10cSrcweir     // adjust scan lines to begin on %4 boundaries
170cdf0e10cSrcweir     if( nScanlineSize & 3 )
171cdf0e10cSrcweir     {
172cdf0e10cSrcweir         nScanlineSize &= 0xfffffffc;
173cdf0e10cSrcweir         nScanlineSize += 4;
174cdf0e10cSrcweir     }
175cdf0e10cSrcweir 
176cdf0e10cSrcweir     // allocate buffer to hold header and scanlines, initialize to zero
177cdf0e10cSrcweir     rOutSize = nHeaderSize + nScanlineSize*pImage->height;
178cdf0e10cSrcweir     pBuffer = (sal_uInt8*)rtl_allocateZeroMemory( rOutSize );
179cdf0e10cSrcweir     for( int y = 0; y < pImage->height; y++ )
180cdf0e10cSrcweir     {
181cdf0e10cSrcweir         sal_uInt8* pScanline = pBuffer + nHeaderSize + (pImage->height-1-y)*nScanlineSize;
182cdf0e10cSrcweir         for( int x = 0; x < pImage->width; x++ )
183cdf0e10cSrcweir         {
184cdf0e10cSrcweir             unsigned long nPixel = XGetPixel( pImage, x, y );
185cdf0e10cSrcweir             if( nPixel >= nColors )
186cdf0e10cSrcweir                 nColors = nPixel+1;
187cdf0e10cSrcweir             X11_writeScanlinePixel( nPixel, pScanline, pImage->depth, x );
188cdf0e10cSrcweir         }
189cdf0e10cSrcweir     }
190cdf0e10cSrcweir 
191cdf0e10cSrcweir     // fill in header fields
192cdf0e10cSrcweir     pBuffer[ 0 ] = 'B';
193cdf0e10cSrcweir     pBuffer[ 1 ] = 'M';
194cdf0e10cSrcweir 
195cdf0e10cSrcweir     writeLE( nHeaderSize, pBuffer+10 );
196cdf0e10cSrcweir     writeLE( (sal_uInt32)40, pBuffer+14 );
197cdf0e10cSrcweir     writeLE( (sal_uInt32)pImage->width, pBuffer+18 );
198cdf0e10cSrcweir     writeLE( (sal_uInt32)pImage->height, pBuffer+22 );
199cdf0e10cSrcweir     writeLE( (sal_uInt16)1, pBuffer+26 );
200cdf0e10cSrcweir     writeLE( nBitCount, pBuffer+28 );
201cdf0e10cSrcweir     writeLE( (sal_uInt32)(DisplayWidth(pDisplay,DefaultScreen(pDisplay))*1000/DisplayWidthMM(pDisplay,DefaultScreen(pDisplay))), pBuffer+38);
202cdf0e10cSrcweir     writeLE( (sal_uInt32)(DisplayHeight(pDisplay,DefaultScreen(pDisplay))*1000/DisplayHeightMM(pDisplay,DefaultScreen(pDisplay))), pBuffer+42);
203cdf0e10cSrcweir     writeLE( nColors, pBuffer+46 );
204cdf0e10cSrcweir     writeLE( nColors, pBuffer+50 );
205cdf0e10cSrcweir 
206cdf0e10cSrcweir     XColor aColors[256];
207cdf0e10cSrcweir     if( nColors > (1U << nBitCount) ) // paranoia
208cdf0e10cSrcweir         nColors = (1U << nBitCount);
209cdf0e10cSrcweir     for( unsigned long nPixel = 0; nPixel < nColors; nPixel++ )
210cdf0e10cSrcweir     {
211cdf0e10cSrcweir         aColors[nPixel].flags = DoRed | DoGreen | DoBlue;
212cdf0e10cSrcweir         aColors[nPixel].pixel = nPixel;
213cdf0e10cSrcweir     }
214cdf0e10cSrcweir     XQueryColors( pDisplay, aColormap, aColors, nColors );
215cdf0e10cSrcweir     for( sal_uInt32 i = 0; i < nColors; i++ )
216cdf0e10cSrcweir     {
217cdf0e10cSrcweir         pBuffer[ 54 + i*4 ] = (sal_uInt8)(aColors[i].blue >> 8);
218cdf0e10cSrcweir         pBuffer[ 55 + i*4 ] = (sal_uInt8)(aColors[i].green >> 8);
219cdf0e10cSrcweir         pBuffer[ 56 + i*4 ] = (sal_uInt8)(aColors[i].red >> 8);
220cdf0e10cSrcweir     }
221cdf0e10cSrcweir 
222cdf0e10cSrcweir     // done
223cdf0e10cSrcweir 
224cdf0e10cSrcweir     return pBuffer;
225cdf0e10cSrcweir }
226cdf0e10cSrcweir 
doRightShift(unsigned long nValue,int nShift)227cdf0e10cSrcweir inline unsigned long doRightShift( unsigned long nValue, int nShift )
228cdf0e10cSrcweir {
229cdf0e10cSrcweir     return (nShift > 0) ? (nValue >> nShift) : (nValue << (-nShift));
230cdf0e10cSrcweir }
231cdf0e10cSrcweir 
doLeftShift(unsigned long nValue,int nShift)232cdf0e10cSrcweir inline unsigned long doLeftShift( unsigned long nValue, int nShift )
233cdf0e10cSrcweir {
234cdf0e10cSrcweir     return (nShift > 0) ? (nValue << nShift) : (nValue >> (-nShift));
235cdf0e10cSrcweir }
236cdf0e10cSrcweir 
getShift(unsigned long nMask,int & rShift,int & rSigBits,int & rShift2)237cdf0e10cSrcweir static void getShift( unsigned long nMask, int& rShift, int& rSigBits, int& rShift2 )
238cdf0e10cSrcweir {
239cdf0e10cSrcweir     unsigned long nUseMask = nMask;
240cdf0e10cSrcweir     rShift = 0;
241cdf0e10cSrcweir     while( nMask & 0xffffff00 )
242cdf0e10cSrcweir     {
243cdf0e10cSrcweir         rShift++;
244cdf0e10cSrcweir         nMask >>= 1;
245cdf0e10cSrcweir     }
246cdf0e10cSrcweir     if( rShift == 0 )
247cdf0e10cSrcweir         while( ! (nMask & 0x00000080) )
248cdf0e10cSrcweir         {
249cdf0e10cSrcweir             rShift--;
250cdf0e10cSrcweir             nMask <<= 1;
251cdf0e10cSrcweir         }
252cdf0e10cSrcweir 
253cdf0e10cSrcweir     int nRotate = sizeof(unsigned long)*8 - rShift;
254cdf0e10cSrcweir     rSigBits = 0;
255cdf0e10cSrcweir     nMask = doRightShift( nUseMask, rShift) ;
256cdf0e10cSrcweir     while( nRotate-- )
257cdf0e10cSrcweir     {
258cdf0e10cSrcweir         if( nMask & 1 )
259cdf0e10cSrcweir             rSigBits++;
260cdf0e10cSrcweir         nMask >>= 1;
261cdf0e10cSrcweir     }
262cdf0e10cSrcweir 
263cdf0e10cSrcweir     rShift2 = 0;
264cdf0e10cSrcweir     if( rSigBits < 8 )
265cdf0e10cSrcweir         rShift2 = 8-rSigBits;
266cdf0e10cSrcweir }
267cdf0e10cSrcweir 
X11_getTCBmpFromImage(Display * pDisplay,XImage * pImage,sal_Int32 & rOutSize,int nScreenNo)268cdf0e10cSrcweir static sal_uInt8* X11_getTCBmpFromImage(
269cdf0e10cSrcweir                                              Display* pDisplay,
270cdf0e10cSrcweir                                              XImage* pImage,
271cdf0e10cSrcweir                                              sal_Int32& rOutSize,
272cdf0e10cSrcweir                                              int nScreenNo
273cdf0e10cSrcweir                                              )
274cdf0e10cSrcweir {
275cdf0e10cSrcweir     // get masks from visual info (guesswork)
276cdf0e10cSrcweir     XVisualInfo aVInfo;
277cdf0e10cSrcweir     if( ! XMatchVisualInfo( pDisplay, nScreenNo, pImage->depth, TrueColor, &aVInfo ) )
278cdf0e10cSrcweir         return NULL;
279cdf0e10cSrcweir 
280cdf0e10cSrcweir     rOutSize = 0;
281cdf0e10cSrcweir 
282cdf0e10cSrcweir     sal_uInt8* pBuffer = 0;
283cdf0e10cSrcweir     sal_uInt32 nHeaderSize = 60;
284cdf0e10cSrcweir     sal_uInt32 nScanlineSize = pImage->width*3;
285cdf0e10cSrcweir 
286cdf0e10cSrcweir     // adjust scan lines to begin on %4 boundaries
287cdf0e10cSrcweir     if( nScanlineSize & 3 )
288cdf0e10cSrcweir     {
289cdf0e10cSrcweir         nScanlineSize &= 0xfffffffc;
290cdf0e10cSrcweir         nScanlineSize += 4;
291cdf0e10cSrcweir     }
292cdf0e10cSrcweir     int nRedShift, nRedSig, nRedShift2 = 0;
293cdf0e10cSrcweir     getShift( aVInfo.red_mask, nRedShift, nRedSig, nRedShift2 );
294cdf0e10cSrcweir     int nGreenShift, nGreenSig, nGreenShift2 = 0;
295cdf0e10cSrcweir     getShift( aVInfo.green_mask, nGreenShift, nGreenSig, nGreenShift2 );
296cdf0e10cSrcweir     int nBlueShift, nBlueSig, nBlueShift2 = 0;
297cdf0e10cSrcweir     getShift( aVInfo.blue_mask, nBlueShift, nBlueSig, nBlueShift2 );
298cdf0e10cSrcweir 
299cdf0e10cSrcweir     // allocate buffer to hold header and scanlines, initialize to zero
300cdf0e10cSrcweir     rOutSize = nHeaderSize + nScanlineSize*pImage->height;
301cdf0e10cSrcweir     pBuffer = (sal_uInt8*)rtl_allocateZeroMemory( rOutSize );
302cdf0e10cSrcweir     for( int y = 0; y < pImage->height; y++ )
303cdf0e10cSrcweir     {
304cdf0e10cSrcweir         sal_uInt8* pScanline = pBuffer + nHeaderSize + (pImage->height-1-y)*nScanlineSize;
305cdf0e10cSrcweir         for( int x = 0; x < pImage->width; x++ )
306cdf0e10cSrcweir         {
307cdf0e10cSrcweir             unsigned long nPixel = XGetPixel( pImage, x, y );
308cdf0e10cSrcweir 
309cdf0e10cSrcweir             sal_uInt8 nValue = (sal_uInt8)doRightShift( nPixel&aVInfo.blue_mask, nBlueShift);
310cdf0e10cSrcweir             if( nBlueShift2 )
311cdf0e10cSrcweir                 nValue |= (nValue >> nBlueShift2 );
312cdf0e10cSrcweir             *pScanline++ = nValue;
313cdf0e10cSrcweir 
314cdf0e10cSrcweir             nValue = (sal_uInt8)doRightShift( nPixel&aVInfo.green_mask, nGreenShift);
315cdf0e10cSrcweir             if( nGreenShift2 )
316cdf0e10cSrcweir                 nValue |= (nValue >> nGreenShift2 );
317cdf0e10cSrcweir             *pScanline++ = nValue;
318cdf0e10cSrcweir 
319cdf0e10cSrcweir             nValue = (sal_uInt8)doRightShift( nPixel&aVInfo.red_mask, nRedShift);
320cdf0e10cSrcweir             if( nRedShift2 )
321cdf0e10cSrcweir                 nValue |= (nValue >> nRedShift2 );
322cdf0e10cSrcweir             *pScanline++ = nValue;
323cdf0e10cSrcweir         }
324cdf0e10cSrcweir     }
325cdf0e10cSrcweir 
326cdf0e10cSrcweir     // fill in header fields
327cdf0e10cSrcweir     pBuffer[  0 ] = 'B';
328cdf0e10cSrcweir     pBuffer[  1 ] = 'M';
329cdf0e10cSrcweir 
330cdf0e10cSrcweir     writeLE( nHeaderSize, pBuffer+10 );
331cdf0e10cSrcweir     writeLE( (sal_uInt32)40, pBuffer+14 );
332cdf0e10cSrcweir     writeLE( (sal_uInt32)pImage->width, pBuffer+18 );
333cdf0e10cSrcweir     writeLE( (sal_uInt32)pImage->height, pBuffer+22 );
334cdf0e10cSrcweir     writeLE( (sal_uInt16)1, pBuffer+26 );
335cdf0e10cSrcweir     writeLE( (sal_uInt16)24, pBuffer+28 );
336cdf0e10cSrcweir     writeLE( (sal_uInt32)(DisplayWidth(pDisplay,DefaultScreen(pDisplay))*1000/DisplayWidthMM(pDisplay,DefaultScreen(pDisplay))), pBuffer+38);
337cdf0e10cSrcweir     writeLE( (sal_uInt32)(DisplayHeight(pDisplay,DefaultScreen(pDisplay))*1000/DisplayHeightMM(pDisplay,DefaultScreen(pDisplay))), pBuffer+42);
338cdf0e10cSrcweir 
339cdf0e10cSrcweir     // done
340cdf0e10cSrcweir 
341cdf0e10cSrcweir     return pBuffer;
342cdf0e10cSrcweir }
343cdf0e10cSrcweir 
X11_getBmpFromPixmap(Display * pDisplay,Drawable aDrawable,Colormap aColormap,sal_Int32 & rOutSize)344cdf0e10cSrcweir sal_uInt8* x11::X11_getBmpFromPixmap(
345cdf0e10cSrcweir                                 Display* pDisplay,
346cdf0e10cSrcweir                                 Drawable aDrawable,
347cdf0e10cSrcweir                                 Colormap aColormap,
348cdf0e10cSrcweir                                 sal_Int32& rOutSize
349cdf0e10cSrcweir                                 )
350cdf0e10cSrcweir {
351cdf0e10cSrcweir     // get geometry of drawable
352cdf0e10cSrcweir     XLIB_Window aRoot;
353cdf0e10cSrcweir     int x,y;
354cdf0e10cSrcweir     unsigned int w, h, bw, d;
355cdf0e10cSrcweir     XGetGeometry( pDisplay, aDrawable, &aRoot, &x, &y, &w, &h, &bw, &d );
356cdf0e10cSrcweir 
357cdf0e10cSrcweir     // find which screen we are on
358cdf0e10cSrcweir     int nScreenNo = ScreenCount( pDisplay );
359cdf0e10cSrcweir     while( nScreenNo-- )
360cdf0e10cSrcweir     {
361cdf0e10cSrcweir         if( RootWindow( pDisplay, nScreenNo ) == aRoot )
362cdf0e10cSrcweir             break;
363cdf0e10cSrcweir     }
364cdf0e10cSrcweir     if( nScreenNo < 0 )
365cdf0e10cSrcweir         return NULL;
366cdf0e10cSrcweir 
367cdf0e10cSrcweir     if( aColormap == None )
368cdf0e10cSrcweir         aColormap = DefaultColormap( pDisplay, nScreenNo );
369cdf0e10cSrcweir 
370cdf0e10cSrcweir     // get the image
371cdf0e10cSrcweir     XImage* pImage = XGetImage( pDisplay, aDrawable, 0, 0, w, h, AllPlanes, ZPixmap );
372cdf0e10cSrcweir     if( ! pImage )
373cdf0e10cSrcweir         return NULL;
374cdf0e10cSrcweir 
375cdf0e10cSrcweir     sal_uInt8* pBmp = d <= 8 ?
376cdf0e10cSrcweir         X11_getPaletteBmpFromImage( pDisplay, pImage, aColormap, rOutSize ) :
377cdf0e10cSrcweir         X11_getTCBmpFromImage( pDisplay, pImage, rOutSize, nScreenNo );
378cdf0e10cSrcweir     XDestroyImage( pImage );
379cdf0e10cSrcweir 
380cdf0e10cSrcweir     return pBmp;
381cdf0e10cSrcweir }
382cdf0e10cSrcweir 
X11_freeBmp(sal_uInt8 * pBmp)383cdf0e10cSrcweir void x11::X11_freeBmp( sal_uInt8* pBmp )
384cdf0e10cSrcweir {
385cdf0e10cSrcweir     rtl_freeMemory( pBmp );
386cdf0e10cSrcweir }
387cdf0e10cSrcweir 
388cdf0e10cSrcweir /*
389cdf0e10cSrcweir  *  PixmapHolder
390cdf0e10cSrcweir  */
391cdf0e10cSrcweir 
PixmapHolder(Display * pDisplay)392cdf0e10cSrcweir PixmapHolder::PixmapHolder( Display* pDisplay ) :
393cdf0e10cSrcweir         m_pDisplay( pDisplay ),
394cdf0e10cSrcweir         m_aColormap( None ),
395cdf0e10cSrcweir         m_aPixmap( None ),
396cdf0e10cSrcweir         m_aBitmap( None )
397cdf0e10cSrcweir {
398cdf0e10cSrcweir     /*  try to get a 24 bit true color visual, if that fails,
399cdf0e10cSrcweir      *  revert to default visual
400cdf0e10cSrcweir      */
401cdf0e10cSrcweir     if( ! XMatchVisualInfo( m_pDisplay, DefaultScreen( m_pDisplay ), 24, TrueColor, &m_aInfo ) )
402cdf0e10cSrcweir     {
403cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 1
404cdf0e10cSrcweir         fprintf( stderr, "PixmapHolder reverting to default visual\n" );
405cdf0e10cSrcweir #endif
406cdf0e10cSrcweir         Visual* pVisual		= DefaultVisual( m_pDisplay, DefaultScreen( m_pDisplay ) );
407cdf0e10cSrcweir         m_aInfo.screen		= DefaultScreen( m_pDisplay );
408cdf0e10cSrcweir         m_aInfo.visual		= pVisual;
409cdf0e10cSrcweir         m_aInfo.visualid	= pVisual->visualid;
410cdf0e10cSrcweir         m_aInfo.c_class		= pVisual->c_class;
411cdf0e10cSrcweir         m_aInfo.red_mask	= pVisual->red_mask;
412cdf0e10cSrcweir         m_aInfo.green_mask	= pVisual->green_mask;
413cdf0e10cSrcweir         m_aInfo.blue_mask	= pVisual->blue_mask;
414cdf0e10cSrcweir         m_aInfo.depth		= DefaultDepth( m_pDisplay, m_aInfo.screen );
415cdf0e10cSrcweir     }
416cdf0e10cSrcweir     m_aColormap			= DefaultColormap( m_pDisplay, m_aInfo.screen );
417cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 1
418cdf0e10cSrcweir     static const char* pClasses[] =
419cdf0e10cSrcweir         { "StaticGray", "GrayScale", "StaticColor", "PseudoColor", "TrueColor", "DirectColor" };
420cdf0e10cSrcweir     fprintf( stderr, "PixmapHolder visual: id = 0x%lx, class = %s (%d), depth=%d; color map = 0x%lx\n",
421cdf0e10cSrcweir              m_aInfo.visualid,
422cdf0e10cSrcweir              (m_aInfo.c_class >= 0 && unsigned(m_aInfo.c_class) < sizeof(pClasses)/sizeof(pClasses[0])) ? pClasses[m_aInfo.c_class] : "<unknown>",
423cdf0e10cSrcweir              m_aInfo.c_class,
424cdf0e10cSrcweir              m_aInfo.depth,
425cdf0e10cSrcweir              m_aColormap  );
426cdf0e10cSrcweir #endif
427cdf0e10cSrcweir     if( m_aInfo.c_class == TrueColor )
428cdf0e10cSrcweir     {
429cdf0e10cSrcweir         int nRedSig, nGreenSig, nBlueSig;
430cdf0e10cSrcweir         m_nRedShift = m_nRedShift2 = 0;
431cdf0e10cSrcweir         getShift( m_aInfo.red_mask, m_nRedShift, nRedSig, m_nRedShift2 );
432cdf0e10cSrcweir         m_nGreenShift = m_nGreenShift2 = 0;
433cdf0e10cSrcweir         getShift( m_aInfo.green_mask, m_nGreenShift, nGreenSig, m_nGreenShift2 );
434cdf0e10cSrcweir         m_nBlueShift = m_nBlueShift2 = 0;
435cdf0e10cSrcweir         getShift( m_aInfo.blue_mask, m_nBlueShift, nBlueSig, m_nBlueShift2 );
436cdf0e10cSrcweir 
437cdf0e10cSrcweir         m_nBlueShift2Mask = m_nBlueShift2 ? ~((unsigned long)((1<<m_nBlueShift2)-1)) : ~0L;
438cdf0e10cSrcweir         m_nGreenShift2Mask = m_nGreenShift2 ? ~((unsigned long)((1<<m_nGreenShift2)-1)) : ~0L;
439cdf0e10cSrcweir         m_nRedShift2Mask = m_nRedShift2 ? ~((unsigned long)((1<<m_nRedShift2)-1)) : ~0L;
440cdf0e10cSrcweir     }
441cdf0e10cSrcweir }
442cdf0e10cSrcweir 
~PixmapHolder()443cdf0e10cSrcweir PixmapHolder::~PixmapHolder()
444cdf0e10cSrcweir {
445cdf0e10cSrcweir     if( m_aPixmap != None )
446cdf0e10cSrcweir         XFreePixmap( m_pDisplay, m_aPixmap );
447cdf0e10cSrcweir     if( m_aBitmap != None )
448cdf0e10cSrcweir         XFreePixmap( m_pDisplay, m_aBitmap );
449cdf0e10cSrcweir }
450cdf0e10cSrcweir 
getTCPixel(sal_uInt8 r,sal_uInt8 g,sal_uInt8 b) const451cdf0e10cSrcweir unsigned long PixmapHolder::getTCPixel( sal_uInt8 r, sal_uInt8 g, sal_uInt8 b ) const
452cdf0e10cSrcweir {
453cdf0e10cSrcweir     unsigned long nPixel = 0;
454cdf0e10cSrcweir     unsigned long nValue = (unsigned long)b;
455cdf0e10cSrcweir     nValue &= m_nBlueShift2Mask;
456cdf0e10cSrcweir     nPixel |= doLeftShift( nValue, m_nBlueShift );
457cdf0e10cSrcweir 
458cdf0e10cSrcweir     nValue = (unsigned long)g;
459cdf0e10cSrcweir     nValue &= m_nGreenShift2Mask;
460cdf0e10cSrcweir     nPixel |= doLeftShift( nValue, m_nGreenShift );
461cdf0e10cSrcweir 
462cdf0e10cSrcweir     nValue = (unsigned long)r;
463cdf0e10cSrcweir     nValue &= m_nRedShift2Mask;
464cdf0e10cSrcweir     nPixel |= doLeftShift( nValue, m_nRedShift );
465cdf0e10cSrcweir 
466cdf0e10cSrcweir     return nPixel;
467cdf0e10cSrcweir }
468cdf0e10cSrcweir 
setBitmapDataPalette(const sal_uInt8 * pData,XImage * pImage)469cdf0e10cSrcweir void PixmapHolder::setBitmapDataPalette( const sal_uInt8* pData, XImage* pImage )
470cdf0e10cSrcweir {
471cdf0e10cSrcweir     // setup palette
472cdf0e10cSrcweir     XColor aPalette[256];
473cdf0e10cSrcweir 
474cdf0e10cSrcweir     sal_uInt32 nColors = readLE32( pData+32 );
475cdf0e10cSrcweir     sal_uInt32 nWidth	= readLE32( pData+4 );
476cdf0e10cSrcweir     sal_uInt32 nHeight	= readLE32( pData+8 );
477cdf0e10cSrcweir     sal_uInt16 nDepth = readLE16( pData+14 );
478cdf0e10cSrcweir 
479cdf0e10cSrcweir     for( sal_uInt16 i = 0 ; i < nColors; i++ )
480cdf0e10cSrcweir     {
481cdf0e10cSrcweir         if( m_aInfo.c_class != TrueColor )
482cdf0e10cSrcweir         {
483cdf0e10cSrcweir             aPalette[i].red		= ((unsigned short)pData[42 + i*4]) << 8 | ((unsigned short)pData[42 + i*4]);
484cdf0e10cSrcweir             aPalette[i].green	= ((unsigned short)pData[41 + i*4]) << 8 | ((unsigned short)pData[41 + i*4]);
485cdf0e10cSrcweir             aPalette[i].blue	= ((unsigned short)pData[40 + i*4]) << 8 | ((unsigned short)pData[40 + i*4]);
486cdf0e10cSrcweir             XAllocColor( m_pDisplay, m_aColormap, aPalette+i );
487cdf0e10cSrcweir         }
488cdf0e10cSrcweir         else
489cdf0e10cSrcweir             aPalette[i].pixel = getTCPixel( pData[42+i*4], pData[41+i*4], pData[40+i*4] );
490cdf0e10cSrcweir     }
491cdf0e10cSrcweir     const sal_uInt8* pBMData = pData + readLE32( pData ) + 4*nColors;
492cdf0e10cSrcweir 
493cdf0e10cSrcweir     sal_uInt32 nScanlineSize = 0;
494cdf0e10cSrcweir     switch( nDepth )
495cdf0e10cSrcweir     {
496cdf0e10cSrcweir         case 1:
497cdf0e10cSrcweir             nScanlineSize = (nWidth+31)/32;
498cdf0e10cSrcweir             break;
499cdf0e10cSrcweir         case 4:
500cdf0e10cSrcweir             nScanlineSize = (nWidth+1)/2;
501cdf0e10cSrcweir             break;
502cdf0e10cSrcweir         case 8:
503cdf0e10cSrcweir             nScanlineSize = nWidth;
504cdf0e10cSrcweir             break;
505cdf0e10cSrcweir     }
506cdf0e10cSrcweir     // adjust scan lines to begin on %4 boundaries
507cdf0e10cSrcweir     if( nScanlineSize & 3 )
508cdf0e10cSrcweir     {
509cdf0e10cSrcweir         nScanlineSize &= 0xfffffffc;
510cdf0e10cSrcweir         nScanlineSize += 4;
511cdf0e10cSrcweir     }
512cdf0e10cSrcweir 
513cdf0e10cSrcweir     // allocate buffer to hold header and scanlines, initialize to zero
514cdf0e10cSrcweir     for( unsigned int y = 0; y < nHeight; y++ )
515cdf0e10cSrcweir     {
516cdf0e10cSrcweir         const sal_uInt8* pScanline = pBMData + (nHeight-1-y)*nScanlineSize;
517cdf0e10cSrcweir         for( unsigned int x = 0; x < nWidth; x++ )
518cdf0e10cSrcweir         {
519cdf0e10cSrcweir             int nCol = 0;
520cdf0e10cSrcweir             switch( nDepth )
521cdf0e10cSrcweir             {
522cdf0e10cSrcweir                 case 1: nCol = (pScanline[ x/8 ] & (0x80 >> (x&7))) != 0 ? 0 : 1; break;
523cdf0e10cSrcweir                 case 4:
524cdf0e10cSrcweir                     if( x & 1 )
525cdf0e10cSrcweir                         nCol = (int)(pScanline[ x/2 ] >> 4);
526cdf0e10cSrcweir                     else
527cdf0e10cSrcweir                         nCol = (int)(pScanline[ x/2 ] & 0x0f);
528cdf0e10cSrcweir                     break;
529cdf0e10cSrcweir                 case 8: nCol = (int)pScanline[x];
530cdf0e10cSrcweir             }
531cdf0e10cSrcweir             XPutPixel( pImage, x, y, aPalette[nCol].pixel );
532cdf0e10cSrcweir         }
533cdf0e10cSrcweir     }
534cdf0e10cSrcweir }
535cdf0e10cSrcweir 
setBitmapDataTCDither(const sal_uInt8 * pData,XImage * pImage)536cdf0e10cSrcweir void PixmapHolder::setBitmapDataTCDither( const sal_uInt8* pData, XImage* pImage )
537cdf0e10cSrcweir {
538cdf0e10cSrcweir     XColor aPalette[216];
539cdf0e10cSrcweir 
540cdf0e10cSrcweir     int nNonAllocs = 0;
541cdf0e10cSrcweir 
542cdf0e10cSrcweir     for( int r = 0; r < 6; r++ )
543cdf0e10cSrcweir     {
544cdf0e10cSrcweir         for( int g = 0; g < 6; g++ )
545cdf0e10cSrcweir         {
546cdf0e10cSrcweir             for( int b = 0; b < 6; b++ )
547cdf0e10cSrcweir             {
548cdf0e10cSrcweir                 int i = r*36+g*6+b;
549cdf0e10cSrcweir                 aPalette[i].red		= r == 5 ? 0xffff : r*10922;
550cdf0e10cSrcweir                 aPalette[i].green	= g == 5 ? 0xffff : g*10922;
551cdf0e10cSrcweir                 aPalette[i].blue	= b == 5 ? 0xffff : b*10922;
552cdf0e10cSrcweir                 aPalette[i].pixel	= 0;
553cdf0e10cSrcweir                 if( ! XAllocColor( m_pDisplay, m_aColormap, aPalette+i ) )
554cdf0e10cSrcweir                     nNonAllocs++;
555cdf0e10cSrcweir             }
556cdf0e10cSrcweir         }
557cdf0e10cSrcweir     }
558cdf0e10cSrcweir 
559cdf0e10cSrcweir     if( nNonAllocs )
560cdf0e10cSrcweir     {
561cdf0e10cSrcweir         XColor aRealPalette[256];
562cdf0e10cSrcweir         int nColors = 1 << m_aInfo.depth;
563cdf0e10cSrcweir         int i;
564cdf0e10cSrcweir         for( i = 0; i < nColors; i++ )
565cdf0e10cSrcweir             aRealPalette[i].pixel = (unsigned long)i;
566cdf0e10cSrcweir         XQueryColors( m_pDisplay, m_aColormap, aRealPalette, nColors );
567cdf0e10cSrcweir         for( i = 0; i < nColors; i++ )
568cdf0e10cSrcweir         {
569cdf0e10cSrcweir             sal_uInt8 nIndex =
570cdf0e10cSrcweir                 36*(sal_uInt8)(aRealPalette[i].red/10923) +
571cdf0e10cSrcweir                 6*(sal_uInt8)(aRealPalette[i].green/10923) +
572cdf0e10cSrcweir                 (sal_uInt8)(aRealPalette[i].blue/10923);
573cdf0e10cSrcweir             if( aPalette[nIndex].pixel == 0 )
574cdf0e10cSrcweir                 aPalette[nIndex] = aRealPalette[i];
575cdf0e10cSrcweir         }
576cdf0e10cSrcweir     }
577cdf0e10cSrcweir 
578cdf0e10cSrcweir     sal_uInt32 nWidth	= readLE32( pData+4 );
579cdf0e10cSrcweir     sal_uInt32 nHeight	= readLE32( pData+8 );
580cdf0e10cSrcweir 
581cdf0e10cSrcweir     const sal_uInt8* pBMData = pData + readLE32( pData );
582cdf0e10cSrcweir     sal_uInt32 nScanlineSize = nWidth*3;
583cdf0e10cSrcweir     // adjust scan lines to begin on %4 boundaries
584cdf0e10cSrcweir     if( nScanlineSize & 3 )
585cdf0e10cSrcweir     {
586cdf0e10cSrcweir         nScanlineSize &= 0xfffffffc;
587cdf0e10cSrcweir         nScanlineSize += 4;
588cdf0e10cSrcweir     }
589cdf0e10cSrcweir 
590cdf0e10cSrcweir     for( int y = 0; y < (int)nHeight; y++ )
591cdf0e10cSrcweir     {
592cdf0e10cSrcweir         const sal_uInt8* pScanline = pBMData + (nHeight-1-(sal_uInt32)y)*nScanlineSize;
593cdf0e10cSrcweir         for( int x = 0; x < (int)nWidth; x++ )
594cdf0e10cSrcweir         {
595cdf0e10cSrcweir             sal_uInt8 b = pScanline[3*x];
596cdf0e10cSrcweir             sal_uInt8 g = pScanline[3*x+1];
597cdf0e10cSrcweir             sal_uInt8 r = pScanline[3*x+2];
598cdf0e10cSrcweir             sal_uInt8 i = 36*(r/43) + 6*(g/43) + (b/43);
599cdf0e10cSrcweir 
600cdf0e10cSrcweir             XPutPixel( pImage, x, y, aPalette[ i ].pixel );
601cdf0e10cSrcweir         }
602cdf0e10cSrcweir     }
603cdf0e10cSrcweir }
604cdf0e10cSrcweir 
setBitmapDataTC(const sal_uInt8 * pData,XImage * pImage)605cdf0e10cSrcweir void PixmapHolder::setBitmapDataTC( const sal_uInt8* pData, XImage* pImage )
606cdf0e10cSrcweir {
607cdf0e10cSrcweir     sal_uInt32 nWidth	= readLE32( pData+4 );
608cdf0e10cSrcweir     sal_uInt32 nHeight	= readLE32( pData+8 );
609cdf0e10cSrcweir 
610cdf0e10cSrcweir     const sal_uInt8* pBMData = pData + readLE32( pData );
611cdf0e10cSrcweir     sal_uInt32 nScanlineSize = nWidth*3;
612cdf0e10cSrcweir     // adjust scan lines to begin on %4 boundaries
613cdf0e10cSrcweir     if( nScanlineSize & 3 )
614cdf0e10cSrcweir     {
615cdf0e10cSrcweir         nScanlineSize &= 0xfffffffc;
616cdf0e10cSrcweir         nScanlineSize += 4;
617cdf0e10cSrcweir     }
618cdf0e10cSrcweir 
619cdf0e10cSrcweir     for( int y = 0; y < (int)nHeight; y++ )
620cdf0e10cSrcweir     {
621cdf0e10cSrcweir         const sal_uInt8* pScanline = pBMData + (nHeight-1-(sal_uInt32)y)*nScanlineSize;
622cdf0e10cSrcweir         for( int x = 0; x < (int)nWidth; x++ )
623cdf0e10cSrcweir         {
624cdf0e10cSrcweir             unsigned long nPixel = getTCPixel( pScanline[3*x+2], pScanline[3*x+1], pScanline[3*x] );
625cdf0e10cSrcweir             XPutPixel( pImage, x, y, nPixel );
626cdf0e10cSrcweir         }
627cdf0e10cSrcweir     }
628cdf0e10cSrcweir }
629cdf0e10cSrcweir 
needsConversion(const sal_uInt8 * pData)630cdf0e10cSrcweir bool PixmapHolder::needsConversion( const sal_uInt8* pData )
631cdf0e10cSrcweir {
632cdf0e10cSrcweir     if( pData[0] != 'B' || pData[1] != 'M' )
633cdf0e10cSrcweir         return true;
634cdf0e10cSrcweir 
635cdf0e10cSrcweir     pData = pData+14;
636cdf0e10cSrcweir     sal_uInt32 nDepth = readLE32( pData+14 );
637cdf0e10cSrcweir     if(  nDepth == 24 )
638cdf0e10cSrcweir     {
639cdf0e10cSrcweir         if( m_aInfo.c_class != TrueColor )
640cdf0e10cSrcweir             return true;
641cdf0e10cSrcweir     }
642cdf0e10cSrcweir     else if( nDepth != (sal_uInt32)m_aInfo.depth )
643cdf0e10cSrcweir     {
644cdf0e10cSrcweir         if( m_aInfo.c_class != TrueColor )
645cdf0e10cSrcweir             return true;
646cdf0e10cSrcweir     }
647cdf0e10cSrcweir 
648cdf0e10cSrcweir     return false;
649cdf0e10cSrcweir }
650cdf0e10cSrcweir 
setBitmapData(const sal_uInt8 * pData)651cdf0e10cSrcweir Pixmap PixmapHolder::setBitmapData( const sal_uInt8* pData )
652cdf0e10cSrcweir {
653cdf0e10cSrcweir     if( pData[0] != 'B' || pData[1] != 'M' )
654cdf0e10cSrcweir         return None;
655cdf0e10cSrcweir 
656cdf0e10cSrcweir     pData = pData+14;
657cdf0e10cSrcweir 
658cdf0e10cSrcweir     // reject compressed data
659cdf0e10cSrcweir     if( readLE32( pData + 16 ) != 0 )
660cdf0e10cSrcweir         return None;
661cdf0e10cSrcweir 
662cdf0e10cSrcweir     sal_uInt32 nWidth	= readLE32( pData+4 );
663cdf0e10cSrcweir     sal_uInt32 nHeight	= readLE32( pData+8 );
664cdf0e10cSrcweir 
665cdf0e10cSrcweir     if( m_aPixmap != None )
666cdf0e10cSrcweir         XFreePixmap( m_pDisplay, m_aPixmap ), m_aPixmap = None;
667cdf0e10cSrcweir     if( m_aBitmap != None )
668cdf0e10cSrcweir         XFreePixmap( m_pDisplay, m_aBitmap ), m_aBitmap = None;
669cdf0e10cSrcweir 
670cdf0e10cSrcweir     m_aPixmap = XCreatePixmap( m_pDisplay,
671cdf0e10cSrcweir                                RootWindow( m_pDisplay, m_aInfo.screen ),
672cdf0e10cSrcweir                                nWidth, nHeight, m_aInfo.depth );
673cdf0e10cSrcweir 
674cdf0e10cSrcweir     if( m_aPixmap != None )
675cdf0e10cSrcweir     {
676cdf0e10cSrcweir         XImage aImage;
677cdf0e10cSrcweir         aImage.width			= (int)nWidth;
678cdf0e10cSrcweir         aImage.height			= (int)nHeight;
679cdf0e10cSrcweir         aImage.xoffset			= 0;
680cdf0e10cSrcweir         aImage.format			= ZPixmap;
681cdf0e10cSrcweir         aImage.data				= NULL;
682cdf0e10cSrcweir         aImage.byte_order		= ImageByteOrder( m_pDisplay );
683cdf0e10cSrcweir         aImage.bitmap_unit		= BitmapUnit( m_pDisplay );
684cdf0e10cSrcweir         aImage.bitmap_bit_order	= BitmapBitOrder( m_pDisplay );
685cdf0e10cSrcweir         aImage.bitmap_pad		= BitmapPad( m_pDisplay );
686cdf0e10cSrcweir         aImage.depth			= m_aInfo.depth;
687cdf0e10cSrcweir         aImage.red_mask			= m_aInfo.red_mask;
688cdf0e10cSrcweir         aImage.green_mask		= m_aInfo.green_mask;
689cdf0e10cSrcweir         aImage.blue_mask		= m_aInfo.blue_mask;
690cdf0e10cSrcweir         aImage.bytes_per_line	= 0; // filled in by XInitImage
691cdf0e10cSrcweir         if( m_aInfo.depth <= 8 )
692cdf0e10cSrcweir             aImage.bits_per_pixel = m_aInfo.depth;
693cdf0e10cSrcweir         else
694cdf0e10cSrcweir             aImage.bits_per_pixel = 8*((m_aInfo.depth+7)/8);
695cdf0e10cSrcweir         aImage.obdata			= NULL;
696cdf0e10cSrcweir 
697cdf0e10cSrcweir         XInitImage( &aImage );
698cdf0e10cSrcweir         aImage.data = (char*)rtl_allocateMemory( nHeight*aImage.bytes_per_line );
699cdf0e10cSrcweir 
700cdf0e10cSrcweir         if( readLE32( pData+14 ) == 24 )
701cdf0e10cSrcweir         {
702cdf0e10cSrcweir             if( m_aInfo.c_class == TrueColor )
703cdf0e10cSrcweir                 setBitmapDataTC( pData, &aImage );
704cdf0e10cSrcweir             else
705cdf0e10cSrcweir                 setBitmapDataTCDither( pData, &aImage );
706cdf0e10cSrcweir         }
707cdf0e10cSrcweir         else
708cdf0e10cSrcweir             setBitmapDataPalette( pData, &aImage );
709cdf0e10cSrcweir 
710cdf0e10cSrcweir         // put the image
711cdf0e10cSrcweir         XPutImage( m_pDisplay,
712cdf0e10cSrcweir                    m_aPixmap,
713cdf0e10cSrcweir                    DefaultGC( m_pDisplay, m_aInfo.screen ),
714cdf0e10cSrcweir                    &aImage,
715cdf0e10cSrcweir                    0, 0,
716cdf0e10cSrcweir                    0, 0,
717cdf0e10cSrcweir                    nWidth, nHeight );
718cdf0e10cSrcweir 
719cdf0e10cSrcweir         // clean up
720cdf0e10cSrcweir         rtl_freeMemory( aImage.data );
721cdf0e10cSrcweir 
722cdf0e10cSrcweir         // prepare bitmap (mask)
723cdf0e10cSrcweir         m_aBitmap = XCreatePixmap( m_pDisplay,
724cdf0e10cSrcweir                                    RootWindow( m_pDisplay, m_aInfo.screen ),
725cdf0e10cSrcweir                                    nWidth, nHeight, 1 );
726cdf0e10cSrcweir         XGCValues aVal;
727cdf0e10cSrcweir         aVal.function = GXcopy;
728cdf0e10cSrcweir         aVal.foreground = 0xffffffff;
729cdf0e10cSrcweir         GC aGC = XCreateGC( m_pDisplay, m_aBitmap, GCFunction | GCForeground, &aVal );
730cdf0e10cSrcweir         XFillRectangle( m_pDisplay, m_aBitmap, aGC, 0, 0, nWidth, nHeight );
731cdf0e10cSrcweir         XFreeGC( m_pDisplay, aGC );
732cdf0e10cSrcweir     }
733cdf0e10cSrcweir 
734cdf0e10cSrcweir     return m_aPixmap;
735cdf0e10cSrcweir }
736