static int create_bitmap(HDC *dc, HBITMAP *prev_bitmap, uint8_t **data, int *nstride, int width, int height) { HBITMAP bitmap; struct { BITMAPINFO inf; RGBQUAD palette[255]; } bitmap_info; memset(&bitmap_info, 0, sizeof(bitmap_info)); bitmap_info.inf.bmiHeader.biSize = sizeof(bitmap_info.inf.bmiHeader); bitmap_info.inf.bmiHeader.biWidth = width; bitmap_info.inf.bmiHeader.biHeight = height; bitmap_info.inf.bmiHeader.biPlanes = 1; bitmap_info.inf.bmiHeader.biBitCount = 32; bitmap_info.inf.bmiHeader.biCompression = BI_RGB; *nstride = width * 4; *dc = create_compatible_dc(); if (!*dc) { return 0; } bitmap = CreateDIBSection(*dc, &bitmap_info.inf, 0, (void **)data, NULL, 0); if (!bitmap) { DeleteObject(*dc); return 0; } *prev_bitmap = (HBITMAP)SelectObject(*dc, bitmap); return 1; }
/**************************************************************************** * * ROUTINE : xprintf * * INPUTS : const PB_INSTANCE *ppbi : Pointer to decoder instance. * long n_pixel : Offset into buffer to write text. * const char *format : Format string for print. * ... : Variable length argument list. * * OUTPUTS : None. * * RETURNS : int: Size (in bytes) of the formatted text. * * FUNCTION : Display a printf style message on the current video frame. * * SPECIAL NOTES : None. * ****************************************************************************/ int onyx_xprintf(unsigned char *ppbuffer, long n_pixel, long n_size, long n_stride, const char *format, ...) { BOOL b_rc; va_list arglist; HFONT hfont, hfonto; int rc = 0; char sz_formatted[256] = ""; unsigned char *p_dest = &ppbuffer[n_pixel]; #ifdef _WIN32_WCE // Set up temporary bitmap HDC hdc_memory = NULL; HBITMAP hbm_temp = NULL; HBITMAP hbm_orig = NULL; RECT rect; // Copy bitmap to video frame long x; long y; // Format text va_start(arglist, format); _vsnprintf(sz_formatted, sizeof(sz_formatted), format, arglist); va_end(arglist); rect.left = 0; rect.top = 0; rect.right = 8 * strlen(sz_formatted); rect.bottom = 8; hdc_memory = create_compatible_dc(NULL); if (hdc_memory == NULL) goto Exit; hbm_temp = create_bitmap(rect.right, rect.bottom, 1, 1, NULL); if (hbm_temp == NULL) goto Exit; hbm_orig = (HBITMAP)(select_object(hdc_memory, hbm_temp)); if (!hbm_orig) goto Exit; // Write text into bitmap // font? hfont = create_font(8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, VARIABLE_PITCH | FF_SWISS, ""); if (hfont == NULL) goto Exit; hfonto = (HFONT)(select_object(hdc_memory, hbm_temp)); if (!hfonto) goto Exit; select_object(hdc_memory, hfont); set_text_color(hdc_memory, 1); set_bk_color(hdc_memory, 0); set_bk_mode(hdc_memory, TRANSPARENT); b_rc = bit_blt(hdc_memory, rect.left, rect.top, rect.right, rect.bottom, hdc_memory, rect.left, rect.top, BLACKNESS); if (!b_rc) goto Exit; b_rc = ext_text_out(hdc_memory, 0, 0, ETO_CLIPPED, &rect, sz_formatted, strlen(sz_formatted), NULL); if (!b_rc) goto Exit; for (y = rect.top; y < rect.bottom; ++y) { for (x = rect.left; x < rect.right; ++x) { if (get_pixel(hdc_memory, x, rect.bottom - 1 - y)) p_dest[x] = 255; } p_dest += n_stride; } rc = strlen(sz_formatted); Exit: if (hbm_temp != NULL) { if (hbm_orig != NULL) { select_object(hdc_memory, hbm_orig); } delete_object(hbm_temp); } if (hfont != NULL) { if (hfonto != NULL) select_object(hdc_memory, hfonto); delete_object(hfont); } if (hdc_memory != NULL) delete_dc(hdc_memory); hdc_memory = 0; #endif return rc; }
RedPixmapSw::RedPixmapSw(int width, int height, RedDrawable::Format format, bool top_bottom, RedWindow *win) : RedPixmap(width, height, format, top_bottom) { DWORD *pixel_format; ASSERT(format == RedDrawable::ARGB32 || format == RedDrawable::RGB32 || format == RedDrawable::RGB16_555 || format == RedDrawable::RGB16_565 || format == RedDrawable::A1); ASSERT(sizeof(RedPixmap_p) <= PIXELES_SOURCE_OPAQUE_SIZE); struct { BITMAPINFO inf; RGBQUAD palette[255]; } bitmap_info; memset(&bitmap_info, 0, sizeof(bitmap_info)); bitmap_info.inf.bmiHeader.biSize = sizeof(bitmap_info.inf.bmiHeader); bitmap_info.inf.bmiHeader.biWidth = _width; bitmap_info.inf.bmiHeader.biHeight = top_bottom ? -_height : _height; /*#ifdef USE_OGL // ----------------------------------------------------------------------------- // ensure valid access to additional stride. // apparently glReadPixels validate ((ptr of last line) + GL_PACK_ROW_LENGTH + 1). // seen on "ATI Radeon HD 2400 PRO" "2.0.6479 Release" if (top_bottom) { bitmap_info.inf.bmiHeader.biHeight--; } else { bitmap_info.inf.bmiHeader.biHeight++; } //------------------------------------------------------------------------------ #endif*/ bitmap_info.inf.bmiHeader.biPlanes = 1; bitmap_info.inf.bmiHeader.biBitCount = RedDrawable::format_to_bpp(format); if (format == RedDrawable::RGB16_565) { bitmap_info.inf.bmiHeader.biCompression = BI_BITFIELDS; } else { bitmap_info.inf.bmiHeader.biCompression = BI_RGB; } switch (format) { case RedDrawable::A1: bitmap_info.inf.bmiColors[0].rgbRed = 0; bitmap_info.inf.bmiColors[0].rgbGreen = 0; bitmap_info.inf.bmiColors[0].rgbBlue = 0; bitmap_info.inf.bmiColors[1].rgbRed = 0xff; bitmap_info.inf.bmiColors[1].rgbGreen = 0xff; bitmap_info.inf.bmiColors[1].rgbBlue = 0xff; break; case RedDrawable::RGB16_565: pixel_format = (DWORD *)bitmap_info.inf.bmiColors; pixel_format[0] = 0xf800; pixel_format[1] = 0x07e0; pixel_format[2] = 0x001f; break; } AutoDC dc(create_compatible_dc()); AutoGDIObject bitmap(CreateDIBSection(dc.get(), &bitmap_info.inf, 0, (VOID **)&_data, NULL, 0)); if (!bitmap.valid()) { THROW("create compatible bitmap failed"); } /*#ifdef USE_OGL SetWindowOrgEx(dc.get(), 0, -1, NULL); // compensate for one pad line #endif*/ ((RedPixmap_p*)get_opaque())->prev_bitmap = (HBITMAP)SelectObject(dc.get(), bitmap.release()); ((RedPixmap_p*)get_opaque())->pixels_source_p.dc = dc.release(); }