Commit a32ddc0f authored by Ove Kaaven's avatar Ove Kaaven Committed by Alexandre Julliard

Implemented Get/SetDIBColorTable.

parent 235f1295
......@@ -205,6 +205,24 @@ void TTYDRV_BITMAP_DeleteDIBSection(BITMAPOBJ *bmp)
}
/***********************************************************************
* TTYDRV_BITMAP_SetDIBColorTable
*/
UINT TTYDRV_BITMAP_SetDIBColorTable(BITMAPOBJ *bmp, DC *dc, UINT start, UINT count, const RGBQUAD *colors)
{
FIXME("(%p): stub\n", bmp);
return 0;
}
/***********************************************************************
* TTYDRV_BITMAP_GetDIBColorTable
*/
UINT TTYDRV_BITMAP_GetDIBColorTable(BITMAPOBJ *bmp, DC *dc, UINT start, UINT count, RGBQUAD *colors)
{
FIXME("(%p): stub\n", bmp);
return 0;
}
/***********************************************************************
* TTYDRV_BITMAP_GetDIBits
*/
INT TTYDRV_BITMAP_GetDIBits(
......
......@@ -122,7 +122,9 @@ BITMAP_DRIVER TTYDRV_BITMAP_Driver =
{
TTYDRV_BITMAP_SetDIBits,
TTYDRV_BITMAP_GetDIBits,
TTYDRV_BITMAP_DeleteDIBSection
TTYDRV_BITMAP_DeleteDIBSection,
TTYDRV_BITMAP_SetDIBColorTable,
TTYDRV_BITMAP_GetDIBColorTable
};
PALETTE_DRIVER TTYDRV_PALETTE_Driver =
......
......@@ -51,6 +51,8 @@ extern HBITMAP16 TTYDRV_BITMAP_CreateDIBSection16(struct tagDC *dc, BITMAPINFO *
extern INT TTYDRV_BITMAP_SetDIBits(struct tagBITMAPOBJ *bmp, struct tagDC *dc, UINT startscan, UINT lines, LPCVOID bits, const BITMAPINFO *info, UINT coloruse, HBITMAP hbitmap);
extern INT TTYDRV_BITMAP_GetDIBits(struct tagBITMAPOBJ *bmp, struct tagDC *dc, UINT startscan, UINT lines, LPVOID bits, BITMAPINFO *info, UINT coloruse, HBITMAP hbitmap);
extern void TTYDRV_BITMAP_DeleteDIBSection(struct tagBITMAPOBJ *bmp);
extern UINT TTYDRV_BITMAP_SetDIBColorTable(struct tagBITMAPOBJ *,struct tagDC *,UINT,UINT,const RGBQUAD *);
extern UINT TTYDRV_BITMAP_GetDIBColorTable(struct tagBITMAPOBJ *,struct tagDC *,UINT,UINT,RGBQUAD *);
#ifndef WINE_CURSES
typedef struct { int dummy; } WINDOW;
......
......@@ -78,53 +78,29 @@ int X11DRV_DIB_GetXImageWidthBytes( int width, int depth )
}
/***********************************************************************
* X11DRV_DIB_BuildColorMap
* X11DRV_DIB_GenColorMap
*
* Build the color map from the bitmap palette. Should not be called
* Fills the color map of a bitmap palette. Should not be called
* for a >8-bit deep bitmap.
*/
int *X11DRV_DIB_BuildColorMap( DC *dc, WORD coloruse, WORD depth,
const BITMAPINFO *info, int *nColors )
int *X11DRV_DIB_GenColorMap( DC *dc, int *colorMapping,
WORD coloruse, WORD depth, BOOL quads,
const void *colorPtr, int start, int end )
{
int i, colors;
BOOL isInfo;
WORD *colorPtr;
int *colorMapping;
if ((isInfo = (info->bmiHeader.biSize == sizeof(BITMAPINFOHEADER))))
{
colors = info->bmiHeader.biClrUsed;
if (!colors) colors = 1 << info->bmiHeader.biBitCount;
colorPtr = (WORD *)info->bmiColors;
}
else /* assume BITMAPCOREINFO */
{
colors = 1 << ((BITMAPCOREHEADER *)&info->bmiHeader)->bcBitCount;
colorPtr = (WORD *)((BITMAPCOREINFO *)info)->bmciColors;
}
if (colors > 256)
{
ERR("called with >256 colors!\n");
return NULL;
}
if (!(colorMapping = (int *)HeapAlloc(GetProcessHeap(), 0,
colors * sizeof(int) )))
return NULL;
int i;
if (coloruse == DIB_RGB_COLORS)
{
if (isInfo)
if (quads)
{
RGBQUAD * rgb = (RGBQUAD *)colorPtr;
if (depth == 1) /* Monochrome */
for (i = 0; i < colors; i++, rgb++)
for (i = start; i < end; i++, rgb++)
colorMapping[i] = (rgb->rgbRed + rgb->rgbGreen +
rgb->rgbBlue > 255*3/2);
else
for (i = 0; i < colors; i++, rgb++)
for (i = start; i < end; i++, rgb++)
colorMapping[i] = X11DRV_PALETTE_ToPhysical( dc, RGB(rgb->rgbRed,
rgb->rgbGreen,
rgb->rgbBlue));
......@@ -134,11 +110,11 @@ int *X11DRV_DIB_BuildColorMap( DC *dc, WORD coloruse, WORD depth,
RGBTRIPLE * rgb = (RGBTRIPLE *)colorPtr;
if (depth == 1) /* Monochrome */
for (i = 0; i < colors; i++, rgb++)
for (i = start; i < end; i++, rgb++)
colorMapping[i] = (rgb->rgbtRed + rgb->rgbtGreen +
rgb->rgbtBlue > 255*3/2);
else
for (i = 0; i < colors; i++, rgb++)
for (i = start; i < end; i++, rgb++)
colorMapping[i] = X11DRV_PALETTE_ToPhysical( dc, RGB(rgb->rgbtRed,
rgb->rgbtGreen,
rgb->rgbtBlue));
......@@ -146,14 +122,56 @@ int *X11DRV_DIB_BuildColorMap( DC *dc, WORD coloruse, WORD depth,
}
else /* DIB_PAL_COLORS */
{
for (i = 0; i < colors; i++, colorPtr++)
colorMapping[i] = X11DRV_PALETTE_ToPhysical( dc, PALETTEINDEX(*colorPtr) );
WORD * index = (WORD *)colorPtr;
for (i = start; i < end; i++, index++)
colorMapping[i] = X11DRV_PALETTE_ToPhysical( dc, PALETTEINDEX(*index) );
}
*nColors = colors;
return colorMapping;
}
/***********************************************************************
* X11DRV_DIB_BuildColorMap
*
* Build the color map from the bitmap palette. Should not be called
* for a >8-bit deep bitmap.
*/
int *X11DRV_DIB_BuildColorMap( DC *dc, WORD coloruse, WORD depth,
const BITMAPINFO *info, int *nColors )
{
int colors;
BOOL isInfo;
WORD *colorPtr;
int *colorMapping;
if ((isInfo = (info->bmiHeader.biSize == sizeof(BITMAPINFOHEADER))))
{
colors = info->bmiHeader.biClrUsed;
if (!colors) colors = 1 << info->bmiHeader.biBitCount;
colorPtr = (WORD *)info->bmiColors;
}
else /* assume BITMAPCOREINFO */
{
colors = 1 << ((BITMAPCOREHEADER *)&info->bmiHeader)->bcBitCount;
colorPtr = (WORD *)((BITMAPCOREINFO *)info)->bmciColors;
}
if (colors > 256)
{
ERR("called with >256 colors!\n");
return NULL;
}
if (!(colorMapping = (int *)HeapAlloc(GetProcessHeap(), 0,
colors * sizeof(int) )))
return NULL;
*nColors = colors;
return X11DRV_DIB_GenColorMap( dc, colorMapping, coloruse, depth,
isInfo, colorPtr, 0, colors);
}
/***********************************************************************
* X11DRV_DIB_MapColor
......@@ -3603,6 +3621,42 @@ void X11DRV_DIB_DeleteDIBSection(BITMAPOBJ *bmp)
if (dib->selector) SELECTOR_FreeBlock( dib->selector );
}
/***********************************************************************
* X11DRV_DIB_SetDIBColorTable
*/
UINT X11DRV_DIB_SetDIBColorTable(BITMAPOBJ *bmp, DC *dc, UINT start, UINT count, const RGBQUAD *colors)
{
X11DRV_DIBSECTION *dib = (X11DRV_DIBSECTION *) bmp->dib;
if (dib && dib->colorMap) {
X11DRV_DIB_GenColorMap( dc, dib->colorMap, DIB_RGB_COLORS, dib->dibSection.dsBm.bmBitsPixel,
TRUE, colors, start, count - start );
return count;
}
return 0;
}
/***********************************************************************
* X11DRV_DIB_GetDIBColorTable
*/
UINT X11DRV_DIB_GetDIBColorTable(BITMAPOBJ *bmp, DC *dc, UINT start, UINT count, RGBQUAD *colors)
{
X11DRV_DIBSECTION *dib = (X11DRV_DIBSECTION *) bmp->dib;
if (dib && dib->colorMap) {
int i, end = count - start;
for (i = start; i < end; i++,colors++) {
COLORREF col = X11DRV_PALETTE_ToLogical( dib->colorMap[i] );
colors->rgbBlue = GetBValue(col);
colors->rgbGreen = GetGValue(col);
colors->rgbRed = GetRValue(col);
colors->rgbReserved = 0;
}
return count;
}
return 0;
}
/**************************************************************************
* X11DRV_DIB_CreateDIBFromPixmap
......
......@@ -131,7 +131,9 @@ BITMAP_DRIVER X11DRV_BITMAP_Driver =
{
X11DRV_DIB_SetDIBits,
X11DRV_DIB_GetDIBits,
X11DRV_DIB_DeleteDIBSection
X11DRV_DIB_DeleteDIBSection,
X11DRV_DIB_SetDIBColorTable,
X11DRV_DIB_GetDIBColorTable
};
PALETTE_DRIVER X11DRV_PALETTE_Driver =
......
......@@ -35,6 +35,8 @@ typedef struct tagBITMAP_DRIVER
INT (*pSetDIBits)(struct tagBITMAPOBJ *,struct tagDC *,UINT,UINT,LPCVOID,const BITMAPINFO *,UINT,HBITMAP);
INT (*pGetDIBits)(struct tagBITMAPOBJ *,struct tagDC *,UINT,UINT,LPVOID,BITMAPINFO *,UINT,HBITMAP);
VOID (*pDeleteDIBSection)(struct tagBITMAPOBJ *);
UINT (*pSetDIBColorTable)(struct tagBITMAPOBJ *,struct tagDC *,UINT,UINT,const RGBQUAD *);
UINT (*pGetDIBColorTable)(struct tagBITMAPOBJ *,struct tagDC *,UINT,UINT,RGBQUAD *);
} BITMAP_DRIVER;
extern BITMAP_DRIVER *BITMAP_Driver;
......
......@@ -280,6 +280,8 @@ extern INT X11DRV_DIB_GetDIBits(struct tagBITMAPOBJ *bmp, struct tagDC *dc, UINT
UINT lines, LPVOID bits, BITMAPINFO *info,
UINT coloruse, HBITMAP hbitmap);
extern void X11DRV_DIB_DeleteDIBSection(struct tagBITMAPOBJ *bmp);
extern UINT X11DRV_DIB_SetDIBColorTable(struct tagBITMAPOBJ *,struct tagDC*,UINT,UINT,const RGBQUAD *);
extern UINT X11DRV_DIB_GetDIBColorTable(struct tagBITMAPOBJ *,struct tagDC*,UINT,UINT,RGBQUAD *);
/**************************************************************************
* X11 GDI driver
......
......@@ -306,40 +306,22 @@ UINT WINAPI SetDIBColorTable( HDC hdc, UINT startpos, UINT entries,
RGBQUAD *colors )
{
DC * dc;
PALETTEENTRY * palEntry;
PALETTEOBJ * palette;
RGBQUAD *end;
BITMAPOBJ * bmp;
UINT result;
if (!(dc = DC_GetDCUpdate( hdc ))) return 0;
if (!(palette = (PALETTEOBJ*)GDI_GetObjPtr( dc->hPalette, PALETTE_MAGIC )))
if (!(bmp = (BITMAPOBJ*)GDI_GetObjPtr( dc->hBitmap, BITMAP_MAGIC )))
{
GDI_ReleaseObj( hdc );
return 0;
}
/* Transfer color info */
if (dc->bitsPerPixel <= 8) {
palEntry = palette->logpalette.palPalEntry + startpos;
if (startpos + entries > (1 << dc->bitsPerPixel))
entries = (1 << dc->bitsPerPixel) - startpos;
if (startpos + entries > palette->logpalette.palNumEntries)
entries = palette->logpalette.palNumEntries - startpos;
result = BITMAP_Driver->pSetDIBColorTable(bmp, dc, startpos, entries, colors);
for (end = colors + entries; colors < end; palEntry++, colors++)
{
palEntry->peRed = colors->rgbRed;
palEntry->peGreen = colors->rgbGreen;
palEntry->peBlue = colors->rgbBlue;
}
} else {
entries = 0;
}
GDI_ReleaseObj( dc->hPalette );
GDI_ReleaseObj( dc->hBitmap );
GDI_ReleaseObj( hdc );
return entries;
return result;
}
/***********************************************************************
......@@ -358,38 +340,22 @@ UINT WINAPI GetDIBColorTable( HDC hdc, UINT startpos, UINT entries,
RGBQUAD *colors )
{
DC * dc;
PALETTEENTRY * palEntry;
PALETTEOBJ * palette;
RGBQUAD *end;
BITMAPOBJ * bmp;
UINT result;
if (!(dc = DC_GetDCUpdate( hdc ))) return 0;
if (!(palette = (PALETTEOBJ*)GDI_GetObjPtr( dc->hPalette, PALETTE_MAGIC )))
if (!(bmp = (BITMAPOBJ*)GDI_GetObjPtr( dc->hBitmap, BITMAP_MAGIC )))
{
GDI_ReleaseObj( hdc );
return 0;
}
/* Transfer color info */
if (dc->bitsPerPixel <= 8) {
palEntry = palette->logpalette.palPalEntry + startpos;
if (startpos + entries > (1 << dc->bitsPerPixel)) {
entries = (1 << dc->bitsPerPixel) - startpos;
}
for (end = colors + entries; colors < end; palEntry++, colors++)
{
colors->rgbRed = palEntry->peRed;
colors->rgbGreen = palEntry->peGreen;
colors->rgbBlue = palEntry->peBlue;
colors->rgbReserved = 0;
}
} else {
entries = 0;
}
GDI_ReleaseObj( dc->hPalette );
result = BITMAP_Driver->pGetDIBColorTable(bmp, dc, startpos, entries, colors);
GDI_ReleaseObj( dc->hBitmap );
GDI_ReleaseObj( hdc );
return entries;
return result;
}
/* FIXME the following two structs should be combined with __sysPalTemplate in
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment