| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright (c) 2010 The VP8 project authors. All Rights Reserved. | |
| 3 * | |
| 4 * Use of this source code is governed by a BSD-style license | |
| 5 * that can be found in the LICENSE file in the root of the source | |
| 6 * tree. An additional intellectual property rights grant can be found | |
| 7 * in the file PATENTS. All contributing project authors may | |
| 8 * be found in the AUTHORS file in the root of the source tree. | |
| 9 */ | |
| 10 | |
| 11 | |
| 12 /**************************************************************************** | |
| 13 * | |
| 14 * Module Title : xprintf.cpp | |
| 15 * | |
| 16 * Description : Display a printf style message on the current video frame
. | |
| 17 * | |
| 18 ****************************************************************************/ | |
| 19 | |
| 20 /**************************************************************************** | |
| 21 * Header Files | |
| 22 ****************************************************************************/ | |
| 23 | |
| 24 #include <stdio.h> | |
| 25 #include <stdarg.h> | |
| 26 #ifdef _WIN32_WCE | |
| 27 #include <windows.h> | |
| 28 #endif | |
| 29 #include "xprintf.h" | |
| 30 | |
| 31 /**************************************************************************** | |
| 32 * | |
| 33 * ROUTINE : xprintf | |
| 34 * | |
| 35 * INPUTS : const PB_INSTANCE *ppbi : Pointer to decoder instance. | |
| 36 * long n_pixel : Offset into buffer to write text. | |
| 37 * const char *format : Format string for print. | |
| 38 * ... : Variable length argument list. | |
| 39 * | |
| 40 * OUTPUTS : None. | |
| 41 * | |
| 42 * RETURNS : int: Size (in bytes) of the formatted text. | |
| 43 * | |
| 44 * FUNCTION : Display a printf style message on the current video frame. | |
| 45 * | |
| 46 * SPECIAL NOTES : None. | |
| 47 * | |
| 48 ****************************************************************************/ | |
| 49 int onyx_xprintf(unsigned char *ppbuffer, long n_pixel, long n_size, long n_stri
de, const char *format, ...) | |
| 50 { | |
| 51 BOOL b_rc; | |
| 52 va_list arglist; | |
| 53 HFONT hfont, hfonto; | |
| 54 | |
| 55 int rc = 0; | |
| 56 char sz_formatted[256] = ""; | |
| 57 unsigned char *p_dest = &ppbuffer[n_pixel]; | |
| 58 | |
| 59 #ifdef _WIN32_WCE | |
| 60 // Set up temporary bitmap | |
| 61 HDC hdc_memory = NULL; | |
| 62 HBITMAP hbm_temp = NULL; | |
| 63 HBITMAP hbm_orig = NULL; | |
| 64 | |
| 65 RECT rect; | |
| 66 | |
| 67 // Copy bitmap to video frame | |
| 68 long x; | |
| 69 long y; | |
| 70 | |
| 71 // Format text | |
| 72 va_start(arglist, format); | |
| 73 _vsnprintf(sz_formatted, sizeof(sz_formatted), format, arglist); | |
| 74 va_end(arglist); | |
| 75 | |
| 76 rect.left = 0; | |
| 77 rect.top = 0; | |
| 78 rect.right = 8 * strlen(sz_formatted); | |
| 79 rect.bottom = 8; | |
| 80 | |
| 81 hdc_memory = create_compatible_dc(NULL); | |
| 82 | |
| 83 if (hdc_memory == NULL) | |
| 84 goto Exit; | |
| 85 | |
| 86 hbm_temp = create_bitmap(rect.right, rect.bottom, 1, 1, NULL); | |
| 87 | |
| 88 if (hbm_temp == NULL) | |
| 89 goto Exit; | |
| 90 | |
| 91 hbm_orig = (HBITMAP)(select_object(hdc_memory, hbm_temp)); | |
| 92 | |
| 93 if (!hbm_orig) | |
| 94 goto Exit; | |
| 95 | |
| 96 // Write text into bitmap | |
| 97 // font? | |
| 98 hfont = create_font(8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, VARIABLE_PITCH | FF_
SWISS, ""); | |
| 99 | |
| 100 if (hfont == NULL) | |
| 101 goto Exit; | |
| 102 | |
| 103 hfonto = (HFONT)(select_object(hdc_memory, hbm_temp)); | |
| 104 | |
| 105 if (!hfonto) | |
| 106 goto Exit; | |
| 107 | |
| 108 select_object(hdc_memory, hfont); | |
| 109 set_text_color(hdc_memory, 1); | |
| 110 set_bk_color(hdc_memory, 0); | |
| 111 set_bk_mode(hdc_memory, TRANSPARENT); | |
| 112 | |
| 113 b_rc = bit_blt(hdc_memory, rect.left, rect.top, rect.right, rect.bottom, hdc
_memory, rect.left, rect.top, BLACKNESS); | |
| 114 | |
| 115 if (!b_rc) | |
| 116 goto Exit; | |
| 117 | |
| 118 b_rc = ext_text_out(hdc_memory, 0, 0, ETO_CLIPPED, &rect, sz_formatted, strl
en(sz_formatted), NULL); | |
| 119 | |
| 120 if (!b_rc) | |
| 121 goto Exit; | |
| 122 | |
| 123 for (y = rect.top; y < rect.bottom; ++y) | |
| 124 { | |
| 125 for (x = rect.left; x < rect.right; ++x) | |
| 126 { | |
| 127 if (get_pixel(hdc_memory, x, rect.bottom - 1 - y)) | |
| 128 p_dest[x] = 255; | |
| 129 } | |
| 130 | |
| 131 p_dest += n_stride; | |
| 132 } | |
| 133 | |
| 134 rc = strlen(sz_formatted); | |
| 135 | |
| 136 Exit: | |
| 137 | |
| 138 if (hbm_temp != NULL) | |
| 139 { | |
| 140 if (hbm_orig != NULL) | |
| 141 { | |
| 142 select_object(hdc_memory, hbm_orig); | |
| 143 } | |
| 144 | |
| 145 delete_object(hbm_temp); | |
| 146 } | |
| 147 | |
| 148 if (hfont != NULL) | |
| 149 { | |
| 150 if (hfonto != NULL) | |
| 151 select_object(hdc_memory, hfonto); | |
| 152 | |
| 153 delete_object(hfont); | |
| 154 } | |
| 155 | |
| 156 if (hdc_memory != NULL) | |
| 157 delete_dc(hdc_memory); | |
| 158 | |
| 159 hdc_memory = 0; | |
| 160 | |
| 161 #endif | |
| 162 | |
| 163 return rc; | |
| 164 } | |
| OLD | NEW |