| 1 | /*************************************************************** |
|---|
| 2 | ** |
|---|
| 3 | ** Broadcom Corp. Confidential |
|---|
| 4 | ** Copyright 2002 Broadcom Corp. All Rights Reserved. |
|---|
| 5 | ** |
|---|
| 6 | ** THIS SOFTWARE MAY ONLY BE USED SUBJECT TO AN EXECUTED |
|---|
| 7 | ** SOFTWARE LICENSE AGREEMENT BETWEEN THE USER AND BROADCOM. |
|---|
| 8 | ** YOU HAVE NO RIGHT TO USE OR EXPLOIT THIS MATERIAL EXCEPT |
|---|
| 9 | ** SUBJECT TO THE TERMS OF SUCH AN AGREEMENT. |
|---|
| 10 | ** |
|---|
| 11 | ** Description: bgfx core implementation |
|---|
| 12 | ** |
|---|
| 13 | ** Created: 8/22/2002 by Jeffrey P. Fisher |
|---|
| 14 | ** |
|---|
| 15 | ** |
|---|
| 16 | ** |
|---|
| 17 | ****************************************************************/ |
|---|
| 18 | |
|---|
| 19 | /** include files **/ |
|---|
| 20 | #define BDISPATCH_BYPASS |
|---|
| 21 | #include "bgfx.h" |
|---|
| 22 | #undef BDISPATCH_BYPASS |
|---|
| 23 | #ifndef LINUX |
|---|
| 24 | #include "bdispatch.h" |
|---|
| 25 | #endif |
|---|
| 26 | |
|---|
| 27 | #define ZORDER_TUNNEL 3 |
|---|
| 28 | #define ZORDER_FX 2 |
|---|
| 29 | #define ZORDER_TOP 1 |
|---|
| 30 | #define ZORDER_BOTTOM 0 |
|---|
| 31 | |
|---|
| 32 | |
|---|
| 33 | #define SURF_WIDTH 720 |
|---|
| 34 | |
|---|
| 35 | #define BGFX_MIN(x,y) ((x < y) ? x : y) |
|---|
| 36 | #define bgfx_valid_flags(x) ((x & BGFX_SURF_RGB) ? (x & BGFX_SURF_PRIMARY) : 1) |
|---|
| 37 | #define bgfx_clut8_to_rgb(clut,c) (uint32_t)(clut[c]) |
|---|
| 38 | |
|---|
| 39 | /* blit row a1 to clut 8 destination */ |
|---|
| 40 | static inline void bgfx_render_a1_to_clut4( uint8_t *src, uint8_t *dst, |
|---|
| 41 | int width, uint8_t c, int odd_pixel ) |
|---|
| 42 | { |
|---|
| 43 | int i; |
|---|
| 44 | |
|---|
| 45 | SGL_TRACE(("%p,%p,%d,0x%02x\n",src,dst,width,c)); |
|---|
| 46 | for (i = 0; i < width; i++) |
|---|
| 47 | { |
|---|
| 48 | if (src[i>>3] & (1<<(7-(i%8)))) |
|---|
| 49 | { |
|---|
| 50 | if (odd_pixel & 1) |
|---|
| 51 | { |
|---|
| 52 | *dst &= 0xF0; |
|---|
| 53 | *dst |= (c & 0xF); |
|---|
| 54 | } |
|---|
| 55 | else |
|---|
| 56 | { |
|---|
| 57 | *dst &= 0xF; |
|---|
| 58 | *dst |= (c & 0xF) << 4; |
|---|
| 59 | } |
|---|
| 60 | SGL_TRACE(("%d,",i)); |
|---|
| 61 | } |
|---|
| 62 | if (odd_pixel) |
|---|
| 63 | { |
|---|
| 64 | odd_pixel = 0; |
|---|
| 65 | dst++; |
|---|
| 66 | } |
|---|
| 67 | else |
|---|
| 68 | odd_pixel = 1; |
|---|
| 69 | |
|---|
| 70 | } |
|---|
| 71 | SGL_TRACE(("\n")); |
|---|
| 72 | } |
|---|
| 73 | |
|---|
| 74 | /* blit row a8 to clut 8 destination */ |
|---|
| 75 | static inline void bgfx_render_a8_to_clut4( uint8_t *src, uint8_t *dst, int width, uint8_t c ) |
|---|
| 76 | { |
|---|
| 77 | int i; |
|---|
| 78 | for (i = 0; i < width; i++) |
|---|
| 79 | { |
|---|
| 80 | if (*src > 0x80) |
|---|
| 81 | { |
|---|
| 82 | if (i & 1) |
|---|
| 83 | { |
|---|
| 84 | *dst &= 0xF0; |
|---|
| 85 | *dst |= (c & 0xF); |
|---|
| 86 | } |
|---|
| 87 | else |
|---|
| 88 | { |
|---|
| 89 | *dst &= 0xF; |
|---|
| 90 | *dst |= (c & 0xF) << 4; |
|---|
| 91 | } |
|---|
| 92 | } |
|---|
| 93 | SGL_TRACE(("0x%02x(0x%02x)",*src,*dst)); |
|---|
| 94 | if (i & 1) |
|---|
| 95 | dst++; |
|---|
| 96 | src++; |
|---|
| 97 | } |
|---|
| 98 | SGL_TRACE(("\n")); |
|---|
| 99 | } |
|---|
| 100 | |
|---|
| 101 | |
|---|
| 102 | /* blit row a1 to clut 8 destination */ |
|---|
| 103 | static inline void bgfx_render_a1_to_clut8( uint8_t *src, uint8_t *dst, int width, uint8_t c ) |
|---|
| 104 | { |
|---|
| 105 | int i; |
|---|
| 106 | |
|---|
| 107 | SGL_TRACE(("%p,%p,%d,0x%02x\n",src,dst,width,c)); |
|---|
| 108 | for (i = 0; i < width; i++) |
|---|
| 109 | { |
|---|
| 110 | if (src[i>>3] & (1<<(7-(i%8)))) |
|---|
| 111 | { |
|---|
| 112 | *dst = c; |
|---|
| 113 | SGL_TRACE(("%d,",i)); |
|---|
| 114 | } |
|---|
| 115 | dst++; |
|---|
| 116 | } |
|---|
| 117 | SGL_TRACE(("\n")); |
|---|
| 118 | } |
|---|
| 119 | /* blit row a8 to clut 8 destination */ |
|---|
| 120 | static inline void bgfx_render_a8_to_clut8( uint8_t *src, uint8_t *dst, int width, uint8_t c ) |
|---|
| 121 | { |
|---|
| 122 | int i; |
|---|
| 123 | for (i = 0; i < width; i++) |
|---|
| 124 | { |
|---|
| 125 | if (*src > 0x80) |
|---|
| 126 | { |
|---|
| 127 | *dst = c; |
|---|
| 128 | } |
|---|
| 129 | SGL_TRACE(("0x%02x(0x%02x)",*src,*dst)); |
|---|
| 130 | dst++; |
|---|
| 131 | src++; |
|---|
| 132 | } |
|---|
| 133 | SGL_TRACE(("\n")); |
|---|
| 134 | } |
|---|
| 135 | |
|---|
| 136 | #ifdef CONFIG_BGFX_SURF_RGB |
|---|
| 137 | |
|---|
| 138 | /* blit row a1 to 8888 ARGB destination */ |
|---|
| 139 | static inline void bgfx_render_a1_to_rgb( uint8_t *src, uint8_t *dst, int width, uint32_t c ) |
|---|
| 140 | { |
|---|
| 141 | int i; |
|---|
| 142 | |
|---|
| 143 | SGL_TRACE(("%p,%p,%d,0x%02lx\n",src,dst,width,c)); |
|---|
| 144 | for (i = 0; i < width; i++) |
|---|
| 145 | { |
|---|
| 146 | if (src[i>>3] & (1<<(7-(i%8)))) |
|---|
| 147 | { |
|---|
| 148 | *((uint32_t*)dst) = c; |
|---|
| 149 | SGL_TRACE(("%d,",i)); |
|---|
| 150 | } |
|---|
| 151 | dst += 4; |
|---|
| 152 | } |
|---|
| 153 | SGL_TRACE(("\n")); |
|---|
| 154 | } |
|---|
| 155 | /* blit row a8 to 8888 ARGB destination */ |
|---|
| 156 | /* |
|---|
| 157 | #define SGL_BLEND(a,rs,rd) (((rs * a)/0xFF) + (rd - ((a * rd)/0xFF)) & 0xFF) |
|---|
| 158 | */ |
|---|
| 159 | #define SGL_BLEND(a,rs,rd) ((a * (rs-rd) >> 8) + rd) |
|---|
| 160 | static inline void bgfx_render_a8_to_rgb( uint8_t *src, uint8_t *dst, int width, uint32_t c) |
|---|
| 161 | { |
|---|
| 162 | register int i; |
|---|
| 163 | register uint32_t a,r,g,b; |
|---|
| 164 | register uint32_t a_src; |
|---|
| 165 | register uint32_t r_src = (c >> 16) & 0xFF; |
|---|
| 166 | register uint32_t g_src = (c >> 8) & 0xFF; |
|---|
| 167 | register uint32_t b_src = (c >> 0) & 0xFF; |
|---|
| 168 | for (i = 0; i < width; i++) |
|---|
| 169 | { |
|---|
| 170 | a_src = *src; |
|---|
| 171 | a = dst[3]; r = dst[2]; g = dst[1]; b = dst[0]; |
|---|
| 172 | *((uint32_t*)dst) = (a << 24) | |
|---|
| 173 | (SGL_BLEND(a_src,r_src,r) << 16) | |
|---|
| 174 | (SGL_BLEND(a_src,g_src,g) << 8) | |
|---|
| 175 | SGL_BLEND(a_src,b_src,b); |
|---|
| 176 | SGL_TRACE(("0x%02x(0x%08x)",*src,*((uint32_t*)dst))); |
|---|
| 177 | dst += 4; |
|---|
| 178 | src++; |
|---|
| 179 | } |
|---|
| 180 | SGL_TRACE(("\n")); |
|---|
| 181 | } |
|---|
| 182 | #endif |
|---|
| 183 | |
|---|
| 184 | /****************************************************************} |
|---|
| 185 | * INPUTS: io and protection function structures |
|---|
| 186 | * OUTPUTS: none |
|---|
| 187 | * RETURNS: non-zero on failure |
|---|
| 188 | * FUNCTION: initialize sgl, primarily for handling freetype |
|---|
| 189 | * |
|---|
| 190 | ****************************************************************/ |
|---|
| 191 | int bgfx_init(bgfx_io_t *io_p,bgfx_prot_t *prot_p) |
|---|
| 192 | { |
|---|
| 193 | bgfx_config(io_p,prot_p); |
|---|
| 194 | return bgfx_font_init(); |
|---|
| 195 | } |
|---|
| 196 | /****************************************************************} |
|---|
| 197 | * INPUTS: none |
|---|
| 198 | * OUTPUTS: none |
|---|
| 199 | * RETURNS: non-zero on failure |
|---|
| 200 | * FUNCTION: release sgl global resources, primarily for handling freetype |
|---|
| 201 | * |
|---|
| 202 | ****************************************************************/ |
|---|
| 203 | void bgfx_done(void) |
|---|
| 204 | { |
|---|
| 205 | bgfx_font_done(); |
|---|
| 206 | } |
|---|
| 207 | |
|---|
| 208 | /****************************************************************} |
|---|
| 209 | * bgfx_create |
|---|
| 210 | * |
|---|
| 211 | * INPUTS: node_name - name of the node to create surface in |
|---|
| 212 | * p - surface structure to initialize |
|---|
| 213 | * OUTPUTS: none |
|---|
| 214 | * RETURNS: non-zero on failure |
|---|
| 215 | * FUNCTION: initialize and create the surface. |
|---|
| 216 | * |
|---|
| 217 | ****************************************************************/ |
|---|
| 218 | int bgfx_create(bgfx_surf_p p,uint16_t width,uint16_t height, |
|---|
| 219 | uint8_t *ptr, uint16_t pitch, |
|---|
| 220 | bgfx_palette_t *palette, |
|---|
| 221 | uint32_t flags) |
|---|
| 222 | { |
|---|
| 223 | SGL_MEMSET(p,0,sizeof(bgfx_surf_t)); |
|---|
| 224 | |
|---|
| 225 | if (!ptr && (flags & BGFX_SURF_PRIMARY)) |
|---|
| 226 | { |
|---|
| 227 | SGL_DEBUG(("bgfx_create SGL_SURF_FULLSCREEN requires valid memory ptr.\n")); |
|---|
| 228 | } |
|---|
| 229 | |
|---|
| 230 | p->bpp = 4; /* = 8bpp TODO support 4bpp */ |
|---|
| 231 | p->flags = flags; |
|---|
| 232 | if (ptr) |
|---|
| 233 | { |
|---|
| 234 | p->surface.pitch = pitch; |
|---|
| 235 | p->surface.buf = ptr; |
|---|
| 236 | p->surface.width = width; |
|---|
| 237 | p->surface.height = height; |
|---|
| 238 | } |
|---|
| 239 | else |
|---|
| 240 | { |
|---|
| 241 | p->surface.pitch = width * p->bpp / 8; |
|---|
| 242 | if (p->surface.pitch & 0x1) |
|---|
| 243 | p->surface.pitch += 1; |
|---|
| 244 | |
|---|
| 245 | p->surface.width = width; |
|---|
| 246 | p->surface.height = height; |
|---|
| 247 | p->surface.buf = SGL_MALLOC(p->surface.pitch * p->surface.height); |
|---|
| 248 | p->flags |= BGFX_SURF_ALLOC; |
|---|
| 249 | } |
|---|
| 250 | |
|---|
| 251 | if (palette) |
|---|
| 252 | { |
|---|
| 253 | SGL_MEMCPY(&p->palette,palette,sizeof(bgfx_palette_t)); |
|---|
| 254 | } |
|---|
| 255 | return 0; |
|---|
| 256 | } |
|---|
| 257 | /**************************************************************** |
|---|
| 258 | * bgfx_destroy |
|---|
| 259 | * |
|---|
| 260 | * INPUTS: p - surface structure |
|---|
| 261 | * OUTPUTS: none |
|---|
| 262 | * RETURNS: none |
|---|
| 263 | * FUNCTION: free up surface resources |
|---|
| 264 | * |
|---|
| 265 | ****************************************************************/ |
|---|
| 266 | void bgfx_destroy(bgfx_surf_p p) |
|---|
| 267 | { |
|---|
| 268 | if (p->flags & BGFX_SURF_ALLOC) |
|---|
| 269 | { |
|---|
| 270 | SGL_FREE(p->surface.buf); |
|---|
| 271 | return; |
|---|
| 272 | } |
|---|
| 273 | } |
|---|
| 274 | /**************************************************************** |
|---|
| 275 | * bgfx_fill_rect |
|---|
| 276 | * |
|---|
| 277 | * INPUTS: p - surface structure |
|---|
| 278 | * OUTPUTS: w,h,flags - surface width,height and flags |
|---|
| 279 | * RETURNS: none |
|---|
| 280 | * FUNCTION: Return surface information (width,height, and flags) |
|---|
| 281 | * |
|---|
| 282 | ****************************************************************/ |
|---|
| 283 | void bgfx_get_info(bgfx_surf_p p,uint16_t *w,uint16_t *h,uint16_t *pitch, uint32_t *flags) |
|---|
| 284 | { |
|---|
| 285 | *w = p->surface.width; |
|---|
| 286 | *h = p->surface.height; |
|---|
| 287 | *pitch = p->surface.pitch; |
|---|
| 288 | *flags = p->flags; |
|---|
| 289 | } |
|---|
| 290 | /**************************************************************** |
|---|
| 291 | * bgfx_get_palette |
|---|
| 292 | * |
|---|
| 293 | * INPUTS: p - surface structure |
|---|
| 294 | * OUTPUTS: palette_p - return current palette |
|---|
| 295 | * RETURNS: none |
|---|
| 296 | * FUNCTION: get the current palett |
|---|
| 297 | * |
|---|
| 298 | ****************************************************************/ |
|---|
| 299 | void bgfx_get_palette(bgfx_surf_p p,bgfx_palette_t *palette_p) |
|---|
| 300 | { |
|---|
| 301 | SGL_MEMCPY(palette_p,&p->palette,sizeof(bgfx_palette_t)); |
|---|
| 302 | } |
|---|
| 303 | /**************************************************************** |
|---|
| 304 | * bgfx_set_palette |
|---|
| 305 | * |
|---|
| 306 | * INPUTS: p - surface structure |
|---|
| 307 | * palette_p - the palette |
|---|
| 308 | * OUTPUTS: none |
|---|
| 309 | * RETURNS: none |
|---|
| 310 | * FUNCTION: set the global system palette |
|---|
| 311 | * |
|---|
| 312 | ****************************************************************/ |
|---|
| 313 | void bgfx_set_palette(bgfx_surf_p p, bgfx_palette_t *palette_p) |
|---|
| 314 | { |
|---|
| 315 | SGL_MEMCPY(&p->palette,palette_p,sizeof(bgfx_palette_t)); |
|---|
| 316 | } |
|---|
| 317 | |
|---|
| 318 | /**************************************************************** |
|---|
| 319 | * bgfx_set_pixel |
|---|
| 320 | * |
|---|
| 321 | * INPUTS: p - surface structure |
|---|
| 322 | * x,y - coordinates |
|---|
| 323 | * c - pixel value |
|---|
| 324 | * OUTPUTS: none |
|---|
| 325 | * RETURNS: none |
|---|
| 326 | * FUNCTION: set the pixel at x,y |
|---|
| 327 | * |
|---|
| 328 | ****************************************************************/ |
|---|
| 329 | void bgfx_set_pixel(bgfx_surf_p p,uint16_t x,uint16_t y,bgfx_pixel c) |
|---|
| 330 | { |
|---|
| 331 | uint8_t *dst; |
|---|
| 332 | |
|---|
| 333 | if ((x >= p->surface.width) || (y >= p->surface.height)) |
|---|
| 334 | { |
|---|
| 335 | SGL_DEBUG(("bgfx_set_pixel param error (%p,%d,%d)\n",p,x,y)); |
|---|
| 336 | return; |
|---|
| 337 | } |
|---|
| 338 | |
|---|
| 339 | dst = (uint8_t*)p->surface.buf; |
|---|
| 340 | dst += y * p->surface.pitch + (x * p->bpp)/8; |
|---|
| 341 | #ifdef CONFIG_BGFX_SURF_RGB |
|---|
| 342 | if (p->flags & BGFX_SURF_RGB) |
|---|
| 343 | { |
|---|
| 344 | *((uint32_t*)dst) = bgfx_clut8_to_rgb(p->palette.clut,c); |
|---|
| 345 | bgfx_cacheflush(dst,4); |
|---|
| 346 | } |
|---|
| 347 | else |
|---|
| 348 | #endif |
|---|
| 349 | { |
|---|
| 350 | if (x & 1) |
|---|
| 351 | { |
|---|
| 352 | *dst &= 0xF0; |
|---|
| 353 | *dst |= (c & 0xF); |
|---|
| 354 | } |
|---|
| 355 | else |
|---|
| 356 | { |
|---|
| 357 | *dst &= 0xF; |
|---|
| 358 | *dst |= (c & 0xF) << 4; |
|---|
| 359 | } |
|---|
| 360 | bgfx_cacheflush(dst,1); |
|---|
| 361 | } |
|---|
| 362 | } |
|---|
| 363 | /**************************************************************** |
|---|
| 364 | * bgfx_get_pixel |
|---|
| 365 | * |
|---|
| 366 | * INPUTS: p - surface structure |
|---|
| 367 | * x,y - coordinates |
|---|
| 368 | * c - pixel value |
|---|
| 369 | * OUTPUTS: none |
|---|
| 370 | * RETURNS: none |
|---|
| 371 | * FUNCTION: get the pixel value at x,y. The bgfx_color will be the |
|---|
| 372 | * actual pixel value. |
|---|
| 373 | * |
|---|
| 374 | * NOTE: Not supported for RGB surfaces. To get a pixel for RGB access buf |
|---|
| 375 | * directly. |
|---|
| 376 | * |
|---|
| 377 | ****************************************************************/ |
|---|
| 378 | bgfx_pixel bgfx_get_pixel(bgfx_surf_p p,uint16_t x,uint16_t y) |
|---|
| 379 | { |
|---|
| 380 | uint8_t *dst; |
|---|
| 381 | if ((x >= p->surface.width) || (y >= p->surface.height)) |
|---|
| 382 | { |
|---|
| 383 | SGL_DEBUG(("bgfx_get_pixel param error (%p,%d,%d)\n",p,x,y)); |
|---|
| 384 | return 0; |
|---|
| 385 | } |
|---|
| 386 | dst = (uint8_t*)p->surface.buf; |
|---|
| 387 | dst += y * p->surface.pitch + (x * p->bpp)/8; |
|---|
| 388 | #ifdef CONFIG_BGFX_SURF_RGB |
|---|
| 389 | if (p->flags & BGFX_SURF_RGB) |
|---|
| 390 | return *((uint32_t*)dst); |
|---|
| 391 | #endif |
|---|
| 392 | if (x & 1) |
|---|
| 393 | { |
|---|
| 394 | return (*dst & 0xF0); |
|---|
| 395 | } |
|---|
| 396 | |
|---|
| 397 | return (*dst >> 4); |
|---|
| 398 | } |
|---|
| 399 | /**************************************************************** |
|---|
| 400 | * bgfx_h_draw_line |
|---|
| 401 | * |
|---|
| 402 | * INPUTS: p - surface structure |
|---|
| 403 | * x1,x2,y - coordinates |
|---|
| 404 | * c - pixel value |
|---|
| 405 | * OUTPUTS: none |
|---|
| 406 | * RETURNS: none |
|---|
| 407 | * FUNCTION: Draw a horizontal line make of pixels defined by the value c. |
|---|
| 408 | * |
|---|
| 409 | * JPF - these need to be optimized |
|---|
| 410 | * |
|---|
| 411 | ****************************************************************/ |
|---|
| 412 | void bgfx_h_draw_line(bgfx_surf_p p,uint16_t x1,uint16_t x2,uint16_t y, |
|---|
| 413 | bgfx_pixel c) |
|---|
| 414 | { |
|---|
| 415 | #if 1 |
|---|
| 416 | int w = x2 - x1; |
|---|
| 417 | |
|---|
| 418 | if (w < 0) |
|---|
| 419 | { |
|---|
| 420 | w = -w; |
|---|
| 421 | bgfx_fill_rect(p,x2,y,(uint16_t)w,1, c); |
|---|
| 422 | } |
|---|
| 423 | else |
|---|
| 424 | { |
|---|
| 425 | bgfx_fill_rect(p,x1,y,(uint16_t)w,1, c); |
|---|
| 426 | } |
|---|
| 427 | |
|---|
| 428 | #else |
|---|
| 429 | uint8_t *dst; |
|---|
| 430 | uint16_t w = x2 - x1; |
|---|
| 431 | uint16_t off; |
|---|
| 432 | |
|---|
| 433 | if ((x2 <= x1) || (y >= p->surface.height)) |
|---|
| 434 | { |
|---|
| 435 | SGL_DEBUG(("bgfx_h_draw_line param error (%p,%d,%d,%d,0x%02lx)\n",p,x1,x2,y,c)); |
|---|
| 436 | return; |
|---|
| 437 | } |
|---|
| 438 | |
|---|
| 439 | if (w > p->surface.width - x1) |
|---|
| 440 | w = p->surface.width - x1; |
|---|
| 441 | dst = (uint8_t*)p->surface.buf; |
|---|
| 442 | dst += (y * p->surface.pitch) + (x1 * p->bpp)/8; |
|---|
| 443 | |
|---|
| 444 | #ifdef CONFIG_BGFX_SURF_RGB |
|---|
| 445 | if (p->flags & BGFX_SURF_RGB) |
|---|
| 446 | { |
|---|
| 447 | uint32_t c32 = bgfx_clut8_to_rgb(p->palette.clut,c); |
|---|
| 448 | while (w--) |
|---|
| 449 | { |
|---|
| 450 | *((uint32_t*)dst) = c32; |
|---|
| 451 | dst += p->bpp/8; |
|---|
| 452 | } |
|---|
| 453 | } |
|---|
| 454 | else |
|---|
| 455 | #endif |
|---|
| 456 | { |
|---|
| 457 | while (w--) |
|---|
| 458 | { |
|---|
| 459 | off = (w * p->bpp)/8; |
|---|
| 460 | if (w & 1) |
|---|
| 461 | { |
|---|
| 462 | dst[off] &= 0xF0; |
|---|
| 463 | dst[off] |= (c & 0xF); |
|---|
| 464 | } |
|---|
| 465 | else |
|---|
| 466 | { |
|---|
| 467 | dst[off] &= 0xF; |
|---|
| 468 | dst[off] |= (c & 0xF) << 4; |
|---|
| 469 | } |
|---|
| 470 | } |
|---|
| 471 | } |
|---|
| 472 | bgfx_cacheflush(p->surface.buf,p->surface.pitch * p->surface.height); |
|---|
| 473 | #endif |
|---|
| 474 | } |
|---|
| 475 | /**************************************************************** |
|---|
| 476 | * bgfx_v_draw_line |
|---|
| 477 | * |
|---|
| 478 | * INPUTS: p - surface structure |
|---|
| 479 | * x,y1,y2 - coordinates |
|---|
| 480 | * c - pixel value |
|---|
| 481 | * OUTPUTS: none |
|---|
| 482 | * RETURNS: none |
|---|
| 483 | * FUNCTION: Draw a vertical line make of pixels defined by the value c. |
|---|
| 484 | * |
|---|
| 485 | * JPF - these need to be optimized |
|---|
| 486 | * |
|---|
| 487 | ****************************************************************/ |
|---|
| 488 | void bgfx_v_draw_line(bgfx_surf_p p,uint16_t x,uint16_t y1,uint16_t y2, |
|---|
| 489 | bgfx_pixel c) |
|---|
| 490 | { |
|---|
| 491 | uint8_t *dst; |
|---|
| 492 | uint16_t h = y2 - y1; |
|---|
| 493 | if ((y2 <= y1) || (x >= p->surface.width)) |
|---|
| 494 | { |
|---|
| 495 | SGL_DEBUG(("bgfx_v_draw_line param error (%p,%d,%d,%d,0x%02lx)\n",p,x,y1,y2,c)); |
|---|
| 496 | return; |
|---|
| 497 | } |
|---|
| 498 | |
|---|
| 499 | if (h > p->surface.height - y1) |
|---|
| 500 | h = p->surface.height - y1; |
|---|
| 501 | dst = (uint8_t*)p->surface.buf; |
|---|
| 502 | dst += y1 * p->surface.pitch + x * p->bpp/8; |
|---|
| 503 | |
|---|
| 504 | #ifdef CONFIG_BGFX_SURF_RGB |
|---|
| 505 | if (p->flags & BGFX_SURF_RGB) |
|---|
| 506 | { |
|---|
| 507 | uint32_t c32 = bgfx_clut8_to_rgb(p->palette.clut,c); |
|---|
| 508 | while (h--) |
|---|
| 509 | { |
|---|
| 510 | *((uint32_t*)dst) = c32; |
|---|
| 511 | dst += p->surface.pitch; |
|---|
| 512 | } |
|---|
| 513 | } |
|---|
| 514 | else |
|---|
| 515 | #endif |
|---|
| 516 | { |
|---|
| 517 | while (h--) |
|---|
| 518 | { |
|---|
| 519 | if (x & 1) |
|---|
| 520 | { |
|---|
| 521 | *dst &= 0xF0; |
|---|
| 522 | *dst |= (c & 0xF); |
|---|
| 523 | } |
|---|
| 524 | else |
|---|
| 525 | { |
|---|
| 526 | *dst &= 0xF; |
|---|
| 527 | *dst |= (c & 0xF) << 4; |
|---|
| 528 | } |
|---|
| 529 | dst += p->surface.pitch; |
|---|
| 530 | } |
|---|
| 531 | } |
|---|
| 532 | bgfx_cacheflush(p->surface.buf,p->surface.pitch * p->surface.height); |
|---|
| 533 | } |
|---|
| 534 | /**************************************************************** |
|---|
| 535 | * bgfx_fill_rect |
|---|
| 536 | * |
|---|
| 537 | * INPUTS: p - surface structure |
|---|
| 538 | * x1,x2,y1,y2 - coordinates |
|---|
| 539 | * c - pixel value |
|---|
| 540 | * OUTPUTS: none |
|---|
| 541 | * RETURNS: none |
|---|
| 542 | * FUNCTION: Fill the rectangle with pixels defined by the value c. |
|---|
| 543 | * |
|---|
| 544 | * JPF - these need to be optimized |
|---|
| 545 | * |
|---|
| 546 | ****************************************************************/ |
|---|
| 547 | /* TODO create optimized version of memset */ |
|---|
| 548 | #if 0 |
|---|
| 549 | static inline void *bgfx_memset(void *dest,int c,size_t count) |
|---|
| 550 | { |
|---|
| 551 | uint8_t *d = dest; |
|---|
| 552 | for(;count>0;count--) { |
|---|
| 553 | *d++ = c; |
|---|
| 554 | } |
|---|
| 555 | return dest; |
|---|
| 556 | } |
|---|
| 557 | #else |
|---|
| 558 | #define bgfx_memset memset |
|---|
| 559 | #endif |
|---|
| 560 | |
|---|
| 561 | void bgfx_fill_rect(bgfx_surf_p p,uint16_t x,uint16_t y,uint16_t w,uint16_t h, |
|---|
| 562 | bgfx_pixel c) |
|---|
| 563 | { |
|---|
| 564 | #if 0 |
|---|
| 565 | bgfx_fill_rect(p->fd,p->psurface[p->surf_idx],x,y,w,h,bgfx_clut8_to_rgb(p->palette.clut,c)); |
|---|
| 566 | #else |
|---|
| 567 | #ifdef CONFIG_BGFX_SURF_RGB |
|---|
| 568 | uint8_t *tdst; |
|---|
| 569 | uint16_t i; |
|---|
| 570 | #endif |
|---|
| 571 | uint8_t *dst; |
|---|
| 572 | uint16_t j; |
|---|
| 573 | |
|---|
| 574 | if (y + h > p->surface.height) |
|---|
| 575 | h = p->surface.height - y; |
|---|
| 576 | |
|---|
| 577 | if (w + x > p->surface.width) |
|---|
| 578 | w = p->surface.width - x; |
|---|
| 579 | |
|---|
| 580 | dst = (uint8_t*)p->surface.buf; |
|---|
| 581 | dst += y * p->surface.pitch + x * p->bpp/8; |
|---|
| 582 | |
|---|
| 583 | #ifdef CONFIG_BGFX_SURF_RGB |
|---|
| 584 | if (p->flags & BGFX_SURF_RGB) |
|---|
| 585 | { |
|---|
| 586 | uint32_t c32 = bgfx_clut8_to_rgb(p->palette.clut,c); |
|---|
| 587 | for (j = 0; j < h; ++j) |
|---|
| 588 | { |
|---|
| 589 | tdst = dst; |
|---|
| 590 | for (i = 0; i < w; ++i) |
|---|
| 591 | { |
|---|
| 592 | *((uint32_t*)tdst) = c32; |
|---|
| 593 | tdst += p->bpp/8; |
|---|
| 594 | } |
|---|
| 595 | dst += p->surface.pitch; |
|---|
| 596 | } |
|---|
| 597 | } |
|---|
| 598 | else |
|---|
| 599 | #endif |
|---|
| 600 | { |
|---|
| 601 | unsigned char two_pixel = (c << 4) | c; |
|---|
| 602 | for (j = 0; j < h; ++j) |
|---|
| 603 | { |
|---|
| 604 | unsigned int num_bytes = (w * p->bpp)/8; |
|---|
| 605 | if (x & 1) |
|---|
| 606 | { |
|---|
| 607 | *dst &= 0xF0; |
|---|
| 608 | *dst |= (c & 0xF); |
|---|
| 609 | if (w & 1) |
|---|
| 610 | { |
|---|
| 611 | bgfx_memset(&dst[1],two_pixel,num_bytes); |
|---|
| 612 | } |
|---|
| 613 | else |
|---|
| 614 | { |
|---|
| 615 | bgfx_memset(&dst[1],two_pixel,num_bytes - 1); |
|---|
| 616 | dst[num_bytes] &= 0x0F; |
|---|
| 617 | dst[num_bytes] |= (c & 0xF) << 4; |
|---|
| 618 | } |
|---|
| 619 | } |
|---|
| 620 | else |
|---|
| 621 | { |
|---|
| 622 | if (w & 1) |
|---|
| 623 | { |
|---|
| 624 | bgfx_memset(dst,two_pixel,num_bytes); |
|---|
| 625 | dst[num_bytes] &= 0x0F; |
|---|
| 626 | dst[num_bytes] |= (c & 0xF) << 4; |
|---|
| 627 | } |
|---|
| 628 | else |
|---|
| 629 | bgfx_memset(dst,two_pixel,num_bytes); |
|---|
| 630 | } |
|---|
| 631 | dst += p->surface.pitch; |
|---|
| 632 | } |
|---|
| 633 | } |
|---|
| 634 | bgfx_cacheflush(p->surface.buf,p->surface.pitch * p->surface.height); |
|---|
| 635 | #endif |
|---|
| 636 | } |
|---|
| 637 | /**************************************************************** |
|---|
| 638 | * bgfx_render_glyph |
|---|
| 639 | * |
|---|
| 640 | * INPUTS: p - surface structure |
|---|
| 641 | * x,y - coordinates |
|---|
| 642 | * a_char - character to render |
|---|
| 643 | * font_p - font definition |
|---|
| 644 | * c - color |
|---|
| 645 | * OUTPUTS: none |
|---|
| 646 | * RETURNS: character advance |
|---|
| 647 | * FUNCTION: Fill the rectangle with pixels defined by the value c. |
|---|
| 648 | * |
|---|
| 649 | ****************************************************************/ |
|---|
| 650 | #define IT_OFFSET 3 |
|---|
| 651 | static inline int bgfx_render_glyph(bgfx_surf_p p,uint16_t x,uint16_t y, |
|---|
| 652 | const unsigned long a_char, bgfx_font_t *font_p,bgfx_pixel c, |
|---|
| 653 | bgfx_glyph_t * p_bgfx_glyph,bgfx_text_style style) |
|---|
| 654 | { |
|---|
| 655 | int max_width,ybase; |
|---|
| 656 | uint16_t row; |
|---|
| 657 | uint8_t *src,*dst; |
|---|
| 658 | bgfx_glyph_t * bgfx_glyph = p_bgfx_glyph; |
|---|
| 659 | unsigned char glyph_width; /* width of the rendered character bitmap in pixels */ |
|---|
| 660 | unsigned char glyph_height; /* height of the rendered character bitmap in pixels */ |
|---|
| 661 | |
|---|
| 662 | ybase = y; |
|---|
| 663 | if (x > p->surface.width) |
|---|
| 664 | { |
|---|
| 665 | SGL_TRACE(("bgfx_render_glyph x > width (%d,%d)\n",x,p->surface.width)); |
|---|
| 666 | return 0; |
|---|
| 667 | } |
|---|
| 668 | |
|---|
| 669 | /* if using glyph cache use the get glyph rather than render directly to surface buffer */ |
|---|
| 670 | if (!bgfx_glyph && (font_p->cache_size > 0)) |
|---|
| 671 | { |
|---|
| 672 | bgfx_glyph = bgfx_get_glyph(font_p,a_char); |
|---|
| 673 | } |
|---|
| 674 | |
|---|
| 675 | if (!bgfx_glyph) |
|---|
| 676 | { |
|---|
| 677 | SGL_DEBUG(("bgfx_render_glyph could not load glyph 0x%08lx\n",a_char)); |
|---|
| 678 | return 0; |
|---|
| 679 | } |
|---|
| 680 | SGL_TRACE(("bgfx_render_glyph glyph (%p,%d,%d)\n",bgfx_glyph->buf,bgfx_glyph->height,bgfx_glyph->width)); |
|---|
| 681 | |
|---|
| 682 | glyph_width = bgfx_glyph->width; |
|---|
| 683 | glyph_height = bgfx_glyph->height; |
|---|
| 684 | |
|---|
| 685 | if (bgfx_glyph->left + x > 0) |
|---|
| 686 | x += bgfx_glyph->left; |
|---|
| 687 | if (y-bgfx_glyph->top > 0) |
|---|
| 688 | y -= bgfx_glyph->top; |
|---|
| 689 | else |
|---|
| 690 | y = 0; |
|---|
| 691 | |
|---|
| 692 | if (glyph_height + y > p->surface.height) |
|---|
| 693 | glyph_height = p->surface.height - y; |
|---|
| 694 | if (glyph_width + x > p->surface.width) |
|---|
| 695 | glyph_width = p->surface.width - x; |
|---|
| 696 | |
|---|
| 697 | src = (uint8_t*)bgfx_glyph->buf; |
|---|
| 698 | dst = (uint8_t*)p->surface.buf; |
|---|
| 699 | |
|---|
| 700 | SGL_TRACE(("bgfx_render_glyph suface (%p(y = %d,x = %d,pitch = %d,bpp = %d)\n",dst,y,x,p->surface.pitch, p->bpp)); |
|---|
| 701 | |
|---|
| 702 | dst += y * p->surface.pitch + x * p->bpp/8; |
|---|
| 703 | if (style & eBGFX_ITALIC) |
|---|
| 704 | max_width = BGFX_MIN(glyph_width + IT_OFFSET, p->surface.width - x); |
|---|
| 705 | else |
|---|
| 706 | max_width = BGFX_MIN(glyph_width, p->surface.width - x); |
|---|
| 707 | |
|---|
| 708 | if (max_width <= 0) |
|---|
| 709 | { |
|---|
| 710 | if (glyph_width != 0) |
|---|
| 711 | { |
|---|
| 712 | SGL_TRACE(("bgfx_render_glyph glyph_width = %d\n", glyph_width)); |
|---|
| 713 | } |
|---|
| 714 | return bgfx_glyph->advance; |
|---|
| 715 | } |
|---|
| 716 | |
|---|
| 717 | /* Render mono glyph */ |
|---|
| 718 | if (font_p->format & SGL_MONO) |
|---|
| 719 | { |
|---|
| 720 | SGL_TRACE(("bgfx_render_glyph Alpha 1 font\n")); |
|---|
| 721 | |
|---|
| 722 | #ifdef CONFIG_BGFX_SURF_RGB |
|---|
| 723 | if (p->flags & BGFX_SURF_RGB) |
|---|
| 724 | { |
|---|
| 725 | uint32_t c32 = bgfx_clut8_to_rgb(p->palette.clut,c); |
|---|
| 726 | for (row = 0; row < glyph_height; row++) |
|---|
| 727 | { |
|---|
| 728 | bgfx_render_a1_to_rgb( src, dst, max_width,c32 ); |
|---|
| 729 | |
|---|
| 730 | src += bgfx_glyph->pitch; |
|---|
| 731 | dst += p->surface.pitch; |
|---|
| 732 | } |
|---|
| 733 | } |
|---|
| 734 | else |
|---|
| 735 | #endif |
|---|
| 736 | { |
|---|
| 737 | uint16_t adjx = x; |
|---|
| 738 | for (row = 0; row < glyph_height; row++) |
|---|
| 739 | { |
|---|
| 740 | if (style & eBGFX_ITALIC) |
|---|
| 741 | { |
|---|
| 742 | adjx = x + IT_OFFSET - ((row * IT_OFFSET)/glyph_height); |
|---|
| 743 | dst = (uint8_t*)p->surface.buf; |
|---|
| 744 | dst += (y + row) * p->surface.pitch + adjx * p->bpp/8; |
|---|
| 745 | } |
|---|
| 746 | bgfx_render_a1_to_clut4( src, dst, max_width,c, adjx & 0x1 ); |
|---|
| 747 | |
|---|
| 748 | src += bgfx_glyph->pitch; |
|---|
| 749 | dst += p->surface.pitch; |
|---|
| 750 | } |
|---|
| 751 | } |
|---|
| 752 | } |
|---|
| 753 | else /* Render 8 bit grayscale glyph */ |
|---|
| 754 | { |
|---|
| 755 | SGL_TRACE(("bgfx_render_glyph Alpha 8 font\n")); |
|---|
| 756 | #ifdef CONFIG_BGFX_SURF_RGB |
|---|
| 757 | if (p->flags & BGFX_SURF_RGB) |
|---|
| 758 | { |
|---|
| 759 | uint32_t c32 = bgfx_clut8_to_rgb(p->palette.clut,c); |
|---|
| 760 | for (row = 0; row < glyph_height; row++) |
|---|
| 761 | { |
|---|
| 762 | bgfx_render_a8_to_rgb( src, dst, glyph_width,c32); |
|---|
| 763 | |
|---|
| 764 | src += bgfx_glyph->pitch; |
|---|
| 765 | dst += p->surface.pitch; |
|---|
| 766 | } |
|---|
| 767 | } |
|---|
| 768 | else |
|---|
| 769 | #endif |
|---|
| 770 | { |
|---|
| 771 | for (row = 0; row < glyph_height; row++) |
|---|
| 772 | { |
|---|
| 773 | bgfx_render_a8_to_clut4( src, dst, glyph_width,c ); |
|---|
| 774 | |
|---|
| 775 | src += bgfx_glyph->pitch; |
|---|
| 776 | dst += p->surface.pitch; |
|---|
| 777 | } |
|---|
| 778 | } |
|---|
| 779 | } |
|---|
| 780 | if (style & eBGFX_UNDERLINE) |
|---|
| 781 | bgfx_h_draw_line(p,x,x + bgfx_glyph->advance,ybase,c); |
|---|
| 782 | return bgfx_glyph->advance; |
|---|
| 783 | } |
|---|
| 784 | |
|---|
| 785 | /**************************************************************** |
|---|
| 786 | * bgfx_draw_text |
|---|
| 787 | * |
|---|
| 788 | * INPUTS: p - surface structure |
|---|
| 789 | * x,y - coordinates |
|---|
| 790 | * str_p - array of 32-bit unicode characters |
|---|
| 791 | str_len - number of 32-bit characters in array |
|---|
| 792 | * font_p - font definition |
|---|
| 793 | * c - color |
|---|
| 794 | * OUTPUTS: none |
|---|
| 795 | * RETURNS: none |
|---|
| 796 | * FUNCTION: Fill the rectangle with pixels defined by the value c. |
|---|
| 797 | * |
|---|
| 798 | ****************************************************************/ |
|---|
| 799 | void bgfx_draw_text(bgfx_surf_p p,uint16_t x,uint16_t y, |
|---|
| 800 | const unsigned long *str_p, int str_len, |
|---|
| 801 | bgfx_font_t *font_p,bgfx_pixel c, bgfx_text_style style) |
|---|
| 802 | { |
|---|
| 803 | int offset; |
|---|
| 804 | |
|---|
| 805 | SGL_TRACE(("bgfx_draw_text %ld characters.\n",str_len)); |
|---|
| 806 | |
|---|
| 807 | for (offset = 0; offset < str_len; offset++) |
|---|
| 808 | { |
|---|
| 809 | x += bgfx_render_glyph(p,x,y, str_p[offset], font_p,c,NULL,style); |
|---|
| 810 | } |
|---|
| 811 | bgfx_cacheflush(p->surface.buf,p->surface.pitch * p->surface.height); |
|---|
| 812 | } |
|---|
| 813 | /**************************************************************** |
|---|
| 814 | * bgfx_draw_text_box |
|---|
| 815 | * |
|---|
| 816 | * INPUTS: p - surface structure |
|---|
| 817 | * x,y - coordinates |
|---|
| 818 | * width,height - width and hegith of the text box to draw |
|---|
| 819 | * str_p - array of 32-bit unicode characters |
|---|
| 820 | str_len - number of 32-bit characters in array |
|---|
| 821 | * font_p - font definition |
|---|
| 822 | * c - color |
|---|
| 823 | line_spacing - line space |
|---|
| 824 | * OUTPUTS: none |
|---|
| 825 | * RETURNS: none |
|---|
| 826 | * FUNCTION: Fill the rectangle with pixels defined by the value c. |
|---|
| 827 | * |
|---|
| 828 | ****************************************************************/ |
|---|
| 829 | #define MAX_TEXT_BOX_CHARS 512 |
|---|
| 830 | #define MAX_LINES 16 |
|---|
| 831 | static unsigned long s_test_char = 0x00000057UL; |
|---|
| 832 | /* TODO: Might want to improve macro to check for chars other than spaces */ |
|---|
| 833 | #define SGL_IS_BREAK(x) ((x == 0x00000020) ? 1 : 0) |
|---|
| 834 | //#define SGL_VARIABL_LINE_HEIGHT |
|---|
| 835 | void bgfx_draw_text_box(bgfx_surf_p p,uint16_t x,uint16_t y, |
|---|
| 836 | uint16_t width, uint16_t height, |
|---|
| 837 | const unsigned long *str_p, int str_len, |
|---|
| 838 | bgfx_font_t *font_p,bgfx_pixel c, |
|---|
| 839 | uint16_t line_spacing) |
|---|
| 840 | { |
|---|
| 841 | int offset,bw_off,line_idx; |
|---|
| 842 | static bgfx_glyph_t * p_bgfx_glyph[MAX_TEXT_BOX_CHARS]; /* Not thread safe */ |
|---|
| 843 | static uint8_t brk_loc[MAX_TEXT_BOX_CHARS]; |
|---|
| 844 | uint16_t max_h[MAX_LINES],ch_w,test_max_h,bot; |
|---|
| 845 | bgfx_glyph_t *p_test_glyph; |
|---|
| 846 | |
|---|
| 847 | SGL_TRACE(("bgfx_draw_text_box(%d,%d,%d,%d,%d) %ld characters.\n",x,y,width,height,line_spacing,str_len)); |
|---|
| 848 | if (str_len > MAX_TEXT_BOX_CHARS) |
|---|
| 849 | { |
|---|
| 850 | SGL_DEBUG(("bgfx_draw_text %d > %d maximum characters.\n",str_len,MAX_TEXT_BOX_CHARS)); |
|---|
| 851 | str_len = MAX_TEXT_BOX_CHARS; |
|---|
| 852 | } |
|---|
| 853 | bot = y + height; |
|---|
| 854 | p_test_glyph = bgfx_get_glyph(font_p,s_test_char); |
|---|
| 855 | if (p_test_glyph) |
|---|
| 856 | test_max_h = p_test_glyph->height; |
|---|
| 857 | else |
|---|
| 858 | test_max_h = 0; |
|---|
| 859 | |
|---|
| 860 | for (line_idx = 0; line_idx < MAX_LINES; ++line_idx) |
|---|
| 861 | max_h[line_idx] = test_max_h; |
|---|
| 862 | |
|---|
| 863 | ch_w = 0; |
|---|
| 864 | line_idx = 0; |
|---|
| 865 | for (offset = 0; offset < str_len; offset++) |
|---|
| 866 | { |
|---|
| 867 | brk_loc[offset] = 0; |
|---|
| 868 | p_bgfx_glyph[offset] = bgfx_get_glyph(font_p,str_p[offset]); |
|---|
| 869 | if (p_bgfx_glyph[offset] == NULL) |
|---|
| 870 | { |
|---|
| 871 | SGL_DEBUG(("%s:%d str[%d] = 0x%08x\n",__FUNCTION__,__LINE__,offset,str_p[offset])); |
|---|
| 872 | /* if not a printable charactor, then use space instead */ |
|---|
| 873 | p_bgfx_glyph[offset] = bgfx_get_glyph(font_p,0x00000020); |
|---|
| 874 | continue; |
|---|
| 875 | } |
|---|
| 876 | ch_w += p_bgfx_glyph[offset]->advance; |
|---|
| 877 | |
|---|
| 878 | if (p_bgfx_glyph[offset]->height > max_h[line_idx]) |
|---|
| 879 | max_h[line_idx] = p_bgfx_glyph[offset]->height; |
|---|
| 880 | |
|---|
| 881 | if (ch_w >= width) |
|---|
| 882 | { |
|---|
| 883 | line_idx++; |
|---|
| 884 | for (bw_off = offset - 1; bw_off >= 0; --bw_off) |
|---|
| 885 | { |
|---|
| 886 | if (brk_loc[bw_off]) { |
|---|
| 887 | bw_off = -1; |
|---|
| 888 | break; |
|---|
| 889 | } |
|---|
| 890 | if (SGL_IS_BREAK(str_p[bw_off])) |
|---|
| 891 | { |
|---|
| 892 | brk_loc[bw_off] = 1; |
|---|
| 893 | break; |
|---|
| 894 | } |
|---|
| 895 | } |
|---|
| 896 | |
|---|
| 897 | /* last resort, break on preceding character */ |
|---|
| 898 | if (bw_off < 0) |
|---|
| 899 | { |
|---|
| 900 | brk_loc[offset - 1] = 1; |
|---|
| 901 | ch_w = p_bgfx_glyph[offset]->advance; |
|---|
| 902 | } |
|---|
| 903 | else |
|---|
| 904 | { |
|---|
| 905 | offset = bw_off; |
|---|
| 906 | ch_w = 0; |
|---|
| 907 | } |
|---|
| 908 | } |
|---|
| 909 | } |
|---|
| 910 | |
|---|
| 911 | /* offset y so text is inside box */ |
|---|
| 912 | line_idx = 0; |
|---|
| 913 | #ifdef SGL_VARIABL_LINE_HEIGHT |
|---|
| 914 | y += max_h[line_idx]; |
|---|
| 915 | #else |
|---|
| 916 | y += test_max_h; |
|---|
| 917 | #endif |
|---|
| 918 | ch_w = 0; |
|---|
| 919 | |
|---|
| 920 | for (offset = 0; (offset < str_len) && (line_idx < MAX_LINES); offset++) |
|---|
| 921 | { |
|---|
| 922 | if (brk_loc[offset]) |
|---|
| 923 | { |
|---|
| 924 | line_idx++; |
|---|
| 925 | ch_w = 0; |
|---|
| 926 | #ifdef SGL_VARIABL_LINE_HEIGHT |
|---|
| 927 | y += line_spacing + max_h[line_idx]; |
|---|
| 928 | if ((y - max_h[line_idx]) > bot) |
|---|
| 929 | break; |
|---|
| 930 | #else |
|---|
| 931 | y += line_spacing + test_max_h; |
|---|
| 932 | if ((y - test_max_h) > bot) |
|---|
| 933 | break; |
|---|
| 934 | #endif |
|---|
| 935 | continue; |
|---|
| 936 | } |
|---|
| 937 | ch_w += bgfx_render_glyph(p,x + ch_w,y, str_p[offset], font_p,c,p_bgfx_glyph[offset],eBGFX_NORMAL); |
|---|
| 938 | } |
|---|
| 939 | bgfx_cacheflush(p->surface.buf,p->surface.pitch * p->surface.height); |
|---|
| 940 | } |
|---|
| 941 | |
|---|
| 942 | /**************************************************************** |
|---|
| 943 | * bgfx_render_file |
|---|
| 944 | * |
|---|
| 945 | * INPUTS: p - surface structure |
|---|
| 946 | * x,y - coordinates |
|---|
| 947 | * file_p - file to get image from |
|---|
| 948 | * set_palette - use the palette in the file to set the |
|---|
| 949 | * global palette. |
|---|
| 950 | * OUTPUTS: none |
|---|
| 951 | * RETURNS: non-zero on error |
|---|
| 952 | * FUNCTION: Render the image in the file to the x,y location |
|---|
| 953 | * |
|---|
| 954 | ****************************************************************/ |
|---|
| 955 | |
|---|
| 956 | int bgfx_render_file(bgfx_surf_p p,uint16_t x,uint16_t y, |
|---|
| 957 | void *file_p,int set_palette) |
|---|
| 958 | { |
|---|
| 959 | bcm_raw_8_t header; |
|---|
| 960 | int result = -1; |
|---|
| 961 | static uint8_t tbuf[SURF_WIDTH]; |
|---|
| 962 | uint16_t row,rows,rowbytes; |
|---|
| 963 | uint8_t *dst_ptr; |
|---|
| 964 | int palette_bytes; |
|---|
| 965 | #ifdef CONFIG_BGFX_SURF_RGB |
|---|
| 966 | uint16_t i; |
|---|
| 967 | uint8_t *r_ptr,*tdst; |
|---|
| 968 | #endif |
|---|
| 969 | |
|---|
| 970 | if (bgfx_read(&header,1,sizeof(header),file_p) == sizeof(header)) |
|---|
| 971 | { |
|---|
| 972 | if (header.type != RAW_TYPE || header.version != RAW_VERSION) |
|---|
| 973 | { |
|---|
| 974 | SGL_DEBUG(("bgfx_render_file failed version,type invalid(0x%08lx,0x%08lx)\n",header.type,header.version)); |
|---|
| 975 | return -1; |
|---|
| 976 | } |
|---|
| 977 | SGL_TRACE(("header.version = 0x%08lx\n",header.version)); |
|---|
| 978 | SGL_TRACE(("header.type = 0x%08lx\n",header.type)); |
|---|
| 979 | SGL_TRACE(("header.clut_size = %d\n",header.clut_size)); |
|---|
| 980 | SGL_TRACE(("header.color_key = 0x%02x\n",header.color_key)); |
|---|
| 981 | SGL_TRACE(("header.pitch = %ld\n",header.pitch)); |
|---|
| 982 | SGL_TRACE(("header.width = 0x%08x\n",header.width)); |
|---|
| 983 | SGL_TRACE(("header.height = 0x%08x\n",header.height)); |
|---|
| 984 | |
|---|
| 985 | palette_bytes = (sizeof(unsigned long) * header.clut_size); |
|---|
| 986 | if (bgfx_read(&p->palette,1,palette_bytes,file_p) == palette_bytes) |
|---|
| 987 | { |
|---|
| 988 | if (set_palette && (header.clut_size == PALETTE_SIZE)) |
|---|
| 989 | bgfx_set_palette(p,&p->palette); |
|---|
| 990 | } |
|---|
| 991 | |
|---|
| 992 | if ((header.width == p->surface.width) && (header.height == p->surface.height) && |
|---|
| 993 | (p->surface.pitch == header.pitch) && (x == 0) && (y == 0) |
|---|
| 994 | && !(p->flags & BGFX_SURF_RGB)) |
|---|
| 995 | { |
|---|
| 996 | SGL_TRACE(("Fast Render\n")); |
|---|
| 997 | bgfx_read(p->surface.buf,1,header.pitch*header.height,file_p); |
|---|
| 998 | } |
|---|
| 999 | else if ((p->palette.clut[header.color_key] & 0xFF000000) != 0) |
|---|
| 1000 | { |
|---|
| 1001 | SGL_TRACE(("Render - no color key\n")); |
|---|
| 1002 | rowbytes = BGFX_MIN(header.width,p->surface.width - x) * p->bpp/8; |
|---|
| 1003 | rows = BGFX_MIN(header.height, p->surface.height - y); |
|---|
| 1004 | |
|---|
| 1005 | dst_ptr = (uint8_t*)p->surface.buf; |
|---|
| 1006 | dst_ptr += y * p->surface.pitch + x * p->bpp/8; |
|---|
| 1007 | |
|---|
| 1008 | #ifdef CONFIG_BGFX_SURF_RGB |
|---|
| 1009 | if (p->flags & BGFX_SURF_RGB) |
|---|
| 1010 | { |
|---|
| 1011 | for (row = 0; row < rows; row++) |
|---|
| 1012 | { |
|---|
| 1013 | bgfx_read(tbuf ,1,rowbytes,file_p); |
|---|
| 1014 | r_ptr = dst_ptr; |
|---|
| 1015 | for (i = 0; i < rowbytes; ++i) |
|---|
| 1016 | { |
|---|
| 1017 | uint32_t sr,sg,sb,sa,dr,dg,db,da,src_c; |
|---|
| 1018 | src_c = bgfx_clut8_to_rgb(p->palette.clut,tbuf[i]); |
|---|
| 1019 | sa = (src_c >> 24) & 0xFF; |
|---|
| 1020 | if (sa == 0xFF) |
|---|
| 1021 | { |
|---|
| 1022 | *((uint32_t*)r_ptr) = src_c; |
|---|
| 1023 | } |
|---|
| 1024 | else |
|---|
| 1025 | { |
|---|
| 1026 | sr = (src_c >> 16) & 0xFF; |
|---|
| 1027 | sg = (src_c >> 8) & 0xFF; |
|---|
| 1028 | sb = (src_c >> 0) & 0xFF; |
|---|
| 1029 | da = (*((uint32_t*)r_ptr) >> 24) & 0xFF; |
|---|
| 1030 | dr = (*((uint32_t*)r_ptr) >> 16) & 0xFF; |
|---|
| 1031 | dg = (*((uint32_t*)r_ptr) >> 8) & 0xFF; |
|---|
| 1032 | db = (*((uint32_t*)r_ptr) >> 0) & 0xFF; |
|---|
| 1033 | |
|---|
| 1034 | dr = (((sr * sa)/0xFF) & 0xFF) + ((((0xFF - sa) * dr)/0xFF) & 0xFF); |
|---|
| 1035 | dg = (((sg * sa)/0xFF) & 0xFF) + ((((0xFF - sa) * dg)/0xFF) & 0xFF); |
|---|
| 1036 | db = (((sb * sa)/0xFF) & 0xFF) + ((((0xFF - sa) * db)/0xFF) & 0xFF); |
|---|
| 1037 | |
|---|
| 1038 | *((uint32_t*)r_ptr) = (da << 24) | (dr << 16) | (dg << 8) | db; |
|---|
| 1039 | } |
|---|
| 1040 | r_ptr += p->bpp/8; |
|---|
| 1041 | } |
|---|
| 1042 | |
|---|
| 1043 | if (header.pitch > rowbytes) |
|---|
| 1044 | { |
|---|
| 1045 | bgfx_read(tbuf ,1,header.pitch - rowbytes,file_p); |
|---|
| 1046 | } |
|---|
| 1047 | dst_ptr += p->surface.pitch; |
|---|
| 1048 | } |
|---|
| 1049 | } |
|---|
| 1050 | else |
|---|
| 1051 | #endif |
|---|
| 1052 | { |
|---|
| 1053 | for (row = 0; row < rows; row++) |
|---|
| 1054 | { |
|---|
| 1055 | bgfx_read(dst_ptr ,1,rowbytes,file_p); |
|---|
| 1056 | if (header.pitch > rowbytes) |
|---|
| 1057 | { |
|---|
| 1058 | bgfx_read(tbuf ,1,header.pitch - rowbytes,file_p); |
|---|
| 1059 | } |
|---|
| 1060 | dst_ptr += p->surface.pitch; |
|---|
| 1061 | } |
|---|
| 1062 | } |
|---|
| 1063 | } |
|---|
| 1064 | else |
|---|
| 1065 | { |
|---|
| 1066 | SGL_TRACE(("Render - color key\n")); |
|---|
| 1067 | rowbytes = BGFX_MIN(header.width,(p->surface.width - x)) * p->bpp/8; |
|---|
| 1068 | rows = BGFX_MIN(header.height, (p->surface.height - y)); |
|---|
| 1069 | dst_ptr = (uint8_t*)p->surface.buf; |
|---|
| 1070 | dst_ptr += y * p->surface.pitch + x * p->bpp/8; |
|---|
| 1071 | |
|---|
| 1072 | #ifdef CONFIG_BGFX_SURF_RGB |
|---|
| 1073 | if (p->flags & BGFX_SURF_RGB) |
|---|
| 1074 | { |
|---|
| 1075 | for (row = 0; row < rows; row++) |
|---|
| 1076 | { |
|---|
| 1077 | bgfx_read(tbuf ,1,rowbytes,file_p); |
|---|
| 1078 | r_ptr = dst_ptr; |
|---|
| 1079 | for (i = 0; i < rowbytes; ++i) |
|---|
| 1080 | { |
|---|
| 1081 | if (tbuf[i] != header.color_key) |
|---|
| 1082 | { |
|---|
| 1083 | uint32_t sr,sg,sb,sa,dr,dg,db,da,src_c; |
|---|
| 1084 | src_c = bgfx_clut8_to_rgb(p->palette.clut,tbuf[i]); |
|---|
| 1085 | sa = (src_c >> 24) & 0xFF; |
|---|
| 1086 | if (sa == 0xFF) |
|---|
| 1087 | { |
|---|
| 1088 | *((uint32_t*)r_ptr) = src_c; |
|---|
| 1089 | } |
|---|
| 1090 | else |
|---|
| 1091 | { |
|---|
| 1092 | sr = (src_c >> 16) & 0xFF; |
|---|
| 1093 | sg = (src_c >> 8) & 0xFF; |
|---|
| 1094 | sb = (src_c >> 0) & 0xFF; |
|---|
| 1095 | da = (*((uint32_t*)r_ptr) >> 24) & 0xFF; |
|---|
| 1096 | dr = (*((uint32_t*)r_ptr) >> 16) & 0xFF; |
|---|
| 1097 | dg = (*((uint32_t*)r_ptr) >> 8) & 0xFF; |
|---|
| 1098 | db = (*((uint32_t*)r_ptr) >> 0) & 0xFF; |
|---|
| 1099 | |
|---|
| 1100 | dr = (((sr * sa)/0xFF) & 0xFF) + ((((0xFF - sa) * dr)/0xFF) & 0xFF); |
|---|
| 1101 | dg = (((sg * sa)/0xFF) & 0xFF) + ((((0xFF - sa) * dg)/0xFF) & 0xFF); |
|---|
| 1102 | db = (((sb * sa)/0xFF) & 0xFF) + ((((0xFF - sa) * db)/0xFF) & 0xFF); |
|---|
| 1103 | *((uint32_t*)r_ptr) = (da << 24) | (dr << 16) | (dg << 8) | db; |
|---|
| 1104 | } |
|---|
| 1105 | } |
|---|
| 1106 | r_ptr += p->bpp/8; |
|---|
| 1107 | } |
|---|
| 1108 | if (header.pitch > rowbytes) |
|---|
| 1109 | { |
|---|
| 1110 | bgfx_read(tbuf ,1,header.pitch - rowbytes,file_p); |
|---|
| 1111 | } |
|---|
| 1112 | dst_ptr += p->surface.pitch; |
|---|
| 1113 | } |
|---|
| 1114 | } |
|---|
| 1115 | else |
|---|
| 1116 | #endif |
|---|
| 1117 | { |
|---|
| 1118 | for (row = 0; row < rows; row++) |
|---|
| 1119 | { |
|---|
| 1120 | bgfx_read(dst_ptr ,1,rowbytes,file_p); |
|---|
| 1121 | if (header.pitch > rowbytes) |
|---|
| 1122 | { |
|---|
| 1123 | bgfx_read(tbuf ,1,header.pitch - rowbytes,file_p); |
|---|
| 1124 | } |
|---|
| 1125 | dst_ptr += p->surface.pitch; |
|---|
| 1126 | } |
|---|
| 1127 | } |
|---|
| 1128 | } |
|---|
| 1129 | } |
|---|
| 1130 | SGL_TRACE(("Render - done\n")); |
|---|
| 1131 | bgfx_cacheflush(p->surface.buf,p->surface.pitch * p->surface.height); |
|---|
| 1132 | result = 0; |
|---|
| 1133 | return result; |
|---|
| 1134 | } |
|---|
| 1135 | |
|---|
| 1136 | /**************************************************************** |
|---|
| 1137 | * bgfx_blit |
|---|
| 1138 | * |
|---|
| 1139 | * INPUTS: p_src,p_dst - surface structure |
|---|
| 1140 | * x,y - destination coordinates |
|---|
| 1141 | * OUTPUTS: none |
|---|
| 1142 | * RETURNS: non-zero on error |
|---|
| 1143 | * FUNCTION: Blit between the two surfaces, only the destination can be RGB |
|---|
| 1144 | * |
|---|
| 1145 | ****************************************************************/ |
|---|
| 1146 | |
|---|
| 1147 | int bgfx_blit(bgfx_surf_p p_src, bgfx_surf_p p_dst, uint16_t x,uint16_t y) |
|---|
| 1148 | { |
|---|
| 1149 | uint8_t *dst,*src; |
|---|
| 1150 | uint16_t j,w,h,rowbytes; |
|---|
| 1151 | #ifdef CONFIG_BGFX_SURF_RGB |
|---|
| 1152 | uint16_t i; |
|---|
| 1153 | uint8_t *tdst; |
|---|
| 1154 | #endif |
|---|
| 1155 | |
|---|
| 1156 | SGL_TRACE(("bgfx_blit x,y (%d,%d)\n",x,y)); |
|---|
| 1157 | |
|---|
| 1158 | if ((x > p_dst->surface.width) || (y > p_dst->surface.height)) |
|---|
| 1159 | { |
|---|
| 1160 | SGL_DEBUG(("bgfx_blit x,y (%d,%d) outside destination (%d,%d)\n",x,y, |
|---|
| 1161 | p_dst->surface.width,p_dst->surface.height)); |
|---|
| 1162 | return -1; |
|---|
| 1163 | } |
|---|
| 1164 | |
|---|
| 1165 | w = p_src->surface.width; |
|---|
| 1166 | if (w > p_dst->surface.width - x) |
|---|
| 1167 | w = p_dst->surface.width - x; |
|---|
| 1168 | h = p_src->surface.height; |
|---|
| 1169 | if (h > p_dst->surface.height - y) |
|---|
| 1170 | h = p_dst->surface.height - y; |
|---|
| 1171 | |
|---|
| 1172 | src = (uint8_t*)p_src->surface.buf; |
|---|
| 1173 | dst = (uint8_t*)p_dst->surface.buf; |
|---|
| 1174 | dst += y * p_dst->surface.pitch + x * p_dst->bpp/8; |
|---|
| 1175 | |
|---|
| 1176 | #ifdef CONFIG_BGFX_SURF_RGB |
|---|
| 1177 | if (p_dst->flags & BGFX_SURF_RGB) |
|---|
| 1178 | { |
|---|
| 1179 | for (j = 0; j < h; ++j) |
|---|
| 1180 | { |
|---|
| 1181 | tdst = dst; |
|---|
| 1182 | for (i = 0; i < w; ++i) |
|---|
| 1183 | { |
|---|
| 1184 | if (src[i] != 0xFF) |
|---|
| 1185 | *((uint32_t*)tdst) = bgfx_clut8_to_rgb(p_src->palette.clut,src[i]); |
|---|
| 1186 | tdst += p_dst->bpp/8; |
|---|
| 1187 | } |
|---|
| 1188 | dst += p_dst->surface.pitch; |
|---|
| 1189 | src += p_src->surface.pitch; |
|---|
| 1190 | } |
|---|
| 1191 | } |
|---|
| 1192 | else |
|---|
| 1193 | #endif |
|---|
| 1194 | { |
|---|
| 1195 | rowbytes = BGFX_MIN(p_src->surface.width,p_dst->surface.width - x) * p_dst->bpp/8; |
|---|
| 1196 | for (j = 0; j < h; ++j) |
|---|
| 1197 | { |
|---|
| 1198 | memcpy(dst,src,rowbytes); |
|---|
| 1199 | dst += p_dst->surface.pitch; |
|---|
| 1200 | src += p_src->surface.pitch; |
|---|
| 1201 | } |
|---|
| 1202 | } |
|---|
| 1203 | bgfx_cacheflush(p_dst->surface.buf,p_dst->surface.pitch * p_dst->surface.height); |
|---|
| 1204 | return 0; |
|---|
| 1205 | } |
|---|
| 1206 | /**************************************************************** |
|---|
| 1207 | * INPUTS: p_src,p_dst - source and destination buffer pointers |
|---|
| 1208 | * sx |
|---|
| 1209 | * dx |
|---|
| 1210 | * w - width |
|---|
| 1211 | * OUTPUTS: none |
|---|
| 1212 | * RETURNS: non-zero on error |
|---|
| 1213 | * FUNCTION: Blit a region of one surface to another (for 4 bpp ) |
|---|
| 1214 | * |
|---|
| 1215 | ****************************************************************/ |
|---|
| 1216 | |
|---|
| 1217 | static inline void bgfx_row_copy(unsigned char *src, unsigned char *dst, |
|---|
| 1218 | uint16_t sx,uint16_t dx,uint16_t w) |
|---|
| 1219 | { |
|---|
| 1220 | unsigned int num_bytes = (w * 4)/8; |
|---|
| 1221 | int pix; |
|---|
| 1222 | |
|---|
| 1223 | if (sx & 1) |
|---|
| 1224 | { |
|---|
| 1225 | if (dx & 1) |
|---|
| 1226 | { |
|---|
| 1227 | *dst &= 0xF0; |
|---|
| 1228 | *dst |= (*src & 0xF); |
|---|
| 1229 | if (w & 1) |
|---|
| 1230 | { |
|---|
| 1231 | memcpy(&dst[1],&src[1],num_bytes); |
|---|
| 1232 | } |
|---|
| 1233 | else |
|---|
| 1234 | { |
|---|
| 1235 | memcpy(&dst[1],&src[1],num_bytes - 1); |
|---|
| 1236 | dst[num_bytes] &= 0x0F; |
|---|
| 1237 | dst[num_bytes] |= (src[num_bytes] & 0xF0); |
|---|
| 1238 | } |
|---|
| 1239 | } |
|---|
| 1240 | else |
|---|
| 1241 | { |
|---|
| 1242 | for (pix = 0; pix < w; ++pix) |
|---|
| 1243 | { |
|---|
| 1244 | if (pix & 1) |
|---|
| 1245 | { |
|---|
| 1246 | *dst &= 0xF0; |
|---|
| 1247 | *dst |= (*src & 0xF0) >> 4; |
|---|
| 1248 | dst++; |
|---|
| 1249 | } |
|---|
| 1250 | else |
|---|
| 1251 | { |
|---|
| 1252 | *dst &= 0x0F; |
|---|
| 1253 | *dst |= (*src & 0xF) << 4; |
|---|
| 1254 | src++; |
|---|
| 1255 | } |
|---|
| 1256 | } |
|---|
| 1257 | } |
|---|
| 1258 | } |
|---|
| 1259 | else |
|---|
| 1260 | { |
|---|
| 1261 | if (dx & 1) |
|---|
| 1262 | { |
|---|
| 1263 | for (pix = 0; pix < w; ++pix) |
|---|
| 1264 | { |
|---|
| 1265 | if (pix & 1) |
|---|
| 1266 | { |
|---|
| 1267 | *dst &= 0x0F; |
|---|
| 1268 | *dst |= (*src & 0xF) << 4; |
|---|
| 1269 | src++; |
|---|
| 1270 | } |
|---|
| 1271 | else |
|---|
| 1272 | { |
|---|
| 1273 | *dst &= 0xF0; |
|---|
| 1274 | *dst |= (*src & 0xF0) >> 4; |
|---|
| 1275 | dst++; |
|---|
| 1276 | } |
|---|
| 1277 | } |
|---|
| 1278 | } |
|---|
| 1279 | else |
|---|
| 1280 | { |
|---|
| 1281 | if (w & 1) |
|---|
| 1282 | { |
|---|
| 1283 | memcpy(dst,src,num_bytes); |
|---|
| 1284 | dst[num_bytes] &= 0x0F; |
|---|
| 1285 | dst[num_bytes] |= (src[num_bytes] & 0xF0); |
|---|
| 1286 | } |
|---|
| 1287 | else |
|---|
| 1288 | { |
|---|
| 1289 | memcpy(dst,src,num_bytes); |
|---|
| 1290 | } |
|---|
| 1291 | } |
|---|
| 1292 | } |
|---|
| 1293 | } |
|---|
| 1294 | /**************************************************************** |
|---|
| 1295 | * INPUTS: p_src,p_dst - source and destination surface structures |
|---|
| 1296 | * sx,sy - source coordinates |
|---|
| 1297 | * dx,dy - destination coordinates |
|---|
| 1298 | * sw,sh - width and height of region |
|---|
| 1299 | * OUTPUTS: none |
|---|
| 1300 | * RETURNS: non-zero on error |
|---|
| 1301 | * FUNCTION: Blit a region of one surface to another |
|---|
| 1302 | * |
|---|
| 1303 | ****************************************************************/ |
|---|
| 1304 | |
|---|
| 1305 | int bgfx_blit_rect(bgfx_surf_p p_src, bgfx_surf_p p_dst, |
|---|
| 1306 | uint16_t sx,uint16_t sy, uint16_t dx,uint16_t dy, |
|---|
| 1307 | uint16_t sw,uint16_t sh) |
|---|
| 1308 | { |
|---|
| 1309 | uint8_t *dst,*src; |
|---|
| 1310 | uint16_t j,w,h; |
|---|
| 1311 | #ifdef CONFIG_BGFX_SURF_RGB |
|---|
| 1312 | uint8_t *tdst; |
|---|
| 1313 | #endif |
|---|
| 1314 | |
|---|
| 1315 | |
|---|
| 1316 | if ((dx >= p_dst->surface.width) || (dy >= p_dst->surface.height)) |
|---|
| 1317 | { |
|---|
| 1318 | SGL_DEBUG(("bgfx_blit_rect dst_x,dst_y (%d,%d) outside destination (%d,%d)\n",dx,dy, |
|---|
| 1319 | p_dst->surface.width,p_dst->surface.height)); |
|---|
| 1320 | return -1; |
|---|
| 1321 | } |
|---|
| 1322 | |
|---|
| 1323 | if ((sx >= p_src->surface.width) || (sy >= p_src->surface.height)) |
|---|
| 1324 | { |
|---|
| 1325 | SGL_DEBUG(("bgfx_blit_rect src_x,src_y (%d,%d) outside source (%d,%d)\n",sx,sy, |
|---|
| 1326 | p_src->surface.width,p_src->surface.height)); |
|---|
| 1327 | return -1; |
|---|
| 1328 | } |
|---|
| 1329 | |
|---|
| 1330 | src = (uint8_t*)p_src->surface.buf; |
|---|
| 1331 | src += (sy * p_src->surface.pitch) + ((sx * p_src->bpp)/8); |
|---|
| 1332 | dst = (uint8_t*)p_dst->surface.buf; |
|---|
| 1333 | dst += (dy * p_dst->surface.pitch) + ((dx * p_dst->bpp)/8); |
|---|
| 1334 | |
|---|
| 1335 | w = sw; |
|---|
| 1336 | |
|---|
| 1337 | if (sw >= (p_src->surface.width - sx)) |
|---|
| 1338 | w= p_src->surface.width - sx; |
|---|
| 1339 | |
|---|
| 1340 | if (w >= p_dst->surface.width - dx) |
|---|
| 1341 | w = p_dst->surface.width - dx; |
|---|
| 1342 | |
|---|
| 1343 | h = sh; |
|---|
| 1344 | |
|---|
| 1345 | if (sh >= (p_src->surface.height - sy)) |
|---|
| 1346 | h= p_src->surface.height - sy; |
|---|
| 1347 | |
|---|
| 1348 | if (h >= p_dst->surface.height - dy) |
|---|
| 1349 | h = p_dst->surface.height - dy; |
|---|
| 1350 | |
|---|
| 1351 | |
|---|
| 1352 | #ifdef CONFIG_BGFX_SURF_RGB |
|---|
| 1353 | if (p_dst->flags & BGFX_SURF_RGB) |
|---|
| 1354 | { |
|---|
| 1355 | for (j = 0; j < h; ++j) |
|---|
| 1356 | { |
|---|
| 1357 | tdst = dst; |
|---|
| 1358 | for (i = 0; i < w; ++i) |
|---|
| 1359 | { |
|---|
| 1360 | if (src[i] != 0xFF) |
|---|
| 1361 | *((uint32_t*)tdst) = bgfx_clut8_to_rgb(p_src->palette.clut,src[i]); |
|---|
| 1362 | tdst += p_dst->bpp/8; |
|---|
| 1363 | } |
|---|
| 1364 | dst += p_dst->surface.pitch; |
|---|
| 1365 | src += p_src->surface.pitch; |
|---|
| 1366 | } |
|---|
| 1367 | } |
|---|
| 1368 | else |
|---|
| 1369 | #endif |
|---|
| 1370 | { |
|---|
| 1371 | for (j = 0; j < h; ++j) |
|---|
| 1372 | { |
|---|
| 1373 | bgfx_row_copy(src,dst,sx,dx,w); |
|---|
| 1374 | |
|---|
| 1375 | dst += p_dst->surface.pitch; |
|---|
| 1376 | src += p_src->surface.pitch; |
|---|
| 1377 | } |
|---|
| 1378 | } |
|---|
| 1379 | bgfx_cacheflush(p_dst->surface.buf,p_dst->surface.pitch * p_dst->surface.height); |
|---|
| 1380 | return 0; |
|---|
| 1381 | } |
|---|