dibdrv: Basic GetDIBits
[wine/dibdrv.git] / dlls / winedib.drv / dib.c
blobeb8a5ff3d28d2933c12b9a6b91ade479818a5e87
1 /*
2 * DIBDRV device-independent bitmaps
4 * Copyright 2007 Jesse Allen
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"
23 #include <stdarg.h>
24 #include "windef.h"
25 #include "winbase.h"
26 #include "wine/debug.h"
28 #include "dibdrv.h"
30 WINE_DEFAULT_DEBUG_CHANNEL(dibdrv);
32 /***********************************************************************
33 * DIBDRV_CreateDIBSection
35 HBITMAP DIBDRV_CreateDIBSection( DIBDRVPHYSDEV *physDev, HBITMAP hbitmap,
36 const BITMAPINFO *bmi, UINT usage )
38 FIXME("stub\n");
39 return hbitmap;
42 /***********************************************************************
43 * DIBDRV_GetDIBits
45 INT DIBDRV_GetDIBits( DIBDRVPHYSDEV *physDev, HBITMAP hbitmap, UINT startscan,
46 UINT lines, LPCVOID bits, const BITMAPINFO *info, UINT coloruse )
48 const DIBFUNCS *dst_funcs, *src_funcs;
49 const DIBCONVERT *convs;
50 DIBDRVBITMAP *dst, *src;
51 int i, min_width;
53 TRACE("%p %p %u %u %p %p %u\n", physDev, hbitmap, startscan, lines, bits, info, coloruse);
55 dst = BITMAP_CreateFromBmi( info, (void *)bits );
56 if (!dst) return 0;
58 src = BITMAP_CreateFromHBitmap( hbitmap, physDev->bmp->color_table, physDev->bmp->nb_colors );
59 if (!src)
61 HeapFree( GetProcessHeap(), 0, dst );
62 return 0;
65 convs = BITMAP_GetDIBConversions( src->format );
66 dst_funcs = BITMAP_GetDIBFuncs( dst->format );
67 src_funcs = BITMAP_GetDIBFuncs( src->format );
68 min_width = src->width < dst->width ? src->width : dst->width;
70 /* copy a scanline at a time */
71 for (i = startscan; i < startscan + lines; i++)
73 dst_funcs->MoveXY( dst, 0, i );
74 src_funcs->MoveXY( src, 0, i );
75 dst_funcs->Copy( dst, src, min_width, convs );
78 HeapFree( GetProcessHeap(), 0, dst );
79 HeapFree( GetProcessHeap(), 0, src );
80 return i - startscan;
83 /***********************************************************************
84 * DIBDRV_SetDIBColorTable
86 UINT DIBDRV_SetDIBColorTable( DIBDRVPHYSDEV *physDev, UINT start, UINT count,
87 const RGBQUAD *colors )
89 TRACE("%p %u %u %p\n", physDev, start, count, colors);
90 if (!physDev->bmp->color_table || start + count > physDev->bmp->nb_colors)
91 return 0; /* maybe */
92 memcpy(physDev->bmp->color_table + start*sizeof(RGBQUAD), colors, count*sizeof(RGBQUAD));
93 return count;
96 /***********************************************************************
97 * DIBDRV_SetDIBits
99 INT DIBDRV_SetDIBits( DIBDRVPHYSDEV *physDev, HBITMAP hbitmap, UINT startscan,
100 UINT lines, LPCVOID bits, const BITMAPINFO *info, UINT coloruse )
102 const DIBFUNCS *dst_funcs, *src_funcs;
103 const DIBCONVERT *convs;
104 DIBDRVBITMAP *dst, *src;
105 int i, min_width;
107 TRACE("%p %p %u %u %p %p %u\n", physDev, hbitmap, startscan, lines, bits, info, coloruse);
109 dst = BITMAP_CreateFromHBitmap( hbitmap, physDev->bmp->color_table, physDev->bmp->nb_colors );
110 if (!dst) return 0;
112 src = BITMAP_CreateFromBmi( info, (void *)bits );
113 if (!src)
115 HeapFree( GetProcessHeap(), 0, dst );
116 return 0;
119 convs = BITMAP_GetDIBConversions( src->format );
120 dst_funcs = BITMAP_GetDIBFuncs( dst->format );
121 src_funcs = BITMAP_GetDIBFuncs( src->format );
122 min_width = dst->width < src->width ? dst->width : src->width;
124 /* copy a scanline at a time */
125 for (i = startscan; i < startscan + lines; i++)
127 dst_funcs->MoveXY( dst, 0, i );
128 src_funcs->MoveXY( src, 0, i );
129 dst_funcs->Copy( dst, src, min_width, convs );
132 HeapFree( GetProcessHeap(), 0, dst );
133 HeapFree( GetProcessHeap(), 0, src );
134 return i - startscan;
137 /*************************************************************************
138 * DIBDRV_SetDIBitsToDevice
140 INT DIBDRV_SetDIBitsToDevice( DIBDRVPHYSDEV *physDev, INT xDest, INT yDest, DWORD cx,
141 DWORD cy, INT xSrc, INT ySrc,
142 UINT startscan, UINT lines, LPCVOID bits,
143 const BITMAPINFO *info, UINT coloruse )
145 FIXME("stub\n");
146 return 0;