Release 971221
[wine.git] / objects / dib.c
blobb5d1cf2d9a38c76dee69f700df0f59f8f3418e3d
1 /*
2 * GDI device-independent bitmaps
4 * Copyright 1993,1994 Alexandre Julliard
5 */
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <X11/Xlib.h>
10 #include <X11/Xutil.h>
11 #include "dc.h"
12 #include "bitmap.h"
13 #include "callback.h"
14 #include "palette.h"
15 #include "stddebug.h"
16 #include "color.h"
17 #include "debug.h"
19 extern void CLIPPING_UpdateGCRegion(DC* );
21 static int bitmapDepthTable[] = { 8, 1, 32, 16, 24, 15, 4, 0 };
22 static int ximageDepthTable[] = { 0, 0, 0, 0, 0, 0, 0 };
25 /* This structure holds the arguments for DIB_SetImageBits() */
26 typedef struct
28 DC *dc;
29 LPCVOID bits;
30 int lines;
31 DWORD infoWidth;
32 WORD depth;
33 WORD infoBpp;
34 const BITMAPINFO *info;
35 WORD coloruse;
36 Drawable drawable;
37 GC gc;
38 int xSrc;
39 int ySrc;
40 int xDest;
41 int yDest;
42 int width;
43 int height;
44 } DIB_SETIMAGEBITS_DESCR;
47 /***********************************************************************
48 * DIB_Init
50 BOOL32 DIB_Init(void)
52 int i;
53 XImage* testimage;
55 for( i = 0; bitmapDepthTable[i]; i++ )
57 testimage = XCreateImage(display, DefaultVisualOfScreen(screen),
58 bitmapDepthTable[i], ZPixmap, 0, NULL, 1, 1, 32, 20 );
59 if( testimage ) ximageDepthTable[i] = testimage->bits_per_pixel;
60 else return FALSE;
61 XDestroyImage(testimage);
63 return TRUE;
66 /***********************************************************************
67 * DIB_GetXImageWidthBytes
69 * Return the width of an X image in bytes
71 int DIB_GetXImageWidthBytes( int width, int depth )
73 int i;
75 if (!ximageDepthTable[0]) {
76 DIB_Init();
78 for( i = 0; bitmapDepthTable[i] ; i++ )
79 if( bitmapDepthTable[i] == depth )
80 return (4 * ((width * ximageDepthTable[i] + 31)/32));
81 fprintf(stderr, "DIB: unsupported depth %d.\n", depth );
82 return (4 * width);
85 /***********************************************************************
86 * DIB_GetDIBWidthBytes
88 * Return the width of a DIB bitmap in bytes. DIB bitmap data is 32-bit aligned.
89 * http://www.microsoft.com/msdn/sdk/platforms/doc/sdk/win32/struc/src/str01.htm
91 int DIB_GetDIBWidthBytes( int width, int depth )
93 int words;
95 switch(depth)
97 case 1: words = (width + 31) / 32; break;
98 case 4: words = (width + 7) / 8; break;
99 case 8: words = (width + 3) / 4; break;
100 case 15:
101 case 16: words = (width + 1) / 2; break;
102 case 24: words = (width * 3 + 3)/4; break;
104 default:
105 fprintf(stderr, "DIB: unsupported depth %d.\n", depth );
106 /* fall through */
107 case 32:
108 words = width;
110 return 4 * words;
114 /***********************************************************************
115 * DIB_BitmapInfoSize
117 * Return the size of the bitmap info structure including color table.
119 int DIB_BitmapInfoSize( BITMAPINFO * info, WORD coloruse )
121 int colors;
123 if (info->bmiHeader.biSize == sizeof(BITMAPCOREHEADER))
125 BITMAPCOREHEADER *core = (BITMAPCOREHEADER *)info;
126 colors = (core->bcBitCount <= 8) ? 1 << core->bcBitCount : 0;
127 return sizeof(BITMAPCOREHEADER) + colors *
128 ((coloruse == DIB_RGB_COLORS) ? sizeof(RGBTRIPLE) : sizeof(WORD));
130 else /* assume BITMAPINFOHEADER */
132 colors = info->bmiHeader.biClrUsed;
133 if (!colors && (info->bmiHeader.biBitCount <= 8))
134 colors = 1 << info->bmiHeader.biBitCount;
135 return sizeof(BITMAPINFOHEADER) + colors *
136 ((coloruse == DIB_RGB_COLORS) ? sizeof(RGBQUAD) : sizeof(WORD));
141 /***********************************************************************
142 * DIB_GetBitmapInfo
144 * Get the info from a bitmap header.
145 * Return 1 for INFOHEADER, 0 for COREHEADER, -1 for error.
147 static int DIB_GetBitmapInfo( const BITMAPINFOHEADER *header, DWORD *width,
148 int *height, WORD *bpp )
150 if (header->biSize == sizeof(BITMAPINFOHEADER))
152 *width = header->biWidth;
153 *height = header->biHeight;
154 *bpp = header->biBitCount;
155 return 1;
157 if (header->biSize == sizeof(BITMAPCOREHEADER))
159 BITMAPCOREHEADER *core = (BITMAPCOREHEADER *)header;
160 *width = core->bcWidth;
161 *height = core->bcHeight;
162 *bpp = core->bcBitCount;
163 return 0;
165 fprintf( stderr, "DIB_GetBitmapInfo: wrong size (%ld) for header\n",
166 header->biSize );
167 return -1;
171 /***********************************************************************
172 * DIB_BuildColorMap
174 * Build the color map from the bitmap palette. Should not be called
175 * for a 24-bit deep bitmap.
177 static int *DIB_BuildColorMap( DC *dc, WORD coloruse, WORD depth,
178 const BITMAPINFO *info )
180 int i, colors;
181 BOOL32 isInfo;
182 WORD *colorPtr;
183 int *colorMapping;
185 if ((isInfo = (info->bmiHeader.biSize == sizeof(BITMAPINFOHEADER))))
187 colors = info->bmiHeader.biClrUsed;
188 if (!colors) colors = 1 << info->bmiHeader.biBitCount;
189 colorPtr = (WORD *)info->bmiColors;
191 else /* assume BITMAPCOREINFO */
193 colors = 1 << ((BITMAPCOREHEADER *)&info->bmiHeader)->bcBitCount;
194 colorPtr = (WORD *)((BITMAPCOREINFO *)info)->bmciColors;
196 if (!(colorMapping = (int *)HeapAlloc(GetProcessHeap(), 0,
197 colors * sizeof(int) ))) return NULL;
199 if (coloruse == DIB_RGB_COLORS)
201 if (isInfo)
203 RGBQUAD * rgb = (RGBQUAD *)colorPtr;
205 if (depth == 1) /* Monochrome */
206 for (i = 0; i < colors; i++, rgb++)
207 colorMapping[i] = (rgb->rgbRed + rgb->rgbGreen +
208 rgb->rgbBlue > 255*3/2);
209 else
210 for (i = 0; i < colors; i++, rgb++)
211 colorMapping[i] = COLOR_ToPhysical( dc, RGB(rgb->rgbRed,
212 rgb->rgbGreen,
213 rgb->rgbBlue));
215 else
217 RGBTRIPLE * rgb = (RGBTRIPLE *)colorPtr;
219 if (depth == 1) /* Monochrome */
220 for (i = 0; i < colors; i++, rgb++)
221 colorMapping[i] = (rgb->rgbtRed + rgb->rgbtGreen +
222 rgb->rgbtBlue > 255*3/2);
223 else
224 for (i = 0; i < colors; i++, rgb++)
225 colorMapping[i] = COLOR_ToPhysical( dc, RGB(rgb->rgbtRed,
226 rgb->rgbtGreen,
227 rgb->rgbtBlue));
230 else /* DIB_PAL_COLORS */
232 for (i = 0; i < colors; i++, colorPtr++)
233 colorMapping[i] = COLOR_ToPhysical( dc, PALETTEINDEX(*colorPtr) );
235 return colorMapping;
238 /***********************************************************************
239 * DIB_SetImageBits_1_Line
241 * Handles a single line of 1 bit data.
243 static void DIB_SetImageBits_1_Line(DWORD dstwidth, int *colors,
244 XImage *bmpImage, int h, const BYTE *bits)
246 BYTE pix;
247 DWORD i, x;
249 for (i = dstwidth/8, x = 0; (i > 0); i--)
251 pix = *bits++;
252 XPutPixel( bmpImage, x++, h, colors[pix >> 7] );
253 XPutPixel( bmpImage, x++, h, colors[(pix >> 6) & 1] );
254 XPutPixel( bmpImage, x++, h, colors[(pix >> 5) & 1] );
255 XPutPixel( bmpImage, x++, h, colors[(pix >> 4) & 1] );
256 XPutPixel( bmpImage, x++, h, colors[(pix >> 3) & 1] );
257 XPutPixel( bmpImage, x++, h, colors[(pix >> 2) & 1] );
258 XPutPixel( bmpImage, x++, h, colors[(pix >> 1) & 1] );
259 XPutPixel( bmpImage, x++, h, colors[pix & 1] );
261 pix = *bits;
262 switch(dstwidth & 7)
264 case 7: XPutPixel( bmpImage, x++, h, colors[pix >> 7] ); pix <<= 1;
265 case 6: XPutPixel( bmpImage, x++, h, colors[pix >> 7] ); pix <<= 1;
266 case 5: XPutPixel( bmpImage, x++, h, colors[pix >> 7] ); pix <<= 1;
267 case 4: XPutPixel( bmpImage, x++, h, colors[pix >> 7] ); pix <<= 1;
268 case 3: XPutPixel( bmpImage, x++, h, colors[pix >> 7] ); pix <<= 1;
269 case 2: XPutPixel( bmpImage, x++, h, colors[pix >> 7] ); pix <<= 1;
270 case 1: XPutPixel( bmpImage, x++, h, colors[pix >> 7] );
274 /***********************************************************************
275 * DIB_SetImageBits_1
277 * SetDIBits for a 1-bit deep DIB.
279 static void DIB_SetImageBits_1( int lines, const BYTE *srcbits,
280 DWORD srcwidth, DWORD dstwidth,
281 int *colors, XImage *bmpImage )
283 int h;
285 /* 32 bit aligned */
286 DWORD linebytes = ((srcwidth + 31) & ~31) / 8;
288 if (lines > 0) {
289 for (h = lines-1; h >=0; h--) {
290 DIB_SetImageBits_1_Line(dstwidth, colors, bmpImage, h, srcbits);
291 srcbits += linebytes;
293 } else {
294 lines = -lines;
295 for (h = 0; h < lines; h++) {
296 DIB_SetImageBits_1_Line(dstwidth, colors, bmpImage, h, srcbits);
297 srcbits += linebytes;
303 /***********************************************************************
304 * DIB_SetImageBits_4
306 * SetDIBits for a 4-bit deep DIB.
308 static void DIB_SetImageBits_4( int lines, const BYTE *srcbits,
309 DWORD srcwidth, DWORD dstwidth,
310 int *colors, XImage *bmpImage )
312 DWORD i, x;
313 int h;
314 const BYTE *bits = srcbits;
316 /* 32 bit aligned */
317 DWORD linebytes = ((srcwidth+7)&~7)/2;
319 if (lines > 0) {
320 for (h = lines-1; h >= 0; h--) {
321 for (i = dstwidth/2, x = 0; i > 0; i--) {
322 BYTE pix = *bits++;
323 XPutPixel( bmpImage, x++, h, colors[pix >> 4] );
324 XPutPixel( bmpImage, x++, h, colors[pix & 0x0f] );
326 if (dstwidth & 1) XPutPixel( bmpImage, x, h, colors[*bits >> 4] );
327 srcbits += linebytes;
328 bits = srcbits;
330 } else {
331 lines = -lines;
332 for (h = 0; h < lines; h++) {
333 for (i = dstwidth/2, x = 0; i > 0; i--) {
334 BYTE pix = *bits++;
335 XPutPixel( bmpImage, x++, h, colors[pix >> 4] );
336 XPutPixel( bmpImage, x++, h, colors[pix & 0x0f] );
338 if (dstwidth & 1) XPutPixel( bmpImage, x, h, colors[*bits >> 4] );
339 srcbits += linebytes;
340 bits = srcbits;
345 #define check_xy(x,y) \
346 if (x > width) { \
347 x = 0; \
348 if (lines) \
349 lines--; \
352 /***********************************************************************
353 * DIB_SetImageBits_RLE4
355 * SetDIBits for a 4-bit deep compressed DIB.
357 static void DIB_SetImageBits_RLE4( int lines, const BYTE *bits, DWORD width,
358 DWORD dstwidth, int *colors, XImage *bmpImage )
360 int x = 0, c, length;
361 const BYTE *begin = bits;
363 lines--;
364 while ((int)lines >= 0)
366 length = *bits++;
367 if (length) { /* encoded */
368 c = *bits++;
369 while (length--) {
370 XPutPixel(bmpImage, x++, lines, colors[c >> 4]);
371 check_xy(x, y);
372 if (length) {
373 length--;
374 XPutPixel(bmpImage, x++, lines, colors[c & 0xf]);
375 check_xy(x, y);
378 } else {
379 length = *bits++;
380 switch (length) {
381 case 0: /* eol */
382 x = 0;
383 lines--;
384 continue;
386 case 1: /* eopicture */
387 return;
389 case 2: /* delta */
390 x += *bits++;
391 lines -= *bits++;
392 continue;
394 default: /* absolute */
395 while (length--) {
396 c = *bits++;
397 XPutPixel(bmpImage, x++, lines, colors[c >> 4]);
398 check_xy(x, y);
399 if (length) {
400 length--;
401 XPutPixel(bmpImage, x++, lines, colors[c & 0xf]);
402 check_xy(x, y);
405 if ((bits - begin) & 1)
406 bits++;
412 /***********************************************************************
413 * DIB_SetImageBits_8
415 * SetDIBits for an 8-bit deep DIB.
417 static void DIB_SetImageBits_8( int lines, const BYTE *srcbits,
418 DWORD srcwidth, DWORD dstwidth,
419 int *colors, XImage *bmpImage )
421 DWORD x;
422 int h;
423 const BYTE *bits = srcbits;
425 /* align to 32 bit */
426 DWORD linebytes = (srcwidth + 3) & ~3;
428 if (lines > 0) {
429 for (h = lines - 1; h >= 0; h--) {
430 for (x = 0; x < dstwidth; x++, bits++) {
431 XPutPixel( bmpImage, x, h, colors[*bits] );
433 bits = (srcbits += linebytes);
435 } else {
436 lines = -lines;
437 for (h = 0; h < lines; h++) {
438 for (x = 0; x < dstwidth; x++, bits++) {
439 XPutPixel( bmpImage, x, h, colors[*bits] );
441 bits = (srcbits += linebytes);
446 /***********************************************************************
447 * DIB_SetImageBits_RLE8
449 * SetDIBits for an 8-bit deep compressed DIB.
451 * This function rewritten 941113 by James Youngman. WINE blew out when I
452 * first ran it because my desktop wallpaper is a (large) RLE8 bitmap.
454 * This was because the algorithm assumed that all RLE8 bitmaps end with the
455 * 'End of bitmap' escape code. This code is very much laxer in what it
456 * allows to end the expansion. Possibly too lax. See the note by
457 * case RleDelta. BTW, MS's documentation implies that a correct RLE8
458 * bitmap should end with RleEnd, but on the other hand, software exists
459 * that produces ones that don't and Windows 3.1 doesn't complain a bit
460 * about it.
462 * (No) apologies for my English spelling. [Emacs users: c-indent-level=4].
463 * James A. Youngman <mbcstjy@afs.man.ac.uk>
464 * [JAY]
467 enum Rle8_EscapeCodes
470 * Apologies for polluting your file's namespace...
472 RleEol = 0, /* End of line */
473 RleEnd = 1, /* End of bitmap */
474 RleDelta = 2 /* Delta */
477 static void DIB_SetImageBits_RLE8( int lines, const BYTE *bits, DWORD width,
478 DWORD dstwidth, int *colors, XImage *bmpImage )
480 int x; /* X-positon on each line. Increases. */
481 int line; /* Line #. Starts at lines-1, decreases */
482 const BYTE *pIn = bits; /* Pointer to current position in bits */
483 BYTE length; /* The length pf a run */
484 BYTE color_index; /* index into colors[] as read from bits */
485 BYTE escape_code; /* See enum Rle8_EscapeCodes.*/
486 WORD color; /* value of colour[color_index] */
488 if (lines == 0) /* Let's hope this doesn't happen. */
489 return;
492 * Note that the bitmap data is stored by Windows starting at the
493 * bottom line of the bitmap and going upwards. Within each line,
494 * the data is stored left-to-right. That's the reason why line
495 * goes from lines-1 to 0. [JAY]
498 x = 0;
499 line = lines-1;
502 length = *pIn++;
505 * If the length byte is not zero (which is the escape value),
506 * We have a run of length pixels all the same colour. The colour
507 * index is stored next.
509 * If the length byte is zero, we need to read the next byte to
510 * know what to do. [JAY]
512 if (length != 0)
515 * [Run-Length] Encoded mode
517 color_index = (*pIn++); /* Get the colour index. */
518 color = colors[color_index];
520 while(length--)
521 XPutPixel(bmpImage, x++, line, color);
523 else
526 * Escape codes (may be an absolute sequence though)
528 escape_code = (*pIn++);
529 switch(escape_code)
531 case RleEol: /* =0, end of line */
533 x = 0;
534 line--;
535 break;
538 case RleEnd: /* =1, end of bitmap */
541 * Not all RLE8 bitmaps end with this
542 * code. For example, Paint Shop Pro
543 * produces some that don't. That's (I think)
544 * what caused the previous implementation to
545 * fail. [JAY]
547 line=-1; /* Cause exit from do loop. */
548 break;
551 case RleDelta: /* =2, a delta */
554 * Note that deltaing to line 0
555 * will cause an exit from the loop,
556 * which may not be what is intended.
557 * The fact that there is a delta in the bits
558 * almost certainly implies that there is data
559 * to follow. You may feel that we should
560 * jump to the top of the loop to avoid exiting
561 * in this case.
563 * TODO: Decide what to do here in that case. [JAY]
565 x += (*pIn++);
566 line -= (*pIn++);
567 if (line == 0)
569 dprintf_bitmap(stddeb,
570 "DIB_SetImageBits_RLE8(): "
571 "Delta to last line of bitmap "
572 "(wrongly?) causes loop exit\n");
574 break;
577 default: /* >2, switch to absolute mode */
580 * Absolute Mode
582 length = escape_code;
583 while(length--)
585 color_index = (*pIn++);
586 XPutPixel(bmpImage, x++, line,
587 colors[color_index]);
591 * If you think for a moment you'll realise that the
592 * only time we could ever possibly read an odd
593 * number of bytes is when there is a 0x00 (escape),
594 * a value >0x02 (absolute mode) and then an odd-
595 * length run. Therefore this is the only place we
596 * need to worry about it. Everywhere else the
597 * bytes are always read in pairs. [JAY]
599 if (escape_code & 1)
600 pIn++; /* Throw away the pad byte. */
601 break;
603 } /* switch (escape_code) : Escape sequence */
604 } /* process either an encoded sequence or an escape sequence */
606 /* We expect to come here more than once per line. */
607 } while (line >= 0); /* Do this until the bitmap is filled */
610 * Everybody comes here at the end.
611 * Check how we exited the loop and print a message if it's a bit odd.
612 * [JAY]
614 if ( (*(pIn-2) != 0/*escape*/) || (*(pIn-1)!= RleEnd) )
616 dprintf_bitmap(stddeb, "DIB_SetImageBits_RLE8(): End-of-bitmap "
617 "without (strictly) proper escape code. Last two "
618 "bytes were: %02X %02X.\n",
619 (int)*(pIn-2),
620 (int)*(pIn-1));
625 /***********************************************************************
626 * DIB_SetImageBits_16
628 * SetDIBits for a 16-bit deep DIB.
630 static void DIB_SetImageBits_16( int lines, const BYTE *srcbits,
631 DWORD srcwidth, DWORD dstwidth,
632 DC *dc, XImage *bmpImage )
634 DWORD x;
635 LPWORD ptr;
636 WORD val;
637 int h;
638 BYTE r, g, b;
640 /* align to 32 bit */
641 DWORD linebytes = (srcwidth * 2 + 3) & ~3;
643 ptr = (LPWORD) srcbits;
644 if (lines > 0) {
645 for (h = lines - 1; h >= 0; h--) {
646 for (x = 0; x < dstwidth; x++, ptr++) {
647 val = *ptr;
648 r = (BYTE) ((val & 0x7c00) >> 7);
649 g = (BYTE) ((val & 0x03e0) >> 2);
650 b = (BYTE) ((val & 0x001f) << 3);
651 XPutPixel( bmpImage, x, h,
652 COLOR_ToPhysical(dc, RGB(r,g,b)) );
654 ptr = (LPWORD) (srcbits += linebytes);
656 } else {
657 lines = -lines;
658 for (h = 0; h < lines; h++) {
659 for (x = 0; x < dstwidth; x++, ptr++) {
660 val = *ptr;
661 r = (BYTE) ((val & 0x7c00) >> 7);
662 g = (BYTE) ((val & 0x03e0) >> 2);
663 b = (BYTE) ((val & 0x001f) << 3);
664 XPutPixel( bmpImage, x, h,
665 COLOR_ToPhysical(dc, RGB(r,g,b)) );
667 ptr = (LPWORD) (srcbits += linebytes);
673 /***********************************************************************
674 * DIB_SetImageBits_24
676 * SetDIBits for a 24-bit deep DIB.
678 static void DIB_SetImageBits_24( int lines, const BYTE *srcbits,
679 DWORD srcwidth, DWORD dstwidth,
680 DC *dc, XImage *bmpImage )
682 DWORD x;
683 const BYTE *bits = srcbits;
684 int h;
686 /* align to 32 bit */
687 DWORD linebytes = (srcwidth * 3 + 3) & ~3;
689 /* "bits" order is reversed for some reason */
691 if (lines > 0) {
692 for (h = lines - 1; h >= 0; h--) {
693 for (x = 0; x < dstwidth; x++, bits += 3) {
694 XPutPixel( bmpImage, x, h,
695 COLOR_ToPhysical(dc, RGB(bits[2],bits[1],bits[0])));
697 bits = (srcbits += linebytes);
699 } else {
700 lines = -lines;
701 for (h = 0; h < lines; h++) {
702 for (x = 0; x < dstwidth; x++, bits += 3) {
703 XPutPixel( bmpImage, x, h,
704 COLOR_ToPhysical(dc, RGB(bits[2],bits[1],bits[0])));
706 bits = (srcbits += linebytes);
712 /***********************************************************************
713 * DIB_SetImageBits_32
715 * SetDIBits for a 32-bit deep DIB.
717 static void DIB_SetImageBits_32( int lines, const BYTE *srcbits,
718 DWORD srcwidth, DWORD dstwidth,
719 DC *dc, XImage *bmpImage )
721 DWORD x;
722 const BYTE *bits = srcbits;
723 int h;
725 DWORD linebytes = (srcwidth * 4);
727 if (lines > 0) {
728 for (h = lines - 1; h >= 0; h--) {
729 for (x = 0; x < dstwidth; x++, bits += 4) {
730 XPutPixel( bmpImage, x, h,
731 COLOR_ToPhysical(dc, RGB(bits[2],bits[1],bits[0])));
733 bits = (srcbits += linebytes);
735 } else {
736 lines = -lines;
737 for (h = 0; h < lines; h++) {
738 for (x = 0; x < dstwidth; x++, bits += 4) {
739 XPutPixel( bmpImage, x, h,
740 COLOR_ToPhysical(dc, RGB(bits[2],bits[1],bits[0])));
742 bits = (srcbits += linebytes);
748 /***********************************************************************
749 * DIB_SetImageBits
751 * Transfer the bits to an X image.
752 * Helper function for SetDIBits() and SetDIBitsToDevice().
754 static int DIB_SetImageBits( const DIB_SETIMAGEBITS_DESCR *descr )
756 int *colorMapping;
757 XImage *bmpImage;
758 DWORD compression = 0;
759 int lines;
761 if (descr->info->bmiHeader.biSize == sizeof(BITMAPINFOHEADER))
762 compression = descr->info->bmiHeader.biCompression;
764 /* Build the color mapping table */
766 if (descr->infoBpp > 8) colorMapping = NULL;
767 else if (!(colorMapping = DIB_BuildColorMap( descr->dc, descr->coloruse,
768 descr->depth, descr->info )))
769 return 0;
771 if( descr->dc->w.flags & DC_DIRTY ) CLIPPING_UpdateGCRegion(descr->dc);
773 /* Transfer the pixels */
774 lines = descr->lines;
775 if (lines < 0) lines = -lines;
776 XCREATEIMAGE(bmpImage, descr->infoWidth, lines, descr->depth );
778 switch(descr->infoBpp)
780 case 1:
781 DIB_SetImageBits_1( descr->lines, descr->bits, descr->infoWidth,
782 descr->width, colorMapping, bmpImage );
783 break;
784 case 4:
785 if (compression) DIB_SetImageBits_RLE4( descr->lines, descr->bits,
786 descr->infoWidth, descr->width,
787 colorMapping, bmpImage );
788 else DIB_SetImageBits_4( descr->lines, descr->bits, descr->infoWidth,
789 descr->width, colorMapping, bmpImage );
790 break;
791 case 8:
792 if (compression) DIB_SetImageBits_RLE8( descr->lines, descr->bits,
793 descr->infoWidth, descr->width,
794 colorMapping, bmpImage );
795 else DIB_SetImageBits_8( descr->lines, descr->bits, descr->infoWidth,
796 descr->width, colorMapping, bmpImage );
797 break;
798 case 15:
799 case 16:
800 DIB_SetImageBits_16( descr->lines, descr->bits, descr->infoWidth,
801 descr->width, descr->dc, bmpImage);
802 break;
803 case 24:
804 DIB_SetImageBits_24( descr->lines, descr->bits, descr->infoWidth,
805 descr->width, descr->dc, bmpImage );
806 break;
807 case 32:
808 DIB_SetImageBits_32( descr->lines, descr->bits, descr->infoWidth,
809 descr->width, descr->dc, bmpImage);
810 break;
811 default:
812 fprintf( stderr, "Invalid depth %d for SetDIBits!\n", descr->infoBpp );
813 break;
815 if (colorMapping) HeapFree( GetProcessHeap(), 0, colorMapping );
816 XPutImage( display, descr->drawable, descr->gc, bmpImage,
817 descr->xSrc, descr->ySrc, descr->xDest, descr->yDest,
818 descr->width, descr->height );
819 XDestroyImage( bmpImage );
820 return lines;
824 /***********************************************************************
825 * StretchDIBits16 (GDI.439)
827 INT16 WINAPI StretchDIBits16(HDC16 hdc, INT16 xDst, INT16 yDst, INT16 widthDst,
828 INT16 heightDst, INT16 xSrc, INT16 ySrc, INT16 widthSrc,
829 INT16 heightSrc, const VOID *bits,
830 const BITMAPINFO *info, UINT16 wUsage, DWORD dwRop )
832 return (INT16)StretchDIBits32( hdc, xDst, yDst, widthDst, heightDst,
833 xSrc, ySrc, widthSrc, heightSrc, bits,
834 info, wUsage, dwRop );
838 /***********************************************************************
839 * StretchDIBits32 (GDI32.351)
841 INT32 WINAPI StretchDIBits32(HDC32 hdc, INT32 xDst, INT32 yDst, INT32 widthDst,
842 INT32 heightDst, INT32 xSrc, INT32 ySrc, INT32 widthSrc,
843 INT32 heightSrc, const void *bits,
844 const BITMAPINFO *info, UINT32 wUsage, DWORD dwRop )
846 HBITMAP32 hBitmap, hOldBitmap;
847 HDC32 hdcMem;
849 hBitmap = CreateDIBitmap32( hdc, &info->bmiHeader, CBM_INIT,
850 bits, info, wUsage );
851 hdcMem = CreateCompatibleDC32( hdc );
852 hOldBitmap = SelectObject32( hdcMem, hBitmap );
853 StretchBlt32( hdc, xDst, yDst, widthDst, heightDst,
854 hdcMem, xSrc, ySrc, widthSrc, heightSrc, dwRop );
855 SelectObject32( hdcMem, hOldBitmap );
856 DeleteDC32( hdcMem );
857 DeleteObject32( hBitmap );
858 return heightSrc;
862 /***********************************************************************
863 * SetDIBits16 (GDI.440)
865 INT16 WINAPI SetDIBits16( HDC16 hdc, HBITMAP16 hbitmap, UINT16 startscan,
866 UINT16 lines, LPCVOID bits, const BITMAPINFO *info,
867 UINT16 coloruse )
869 return SetDIBits32( hdc, hbitmap, startscan, lines, bits, info, coloruse );
873 /***********************************************************************
874 * SetDIBits32 (GDI32.312)
876 INT32 WINAPI SetDIBits32( HDC32 hdc, HBITMAP32 hbitmap, UINT32 startscan,
877 UINT32 lines, LPCVOID bits, const BITMAPINFO *info,
878 UINT32 coloruse )
880 DIB_SETIMAGEBITS_DESCR descr;
881 BITMAPOBJ * bmp;
882 int height, tmpheight;
883 INT32 result;
885 /* Check parameters */
887 descr.dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
888 if (!descr.dc)
890 descr.dc = (DC *)GDI_GetObjPtr(hdc, METAFILE_DC_MAGIC);
891 if (!descr.dc) return 0;
893 if (!(bmp = (BITMAPOBJ *)GDI_GetObjPtr( hbitmap, BITMAP_MAGIC )))
895 GDI_HEAP_UNLOCK( hdc );
896 return 0;
898 if (DIB_GetBitmapInfo( &info->bmiHeader, &descr.infoWidth, &height,
899 &descr.infoBpp ) == -1)
901 GDI_HEAP_UNLOCK( hbitmap );
902 GDI_HEAP_UNLOCK( hdc );
903 return 0;
905 tmpheight = height;
906 if (height < 0) height = -height;
907 if (!lines || (startscan >= height))
909 GDI_HEAP_UNLOCK( hbitmap );
910 GDI_HEAP_UNLOCK( hdc );
911 return 0;
913 if (startscan + lines > height) lines = height - startscan;
915 descr.bits = bits;
916 descr.lines = tmpheight >= 0 ? lines : -lines;
917 descr.depth = bmp->bitmap.bmBitsPixel;
918 descr.info = info;
919 descr.coloruse = coloruse;
920 descr.drawable = bmp->pixmap;
921 descr.gc = BITMAP_GC(bmp);
922 descr.xSrc = 0;
923 descr.ySrc = 0;
924 descr.xDest = 0;
925 descr.yDest = height - startscan - lines;
926 descr.width = bmp->bitmap.bmWidth;
927 descr.height = lines;
929 result = CALL_LARGE_STACK( DIB_SetImageBits, &descr );
930 GDI_HEAP_UNLOCK( hdc );
931 GDI_HEAP_UNLOCK( hbitmap );
932 return result;
936 /***********************************************************************
937 * SetDIBitsToDevice16 (GDI.443)
939 INT16 WINAPI SetDIBitsToDevice16(HDC16 hdc, INT16 xDest, INT16 yDest, INT16 cx,
940 INT16 cy, INT16 xSrc, INT16 ySrc, UINT16 startscan,
941 UINT16 lines, LPCVOID bits, const BITMAPINFO *info,
942 UINT16 coloruse )
944 return SetDIBitsToDevice32( hdc, xDest, yDest, cx, cy, xSrc, ySrc,
945 startscan, lines, bits, info, coloruse );
949 /***********************************************************************
950 * SetDIBitsToDevice32 (GDI32.313)
952 INT32 WINAPI SetDIBitsToDevice32(HDC32 hdc, INT32 xDest, INT32 yDest, DWORD cx,
953 DWORD cy, INT32 xSrc, INT32 ySrc, UINT32 startscan,
954 UINT32 lines, LPCVOID bits, const BITMAPINFO *info,
955 UINT32 coloruse )
957 DIB_SETIMAGEBITS_DESCR descr;
958 DC * dc;
959 DWORD width;
960 int height, tmpheight;
962 /* Check parameters */
964 dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
965 if (!dc)
967 dc = (DC *)GDI_GetObjPtr(hdc, METAFILE_DC_MAGIC);
968 if (!dc) return 0;
970 if (DIB_GetBitmapInfo( &info->bmiHeader, &width,
971 &height, &descr.infoBpp ) == -1)
972 return 0;
973 tmpheight = height;
974 if (height < 0) height = -height;
975 if (!lines || (startscan >= height)) return 0;
976 if (startscan + lines > height) lines = height - startscan;
977 if (ySrc < startscan) ySrc = startscan;
978 else if (ySrc >= startscan + lines) return 0;
979 if (xSrc >= width) return 0;
980 if (ySrc + cy >= startscan + lines) cy = startscan + lines - ySrc;
981 if (xSrc + cx >= width) cx = width - xSrc;
982 if (!cx || !cy) return 0;
984 DC_SetupGCForText( dc ); /* To have the correct colors */
985 XSetFunction( display, dc->u.x.gc, DC_XROPfunction[dc->w.ROPmode-1] );
987 descr.dc = dc;
988 descr.bits = bits;
989 descr.lines = tmpheight >= 0 ? lines : -lines;
990 descr.infoWidth = width;
991 descr.depth = dc->w.bitsPerPixel;
992 descr.info = info;
993 descr.coloruse = coloruse;
994 descr.drawable = dc->u.x.drawable;
995 descr.gc = dc->u.x.gc;
996 descr.xSrc = xSrc;
997 descr.ySrc = ySrc - startscan;
998 descr.xDest = dc->w.DCOrgX + XLPTODP( dc, xDest );
999 descr.yDest = dc->w.DCOrgY + YLPTODP( dc, yDest );
1000 descr.width = cx;
1001 descr.height = cy;
1003 return CALL_LARGE_STACK( DIB_SetImageBits, &descr );
1006 /***********************************************************************
1007 * SetDIBColorTable32 (GDI32.311)
1009 UINT32 WINAPI SetDIBColorTable32( HDC32 hdc, UINT32 startpos, UINT32 entries,
1010 RGBQUAD *colors )
1012 DC * dc;
1013 PALETTEENTRY * palEntry;
1014 PALETTEOBJ * palette;
1015 RGBQUAD *end;
1017 dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
1018 if (!dc)
1020 dc = (DC *)GDI_GetObjPtr(hdc, METAFILE_DC_MAGIC);
1021 if (!dc) return 0;
1024 if (!(palette = (PALETTEOBJ*)GDI_GetObjPtr( dc->w.hPalette, PALETTE_MAGIC )))
1026 return 0;
1029 /* Transfer color info */
1031 if (dc->w.bitsPerPixel <= 8) {
1032 palEntry = palette->logpalette.palPalEntry + startpos;
1033 if (startpos + entries > (1 << dc->w.bitsPerPixel)) {
1034 entries = (1 << dc->w.bitsPerPixel) - startpos;
1036 for (end = colors + entries; colors < end; palEntry++, colors++)
1038 palEntry->peRed = colors->rgbRed;
1039 palEntry->peGreen = colors->rgbGreen;
1040 palEntry->peBlue = colors->rgbBlue;
1042 } else {
1043 entries = 0;
1045 GDI_HEAP_UNLOCK( dc->w.hPalette );
1046 return entries;
1049 /***********************************************************************
1050 * GetDIBColorTable32 (GDI32.169)
1052 UINT32 WINAPI GetDIBColorTable32( HDC32 hdc, UINT32 startpos, UINT32 entries,
1053 RGBQUAD *colors )
1055 DC * dc;
1056 PALETTEENTRY * palEntry;
1057 PALETTEOBJ * palette;
1058 RGBQUAD *end;
1060 dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
1061 if (!dc)
1063 dc = (DC *)GDI_GetObjPtr(hdc, METAFILE_DC_MAGIC);
1064 if (!dc) return 0;
1067 if (!(palette = (PALETTEOBJ*)GDI_GetObjPtr( dc->w.hPalette, PALETTE_MAGIC )))
1069 return 0;
1072 /* Transfer color info */
1074 if (dc->w.bitsPerPixel <= 8) {
1075 palEntry = palette->logpalette.palPalEntry + startpos;
1076 if (startpos + entries > (1 << dc->w.bitsPerPixel)) {
1077 entries = (1 << dc->w.bitsPerPixel) - startpos;
1079 for (end = colors + entries; colors < end; palEntry++, colors++)
1081 colors->rgbRed = palEntry->peRed;
1082 colors->rgbGreen = palEntry->peGreen;
1083 colors->rgbBlue = palEntry->peBlue;
1084 colors->rgbReserved = 0;
1086 } else {
1087 entries = 0;
1089 GDI_HEAP_UNLOCK( dc->w.hPalette );
1090 return entries;
1093 /***********************************************************************
1094 * GetDIBits16 (GDI.441)
1096 INT16 WINAPI GetDIBits16( HDC16 hdc, HBITMAP16 hbitmap, UINT16 startscan,
1097 UINT16 lines, LPSTR bits, BITMAPINFO * info,
1098 UINT16 coloruse )
1100 return GetDIBits32( hdc, hbitmap, startscan, lines, bits, info, coloruse );
1104 /***********************************************************************
1105 * GetDIBits32 (GDI32.170)
1107 * http://www.microsoft.com/msdn/sdk/platforms/doc/sdk/win32/func/src/f30_14.htm
1109 INT32 WINAPI GetDIBits32( HDC32 hdc, HBITMAP32 hbitmap, UINT32 startscan,
1110 UINT32 lines, LPSTR bits, BITMAPINFO * info,
1111 UINT32 coloruse )
1113 DC * dc;
1114 BITMAPOBJ * bmp;
1115 PALETTEENTRY * palEntry;
1116 PALETTEOBJ * palette;
1117 XImage * bmpImage;
1118 int i, x, y;
1120 if (!lines) return 0;
1121 dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
1122 if (!dc)
1124 dc = (DC *)GDI_GetObjPtr(hdc, METAFILE_DC_MAGIC);
1125 if (!dc) return 0;
1127 if (!(bmp = (BITMAPOBJ *)GDI_GetObjPtr( hbitmap, BITMAP_MAGIC )))
1128 return 0;
1129 if (!(palette = (PALETTEOBJ*)GDI_GetObjPtr( dc->w.hPalette, PALETTE_MAGIC )))
1131 GDI_HEAP_UNLOCK( hbitmap );
1132 return 0;
1135 /* Transfer color info */
1137 if (info->bmiHeader.biBitCount<=8) {
1138 palEntry = palette->logpalette.palPalEntry;
1139 for (i = 0; i < info->bmiHeader.biClrUsed; i++, palEntry++)
1141 if (coloruse == DIB_RGB_COLORS)
1143 info->bmiColors[i].rgbRed = palEntry->peRed;
1144 info->bmiColors[i].rgbGreen = palEntry->peGreen;
1145 info->bmiColors[i].rgbBlue = palEntry->peBlue;
1146 info->bmiColors[i].rgbReserved = 0;
1148 else ((WORD *)info->bmiColors)[i] = (WORD)i;
1152 if (bits)
1154 BYTE* bbits = bits;
1155 int pad, yend, xend = bmp->bitmap.bmWidth;
1157 dprintf_bitmap(stddeb, "GetDIBits: %u scanlines of (%i,%i) -> (%i,%i) starting from %u\n",
1158 lines, bmp->bitmap.bmWidth, bmp->bitmap.bmHeight,
1159 (int)info->bmiHeader.biWidth, (int)info->bmiHeader.biHeight, startscan );
1161 /* adjust number of scanlines to copy */
1163 if( lines > info->bmiHeader.biHeight ) lines = info->bmiHeader.biHeight;
1164 yend = startscan + lines;
1165 if( startscan >= bmp->bitmap.bmHeight )
1167 GDI_HEAP_UNLOCK( hbitmap );
1168 GDI_HEAP_UNLOCK( dc->w.hPalette );
1169 return FALSE;
1171 if( yend > bmp->bitmap.bmHeight ) yend = bmp->bitmap.bmHeight;
1173 /* adjust scanline width */
1175 pad = info->bmiHeader.biWidth - bmp->bitmap.bmWidth;
1176 if( pad < 0 )
1178 /* bitmap is wider than DIB, copy only a part */
1180 pad = 0;
1181 xend = info->bmiHeader.biWidth;
1184 bmpImage = (XImage *)CALL_LARGE_STACK( BITMAP_GetXImage, bmp );
1186 switch( info->bmiHeader.biBitCount )
1188 case 8:
1189 /* pad up to 32 bit */
1190 pad += (4 - (info->bmiHeader.biWidth & 3)) & 3;
1191 for( y = yend - 1; (int)y >= (int)startscan; y-- )
1193 for( x = 0; x < xend; x++ )
1194 *bbits++ = XGetPixel( bmpImage, x, y );
1195 bbits += pad;
1197 break;
1198 case 1:
1199 pad += ((32 - (info->bmiHeader.biWidth & 31)) / 8) & 3;
1200 for( y = yend - 1; (int)y >= (int)startscan; y-- )
1202 *bbits = 0;
1203 for( x = 0; x < xend; x++ ) {
1205 *bbits |= XGetPixel( bmpImage, x, y)<<(7-(x&7));
1206 if ((x&7)==7) {
1207 bbits++;
1208 *bbits=0;
1211 bbits += pad;
1213 break;
1214 case 4:
1215 pad += ((8 - (info->bmiHeader.biWidth & 7)) / 2) & 3;
1216 for( y = yend - 1; (int)y >= (int)startscan; y-- )
1218 *bbits = 0;
1219 for( x = 0; x < xend; x++ ) {
1221 *bbits |= XGetPixel( bmpImage, x, y)<<(4*(1-(x&1)));
1222 if ((x&1)==1) {
1223 bbits++;
1224 *bbits=0;
1227 bbits += pad;
1229 break;
1230 case 15:
1231 case 16:
1232 pad += (4 - ((info->bmiHeader.biWidth*2) & 3)) & 3;
1233 for( y = yend - 1; (int)y >= (int)startscan; y-- )
1235 *bbits = 0;
1236 for( x = 0; x < xend; x++ ) {
1237 unsigned long pixel=XGetPixel( bmpImage, x, y);
1238 *bbits++ = pixel & 0xff;
1239 *bbits++ = (pixel >> 8) & 0xff;
1241 bbits += pad;
1243 break;
1244 case 24:
1245 pad += (4 - ((info->bmiHeader.biWidth*3) & 3)) & 3;
1246 for( y = yend - 1; (int)y >= (int)startscan; y-- )
1248 *bbits = 0;
1249 for( x = 0; x < xend; x++ ) {
1250 unsigned long pixel=XGetPixel( bmpImage, x, y);
1251 *bbits++ = (pixel >>16) & 0xff;
1252 *bbits++ = (pixel >> 8) & 0xff;
1253 *bbits++ = pixel & 0xff;
1255 bbits += pad;
1257 break;
1258 case 32:
1259 for( y = yend - 1; (int)y >= (int)startscan; y-- )
1261 *bbits = 0;
1262 for( x = 0; x < xend; x++ ) {
1263 unsigned long pixel=XGetPixel( bmpImage, x, y);
1264 *bbits++ = (pixel >>16) & 0xff;
1265 *bbits++ = (pixel >> 8) & 0xff;
1266 *bbits++ = pixel & 0xff;
1269 break;
1270 default:
1271 fprintf(stderr,"GetDIBits*: unsupported depth %d\n",
1272 info->bmiHeader.biBitCount
1274 break;
1277 XDestroyImage( bmpImage );
1279 info->bmiHeader.biCompression = 0;
1281 else if( info->bmiHeader.biSize >= sizeof(BITMAPINFOHEADER) )
1283 /* fill in struct members */
1285 info->bmiHeader.biWidth = bmp->bitmap.bmWidth;
1286 info->bmiHeader.biHeight = bmp->bitmap.bmHeight;
1287 info->bmiHeader.biPlanes = 1;
1288 info->bmiHeader.biBitCount = bmp->bitmap.bmBitsPixel;
1289 info->bmiHeader.biSizeImage = bmp->bitmap.bmHeight *
1290 DIB_GetDIBWidthBytes( bmp->bitmap.bmWidth,
1291 bmp->bitmap.bmBitsPixel );
1292 info->bmiHeader.biCompression = 0;
1295 GDI_HEAP_UNLOCK( hbitmap );
1296 GDI_HEAP_UNLOCK( dc->w.hPalette );
1297 return lines;
1301 /***********************************************************************
1302 * CreateDIBitmap16 (GDI.442)
1304 HBITMAP16 WINAPI CreateDIBitmap16( HDC16 hdc, const BITMAPINFOHEADER * header,
1305 DWORD init, LPCVOID bits, const BITMAPINFO * data,
1306 UINT16 coloruse )
1308 return CreateDIBitmap32( hdc, header, init, bits, data, coloruse );
1312 /***********************************************************************
1313 * CreateDIBitmap32 (GDI32.37)
1315 HBITMAP32 WINAPI CreateDIBitmap32( HDC32 hdc, const BITMAPINFOHEADER *header,
1316 DWORD init, LPCVOID bits, const BITMAPINFO *data,
1317 UINT32 coloruse )
1319 HBITMAP32 handle;
1320 BOOL32 fColor;
1321 DWORD width;
1322 int height;
1323 WORD bpp;
1325 if (DIB_GetBitmapInfo( header, &width, &height, &bpp ) == -1) return 0;
1326 if (height < 0) height = -height;
1328 /* Check if we should create a monochrome or color bitmap. */
1329 /* We create a monochrome bitmap only if it has exactly 2 */
1330 /* colors, which are either black or white, nothing else. */
1331 /* In all other cases, we create a color bitmap. */
1333 if (bpp != 1) fColor = TRUE;
1334 else if ((coloruse != DIB_RGB_COLORS) ||
1335 (init != CBM_INIT) || !data) fColor = FALSE;
1336 else
1338 if (data->bmiHeader.biSize == sizeof(BITMAPINFOHEADER))
1340 RGBQUAD *rgb = data->bmiColors;
1341 DWORD col = RGB( rgb->rgbRed, rgb->rgbGreen, rgb->rgbBlue );
1342 if ((col == RGB(0,0,0)) || (col == RGB(0xff,0xff,0xff)))
1344 rgb++;
1345 col = RGB( rgb->rgbRed, rgb->rgbGreen, rgb->rgbBlue );
1346 fColor = ((col != RGB(0,0,0)) && (col != RGB(0xff,0xff,0xff)));
1348 else fColor = TRUE;
1350 else if (data->bmiHeader.biSize == sizeof(BITMAPCOREHEADER))
1352 RGBTRIPLE *rgb = ((BITMAPCOREINFO *)data)->bmciColors;
1353 DWORD col = RGB( rgb->rgbtRed, rgb->rgbtGreen, rgb->rgbtBlue );
1354 if ((col == RGB(0,0,0)) || (col == RGB(0xff,0xff,0xff)))
1356 rgb++;
1357 col = RGB( rgb->rgbtRed, rgb->rgbtGreen, rgb->rgbtBlue );
1358 fColor = ((col != RGB(0,0,0)) && (col != RGB(0xff,0xff,0xff)));
1360 else fColor = TRUE;
1362 else
1364 fprintf( stderr, "CreateDIBitmap: wrong size (%ld) for data\n",
1365 data->bmiHeader.biSize );
1366 return 0;
1370 /* Now create the bitmap */
1372 handle = fColor ? CreateCompatibleBitmap32( hdc, width, height ) :
1373 CreateBitmap32( width, height, 1, 1, NULL );
1374 if (!handle) return 0;
1376 if (init == CBM_INIT)
1377 SetDIBits32( hdc, handle, 0, height, bits, data, coloruse );
1378 return handle;
1381 /***********************************************************************
1382 * CreateDIBSection16 (GDI.489)
1384 HBITMAP16 WINAPI CreateDIBSection16 (HDC16 hdc, BITMAPINFO *bmi, UINT16 usage,
1385 LPVOID **bits, HANDLE16 section,
1386 DWORD offset)
1388 return CreateDIBSection32 (hdc, bmi, usage, bits, section, offset);
1391 /***********************************************************************
1392 * CreateDIBSection32 (GDI32.36)
1394 HBITMAP32 WINAPI CreateDIBSection32 (HDC32 hdc, BITMAPINFO *bmi, UINT32 usage,
1395 LPVOID **bits,HANDLE32 section,
1396 DWORD offset)
1398 HBITMAP32 res = 0;
1400 fprintf(stderr,
1401 "CreateDIBSection(%d,[w=%ld,h=%ld],%d,%p,0x%08x,%ld),semistub\n",
1402 hdc,bmi->bmiHeader.biWidth,bmi->bmiHeader.biHeight,
1403 usage,bits,section,offset
1405 /* FIXME. The following line isn't quite right. */
1406 res = CreateDIBitmap32 (hdc, &bmi->bmiHeader, 0, NULL, bmi, 0);
1407 if (res)
1409 BITMAP32 bmp;
1410 if (GetObject32A (res, sizeof (bmp), &bmp))
1412 *bits = bmp.bmBits;
1413 return res;
1417 /* Error. */
1418 if (res) DeleteObject32 (res);
1419 *bits = NULL;
1420 return 0;