void SplashPaint(Splash * splash, HDC hdc) { unsigned numColors = splash->screenFormat.colorMap ? splash->screenFormat.numColors : 0; BITMAPV4HEADER *pBmi; HPALETTE hOldPal = NULL; if (!splash->frames) return; if (splash->currentFrame < 0 || splash->currentFrame >= splash->frameCount) return; pBmi = (BITMAPV4HEADER *) SAFE_SIZE_STRUCT_ALLOC(alloca, sizeof(BITMAPV4HEADER), sizeof(RGBQUAD), numColors); if (!pBmi) { return; } memset(pBmi, 0, sizeof(BITMAPV4HEADER)); if (splash->screenFormat.colorMap) memcpy(((BYTE *) pBmi) + sizeof(BITMAPV4HEADER), splash->screenFormat.colorMap, sizeof(RGBQUAD) * numColors); pBmi->bV4Size = sizeof(BITMAPV4HEADER); pBmi->bV4Width = splash->width; pBmi->bV4Height = -splash->height; pBmi->bV4Planes = 1; pBmi->bV4BitCount = (WORD) (splash->screenFormat.depthBytes * 8); /* we're ALWAYS using BGRA in screenFormat */ pBmi->bV4V4Compression = BI_RGB; pBmi->bV4ClrUsed = numColors; pBmi->bV4ClrImportant = numColors; pBmi->bV4AlphaMask = splash->screenFormat.mask[3]; pBmi->bV4RedMask = splash->screenFormat.mask[2]; pBmi->bV4GreenMask = splash->screenFormat.mask[1]; pBmi->bV4BlueMask = splash->screenFormat.mask[0]; /* creating the palette in SplashInitPlatform does not work, so I'm creating it here on demand */ if (!splash->hPalette) { unsigned i; LOGPALETTE *pLogPal = (LOGPALETTE *) SAFE_SIZE_STRUCT_ALLOC(malloc, sizeof(LOGPALETTE), sizeof(PALETTEENTRY), numColors); if (!pLogPal) { return; } pLogPal->palVersion = 0x300; pLogPal->palNumEntries = (WORD) numColors; for (i = 0; i < numColors; i++) { pLogPal->palPalEntry[i].peRed = (BYTE) QUAD_RED(splash->colorMap[i]); pLogPal->palPalEntry[i].peGreen = (BYTE) QUAD_GREEN(splash->colorMap[i]); pLogPal->palPalEntry[i].peBlue = (BYTE) QUAD_BLUE(splash->colorMap[i]); pLogPal->palPalEntry[i].peFlags = PC_NOCOLLAPSE; } splash->hPalette = CreatePalette(pLogPal); free(pLogPal); } if (splash->hPalette) { hOldPal = SelectPalette(hdc, splash->hPalette, FALSE); RealizePalette(hdc); } StretchDIBits(hdc, 0, 0, splash->width, splash->height, 0, 0, splash->width, splash->height, splash->screenData, (BITMAPINFO *) pBmi, DIB_RGB_COLORS, SRCCOPY); if (hOldPal) SelectPalette(hdc, hOldPal, FALSE); }
void SplashInitPlatform(Splash * splash) { int shapeVersionMajor, shapeVersionMinor; // This setting enables the synchronous Xlib mode! // Don't use it == 1 in production builds! #if (defined DEBUG) _Xdebug = 1; #endif pthread_mutex_init(&splash->lock, NULL); // We should not ignore any errors. //XSetErrorHandler(HandleError); // XSetIOErrorHandler(HandleIOError); XSetIOErrorHandler(NULL); splash->display = XOpenDisplay(NULL); if (!splash->display) { splash->isVisible = -1; return; } shapeSupported = XShapeQueryExtension(splash->display, &shapeEventBase, &shapeErrorBase); if (shapeSupported) { XShapeQueryVersion(splash->display, &shapeVersionMajor, &shapeVersionMinor); } splash->screen = XDefaultScreenOfDisplay(splash->display); splash->visual = XDefaultVisualOfScreen(splash->screen); switch (splash->visual->class) { case TrueColor: { int depth = XDefaultDepthOfScreen(splash->screen); splash->byteAlignment = 1; splash->maskRequired = shapeSupported; initFormat(&splash->screenFormat, splash->visual->red_mask, splash->visual->green_mask, splash->visual->blue_mask, 0); splash->screenFormat.byteOrder = (XImageByteOrder(splash->display) == LSBFirst ? BYTE_ORDER_LSBFIRST : BYTE_ORDER_MSBFIRST); splash->screenFormat.depthBytes = (depth + 7) / 8; // TrueColor depth probably can't be less // than 8 bits, and it's always byte padded break; } case PseudoColor: { int availableColors; int numColors; int numComponents[3]; unsigned long colorIndex[SPLASH_COLOR_MAP_SIZE]; XColor xColors[SPLASH_COLOR_MAP_SIZE]; int i; int depth = XDefaultDepthOfScreen(splash->screen); int scale = 65535 / MAX_COLOR_VALUE; availableColors = GetNumAvailableColors(splash->display, splash->screen, splash->visual->map_entries); numColors = quantizeColors(availableColors, numComponents); if (numColors > availableColors) { // Could not allocate the color cells. Most probably // the pool got exhausted. Disable the splash screen. XCloseDisplay(splash->display); splash->isVisible = -1; splash->display = NULL; splash->screen = NULL; splash->visual = NULL; fprintf(stderr, "Warning: unable to initialize the splashscreen. Not enough available color cells.\n"); return; } splash->cmap = AllocColors(splash->display, splash->screen, numColors, colorIndex); for (i = 0; i < numColors; i++) { splash->colorIndex[i] = colorIndex[i]; } initColorCube(numComponents, splash->colorMap, splash->dithers, splash->colorIndex); for (i = 0; i < numColors; i++) { xColors[i].pixel = colorIndex[i]; xColors[i].red = (unsigned short) QUAD_RED(splash->colorMap[colorIndex[i]]) * scale; xColors[i].green = (unsigned short) QUAD_GREEN(splash->colorMap[colorIndex[i]]) * scale; xColors[i].blue = (unsigned short) QUAD_BLUE(splash->colorMap[colorIndex[i]]) * scale; xColors[i].flags = DoRed | DoGreen | DoBlue; } XStoreColors(splash->display, splash->cmap, xColors, numColors); initFormat(&splash->screenFormat, 0, 0, 0, 0); splash->screenFormat.colorIndex = splash->colorIndex; splash->screenFormat.depthBytes = (depth + 7) / 8; // or always 8? splash->screenFormat.colorMap = splash->colorMap; splash->screenFormat.dithers = splash->dithers; splash->screenFormat.numColors = numColors; splash->screenFormat.byteOrder = BYTE_ORDER_NATIVE; break; } default: ; /* FIXME: should probably be fixed, but javaws splash screen doesn't support other visuals either */ } }