DIB Engine: fixes clipping, text and more
[wine/hacks.git] / dlls / winedib.drv / dib.c
blob653148d8c16efa7fe2711d993a4cad8db19a308a
1 /*
2 * DIBDRV device-independent bitmaps
4 * Copyright 2009 Massimo Del Fedele
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include "config.h"
22 #include "wine/port.h"
24 #include "dibdrv.h"
26 WINE_DEFAULT_DEBUG_CHANNEL(dibdrv);
28 /***********************************************************************
29 * DIBDRV_CreateDIBSection
31 HBITMAP DIBDRV_CreateDIBSection( DIBDRVPHYSDEV *physDev, HBITMAP hbitmap,
32 const BITMAPINFO *bmi, UINT usage )
34 HBITMAP res;
36 MAYBE(TRACE("physDev:%p, hbitmap:%p, bmi:%p, usage:%d\n", physDev, hbitmap, bmi, usage));
38 /* createDIBSection is only DIB-related, so we just use the engine */
39 ONCE(FIXME("STUB\n"));
40 res = hbitmap;
42 return res;
45 /***********************************************************************
46 * DIBDRV_GetDIBits
48 INT DIBDRV_GetDIBits( DIBDRVPHYSDEV *physDev, HBITMAP hbitmap, UINT startscan,
49 UINT lines, LPCVOID bits, const BITMAPINFO *bmi, UINT coloruse )
51 INT res;
53 MAYBE(TRACE("physDev:%p, hbitmap:%p, startscan:%d, lines:%d, bits:%p, bmi:%p, coloruse:%d\n",
54 physDev, hbitmap, startscan, lines, bits, bmi, coloruse));
56 /* GetDIBits reads bits from a DDB, so we should use the X11 driver */
57 res = _DIBDRV_GetDisplayDriver()->pGetDIBits(physDev->X11PhysDev, hbitmap, startscan, lines, bits, bmi, coloruse);
59 return res;
62 /***********************************************************************
63 * DIBDRV_SetDIBColorTable
65 UINT DIBDRV_SetDIBColorTable( DIBDRVPHYSDEV *physDev, UINT start, UINT count,
66 const RGBQUAD *colors )
68 DIBDRVBITMAP *dib = &physDev->physBitmap;
70 MAYBE(TRACE("physDev:%p, start:%d, count:%d, colors:%p\n", physDev, start, count, colors));
72 /* SetDIBColorTable operates on a DIB, so we use the engine */
74 /* if bpp > 8, some error occurred... */
75 if(dib->bitCount > 8)
77 ERR("Called for BPP > 8\n");
78 return 0;
81 /* if dib hasn't a color table, or has a small one, we must before
82 create/extend it */
83 if(!(dib->colorTable))
85 dib->colorTableSize = (1 << dib->bitCount);
86 dib->colorTable = HeapAlloc(GetProcessHeap(), 0, sizeof(RGBQUAD) * dib->colorTableSize);
88 else if(dib->colorTableSize < (1 << dib->bitCount))
90 int newSize = (1 << dib->bitCount);
91 RGBQUAD *newTable = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(RGBQUAD) * newSize);
92 memcpy(newTable, dib->colorTable, sizeof(RGBQUAD) * dib->colorTableSize);
93 HeapFree(GetProcessHeap(), 0, dib->colorTable);
94 dib->colorTable = newTable;
95 dib->colorTableSize = newSize;
98 /* sanity check */
99 if(start + count > dib->colorTableSize)
101 ERR("Out of range setting color table, size is %d, requested is %d\n", dib->colorTableSize, start+count);
102 return 0;
104 memcpy(dib->colorTable + start, colors, sizeof(RGBQUAD) * count);
105 dib->colorTableGrabbed = TRUE;
107 return TRUE;
110 /***********************************************************************
111 * DIBDRV_SetDIBits
113 INT DIBDRV_SetDIBits( DIBDRVPHYSDEV *physDev, HBITMAP hbitmap, UINT startscan,
114 UINT lines, LPCVOID bits, const BITMAPINFO *info, UINT coloruse )
116 INT res;
118 MAYBE(TRACE("physDev:%p, hbitmap:%p, startscan:%d, lines:%d, bits:%p, bmi:%p, coloruse:%d\n",
119 physDev, hbitmap, startscan, lines, bits, info, coloruse));
121 /* SetDIBits writes bits to a DDB, so we should use the X11 driver */
122 res = _DIBDRV_GetDisplayDriver()->pSetDIBits(physDev->X11PhysDev, hbitmap, startscan, lines, bits, info, coloruse);
124 return res;
127 /*************************************************************************
128 * DIBDRV_SetDIBitsToDevice
130 INT DIBDRV_SetDIBitsToDevice( DIBDRVPHYSDEV *physDev, INT xDest, INT yDest, DWORD cx,
131 DWORD cy, INT xSrc, INT ySrc,
132 UINT startscan, UINT lines, LPCVOID bits,
133 const BITMAPINFO *info, UINT coloruse )
135 INT res;
137 MAYBE(TRACE("physDev:%p, xDest:%d, yDest:%d, cx:%x, cy:%x, xSrc:%d, ySrc:%d, startscan:%d, lines:%d, bits:%p, info:%p, coloruse:%d\n",
138 physDev, xDest, yDest, cx, cy, xSrc, ySrc, startscan, lines, bits, info, coloruse));
140 /* SetDIBitsToDevice operates on a physical device, so we should use the X11 driver */
141 res = _DIBDRV_GetDisplayDriver()->pSetDIBitsToDevice(physDev->X11PhysDev, xDest, yDest, cx, cy, xSrc, ySrc,
142 startscan, lines, bits, info, coloruse);
144 return res;