blind fix for wxMotif compilation with wxHAVE_LIB_XPM == 0

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@20342 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2003-04-25 11:10:45 +00:00
parent c5a2f27478
commit 0cad49b42c

View File

@@ -1134,11 +1134,11 @@ bool wxGetImageFromDrawable(GR_DRAW_ID drawable, int srcX, int srcY, int width,
GrGetScreenInfo(&sinfo); GrGetScreenInfo(&sinfo);
if (sinfo.pixtype == MWPF_PALETTE) { if (sinfo.pixtype == MWPF_PALETTE) {
if(!(palette = (GR_PALETTE*) malloc(sizeof(GR_PALETTE)))) { if(!(palette = (GR_PALETTE*) malloc(sizeof(GR_PALETTE)))) {
return FALSE; return FALSE;
} }
GrGetSystemPalette(palette); GrGetSystemPalette(palette);
} }
if(!(pixels = (GR_PIXELVAL*) malloc(sizeof(GR_PIXELVAL) * width * height))) if(!(pixels = (GR_PIXELVAL*) malloc(sizeof(GR_PIXELVAL) * width * height)))
{ {
@@ -1147,55 +1147,55 @@ bool wxGetImageFromDrawable(GR_DRAW_ID drawable, int srcX, int srcY, int width,
image.Create(width, height); image.Create(width, height);
GrReadArea(drawable, srcX, srcY, width, height, GrReadArea(drawable, srcX, srcY, width, height,
pixels); pixels);
for(x = 0; x < sinfo.cols; x++) { for(x = 0; x < sinfo.cols; x++) {
pp = (unsigned char *)pixels + pp = (unsigned char *)pixels +
((x + (y * sinfo.cols)) * ((x + (y * sinfo.cols)) *
sizeof(GR_PIXELVAL)); sizeof(GR_PIXELVAL));
switch(sinfo.pixtype) { switch(sinfo.pixtype) {
/* FIXME: These may need modifying on big endian. */ /* FIXME: These may need modifying on big endian. */
case MWPF_TRUECOLOR0888: case MWPF_TRUECOLOR0888:
case MWPF_TRUECOLOR888: case MWPF_TRUECOLOR888:
rgb[0] = pp[2]; rgb[0] = pp[2];
rgb[1] = pp[1]; rgb[1] = pp[1];
rgb[2] = pp[0]; rgb[2] = pp[0];
break; break;
case MWPF_PALETTE: case MWPF_PALETTE:
rgb[0] = palette->palette[pp[0]].r; rgb[0] = palette->palette[pp[0]].r;
rgb[1] = palette->palette[pp[0]].g; rgb[1] = palette->palette[pp[0]].g;
rgb[2] = palette->palette[pp[0]].b; rgb[2] = palette->palette[pp[0]].b;
break; break;
case MWPF_TRUECOLOR565: case MWPF_TRUECOLOR565:
rgb[0] = pp[1] & 0xf8; rgb[0] = pp[1] & 0xf8;
rgb[1] = ((pp[1] & 0x07) << 5) | rgb[1] = ((pp[1] & 0x07) << 5) |
((pp[0] & 0xe0) >> 3); ((pp[0] & 0xe0) >> 3);
rgb[2] = (pp[0] & 0x1f) << 3; rgb[2] = (pp[0] & 0x1f) << 3;
break; break;
case MWPF_TRUECOLOR555: case MWPF_TRUECOLOR555:
rgb[0] = (pp[1] & 0x7c) << 1; rgb[0] = (pp[1] & 0x7c) << 1;
rgb[1] = ((pp[1] & 0x03) << 6) | rgb[1] = ((pp[1] & 0x03) << 6) |
((pp[0] & 0xe0) >> 2); ((pp[0] & 0xe0) >> 2);
rgb[2] = (pp[0] & 0x1f) << 3; rgb[2] = (pp[0] & 0x1f) << 3;
break; break;
case MWPF_TRUECOLOR332: case MWPF_TRUECOLOR332:
rgb[0] = pp[0] & 0xe0; rgb[0] = pp[0] & 0xe0;
rgb[1] = (pp[0] & 0x1c) << 3; rgb[1] = (pp[0] & 0x1c) << 3;
rgb[2] = (pp[0] & 0x03) << 6; rgb[2] = (pp[0] & 0x03) << 6;
break; break;
default: default:
fprintf(stderr, "Unsupported pixel " fprintf(stderr, "Unsupported pixel "
"format\n"); "format\n");
return 1; return 1;
} }
image.SetRGB(x, y, rgb[0], rgb[1], rgb[2]); image.SetRGB(x, y, rgb[0], rgb[1], rgb[2]);
} }
free(pixels); free(pixels);
if(palette) free(palette); if(palette) free(palette);
@@ -1207,45 +1207,45 @@ bool wxGetImageFromDrawable(GR_DRAW_ID drawable, int srcX, int srcY, int width,
int GrGetPixelColor(GR_SCREEN_INFO* sinfo, GR_PALETTE* palette, GR_PIXELVAL pixel, int GrGetPixelColor(GR_SCREEN_INFO* sinfo, GR_PALETTE* palette, GR_PIXELVAL pixel,
unsigned char* red, unsigned char* green, unsigned char* blue) unsigned char* red, unsigned char* green, unsigned char* blue)
{ {
unsigned char rgb[3], *pp; unsigned char rgb[3], *pp;
pp = (unsigned char*) & pixel ; pp = (unsigned char*) & pixel ;
switch (sinfo.pixtype) switch (sinfo.pixtype)
{ {
/* FIXME: These may need modifying on big endian. */ /* FIXME: These may need modifying on big endian. */
case MWPF_TRUECOLOR0888: case MWPF_TRUECOLOR0888:
case MWPF_TRUECOLOR888: case MWPF_TRUECOLOR888:
rgb[0] = pp[2]; rgb[0] = pp[2];
rgb[1] = pp[1]; rgb[1] = pp[1];
rgb[2] = pp[0]; rgb[2] = pp[0];
break; break;
case MWPF_PALETTE: case MWPF_PALETTE:
rgb[0] = palette->palette[pp[0]].r; rgb[0] = palette->palette[pp[0]].r;
rgb[1] = palette->palette[pp[0]].g; rgb[1] = palette->palette[pp[0]].g;
rgb[2] = palette->palette[pp[0]].b; rgb[2] = palette->palette[pp[0]].b;
break; break;
case MWPF_TRUECOLOR565: case MWPF_TRUECOLOR565:
rgb[0] = pp[1] & 0xf8; rgb[0] = pp[1] & 0xf8;
rgb[1] = ((pp[1] & 0x07) << 5) | rgb[1] = ((pp[1] & 0x07) << 5) |
((pp[0] & 0xe0) >> 3); ((pp[0] & 0xe0) >> 3);
rgb[2] = (pp[0] & 0x1f) << 3; rgb[2] = (pp[0] & 0x1f) << 3;
break; break;
case MWPF_TRUECOLOR555: case MWPF_TRUECOLOR555:
rgb[0] = (pp[1] & 0x7c) << 1; rgb[0] = (pp[1] & 0x7c) << 1;
rgb[1] = ((pp[1] & 0x03) << 6) | rgb[1] = ((pp[1] & 0x03) << 6) |
((pp[0] & 0xe0) >> 2); ((pp[0] & 0xe0) >> 2);
rgb[2] = (pp[0] & 0x1f) << 3; rgb[2] = (pp[0] & 0x1f) << 3;
break; break;
case MWPF_TRUECOLOR332: case MWPF_TRUECOLOR332:
rgb[0] = pp[0] & 0xe0; rgb[0] = pp[0] & 0xe0;
rgb[1] = (pp[0] & 0x1c) << 3; rgb[1] = (pp[0] & 0x1c) << 3;
rgb[2] = (pp[0] & 0x03) << 6; rgb[2] = (pp[0] & 0x03) << 6;
break; break;
default: default:
fprintf(stderr, "Unsupported pixel format\n"); fprintf(stderr, "Unsupported pixel format\n");
return 0; return 0;
} }
*(red) = rgb[0]; *(red) = rgb[0];
@@ -1357,13 +1357,10 @@ bool wxXPMFileHandler::LoadFile(wxBitmap *bitmap, const wxString& name,
if (stream.Ok()) if (stream.Ok())
{ {
wxImage image(decoder.ReadFile(stream)); wxImage image(decoder.ReadFile(stream));
if (image.Ok()) return image.Ok() && bitmap->CreateFromImage(image);
return CreateFromImage(image);
else
return FALSE;
} }
else #else // !wxHAVE_LIB_XPM && !wxUSE_STREAMS
return FALSE; return FALSE;
#endif // wxHAVE_LIB_XPM / wxUSE_STREAMS #endif // wxHAVE_LIB_XPM / wxUSE_STREAMS
} }
@@ -1463,7 +1460,7 @@ bool wxXPMDataHandler::Create(wxBitmap *bitmap, void *bits,
M_BMPHANDLERDATA->m_mask->SetBitmap( (WXPixmap) mask ); M_BMPHANDLERDATA->m_mask->SetBitmap( (WXPixmap) mask );
M_BMPHANDLERDATA->m_mask->SetDisplay( xdisplay ); M_BMPHANDLERDATA->m_mask->SetDisplay( xdisplay );
} }
return TRUE; return TRUE;
} }
else else
{ {
@@ -1471,14 +1468,11 @@ bool wxXPMDataHandler::Create(wxBitmap *bitmap, void *bits,
return FALSE; return FALSE;
} }
#else #else // !wxHAVE_LIB_XPM
wxXPMDecoder decoder; wxXPMDecoder decoder;
wxImage image(decoder.ReadData(bits)); wxImage image(decoder.ReadData((const char **)bits));
if (image.Ok()) return image.Ok() && bitmap->CreateFromImage(image);
return bitmap->CreateFromImage(image); #endif // wxHAVE_LIB_XPM/!wxHAVE_LIB_XPM
else
return FALSE;
#endif
} }
#endif // wxUSE_XPM #endif // wxUSE_XPM