| 1 | |
|---|
| 2 | #include "DHL_OSAL.h" |
|---|
| 3 | #include "DHL_Graphic.h" |
|---|
| 4 | |
|---|
| 5 | //#include <string.h> |
|---|
| 6 | //#include <string.h> |
|---|
| 7 | |
|---|
| 8 | #include "BMF.h" |
|---|
| 9 | |
|---|
| 10 | #include "DMG_Util.h" |
|---|
| 11 | |
|---|
| 12 | //#include "font_img_18.h" |
|---|
| 13 | //#include "font_img_20.h" |
|---|
| 14 | //#include "font_img_22.h" |
|---|
| 15 | |
|---|
| 16 | #include "osd_font_13.h" |
|---|
| 17 | //#include "osd_font_16.h" |
|---|
| 18 | #include "osd_font_18.h" |
|---|
| 19 | #include "osd_font_20.h" |
|---|
| 20 | #include "osd_font_22.h" |
|---|
| 21 | #include "osd_font_23.h" |
|---|
| 22 | #include "osd_font_24.h" |
|---|
| 23 | //#include "osd_font_26.h" |
|---|
| 24 | #include "osd_font_36.h" |
|---|
| 25 | #include "osd_font_47.h" |
|---|
| 26 | |
|---|
| 27 | |
|---|
| 28 | static struct { |
|---|
| 29 | UINT8 style; |
|---|
| 30 | UINT8 fsize; |
|---|
| 31 | UINT8 depth; |
|---|
| 32 | UINT8 *pdata; |
|---|
| 33 | int len; |
|---|
| 34 | int num_ch; |
|---|
| 35 | } p_font_array[]={ |
|---|
| 36 | {BMF_STYLE1, 13, OSD_FONT_DEPTH_13, p_osd_font_13, sizeof(p_osd_font_13), NUM_OSD_FONT_13}, |
|---|
| 37 | {BMF_STYLE1, 18, OSD_FONT_DEPTH_18, p_osd_font_18, sizeof(p_osd_font_18), NUM_OSD_FONT_18}, |
|---|
| 38 | {BMF_STYLE1, 20, OSD_FONT_DEPTH_20, p_osd_font_20, sizeof(p_osd_font_20), NUM_OSD_FONT_20}, |
|---|
| 39 | {BMF_STYLE1, 22, OSD_FONT_DEPTH_22, p_osd_font_22, sizeof(p_osd_font_22), NUM_OSD_FONT_22}, |
|---|
| 40 | {BMF_STYLE1, 23, OSD_FONT_DEPTH_23, p_osd_font_23, sizeof(p_osd_font_23), NUM_OSD_FONT_23}, |
|---|
| 41 | {BMF_STYLE1, 24, OSD_FONT_DEPTH_24, p_osd_font_24, sizeof(p_osd_font_24), NUM_OSD_FONT_24}, |
|---|
| 42 | // {BMF_STYLE1, 26, OSD_FONT_DEPTH_26, p_osd_font_26, sizeof(p_osd_font_26), NUM_OSD_FONT_26}, |
|---|
| 43 | {BMF_STYLE1, 36, OSD_FONT_DEPTH_36, p_osd_font_36, sizeof(p_osd_font_36), NUM_OSD_FONT_36}, |
|---|
| 44 | {BMF_STYLE1, 47, OSD_FONT_DEPTH_47, p_osd_font_47, sizeof(p_osd_font_47), NUM_OSD_FONT_47}, |
|---|
| 45 | }; |
|---|
| 46 | |
|---|
| 47 | #define NUM_FONT (sizeof(p_font_array)/sizeof(p_font_array[0])) |
|---|
| 48 | |
|---|
| 49 | static int p_idx_table[NUM_FONT][0x1000]; |
|---|
| 50 | |
|---|
| 51 | static BOOL p_is_idx_created=FALSE; |
|---|
| 52 | |
|---|
| 53 | #define IMAGE_TYPE_NULL_GLYPH 0x0020 //0x0041('A')->0x0020(' ') |
|---|
| 54 | |
|---|
| 55 | #define CALI_X 8 |
|---|
| 56 | #define CALI_Y 8 |
|---|
| 57 | |
|---|
| 58 | #if 0 |
|---|
| 59 | __Local_Var__() |
|---|
| 60 | #endif |
|---|
| 61 | |
|---|
| 62 | |
|---|
| 63 | #if 0 |
|---|
| 64 | ___APIs_For_CC___() {} |
|---|
| 65 | /* CC¸¦ À§ÇÑ Èû¼öµé */ |
|---|
| 66 | #endif |
|---|
| 67 | |
|---|
| 68 | |
|---|
| 69 | |
|---|
| 70 | |
|---|
| 71 | void BMF_InitFontManager(void *fn_m, void *fn_f, int a, int b, int c, int d) |
|---|
| 72 | { |
|---|
| 73 | /* ÇØÁÙ °Í ¾øÀ½ */ |
|---|
| 74 | |
|---|
| 75 | |
|---|
| 76 | } |
|---|
| 77 | |
|---|
| 78 | void BMF_InitFontContext(BMF_FC *fc, int a, int b) |
|---|
| 79 | { |
|---|
| 80 | /* TODO : ÃʱâÈ */ |
|---|
| 81 | int i,j; |
|---|
| 82 | |
|---|
| 83 | if(p_is_idx_created) return; |
|---|
| 84 | |
|---|
| 85 | if(!fc) return; |
|---|
| 86 | |
|---|
| 87 | for(j=0; j<NUM_FONT; j++) { |
|---|
| 88 | UINT8 *array=p_font_array[j].pdata; |
|---|
| 89 | int size=p_font_array[j].len; |
|---|
| 90 | |
|---|
| 91 | for(i=0; i<0x1000; i++) |
|---|
| 92 | p_idx_table[j][i]=-1; |
|---|
| 93 | |
|---|
| 94 | for(i=0; i<size;) { |
|---|
| 95 | int code=(array[i]<<8) | array[i+1]; |
|---|
| 96 | int pitch=(array[i+2]>>2); |
|---|
| 97 | int height=((array[i+2]&0x3)<<4) | (array[i+3]>>4); |
|---|
| 98 | |
|---|
| 99 | if(p_font_array[j].depth==1) { |
|---|
| 100 | if(pitch==0) pitch=0; |
|---|
| 101 | else pitch=((pitch-1)/16)*2+2; |
|---|
| 102 | } |
|---|
| 103 | else if(p_font_array[j].depth==4) { |
|---|
| 104 | if(pitch==0) pitch=0; |
|---|
| 105 | else pitch=((pitch-1)/4)*2+2; |
|---|
| 106 | } |
|---|
| 107 | |
|---|
| 108 | if(p_idx_table[j][code>>4]==-1) { |
|---|
| 109 | p_idx_table[j][code>>4]=i; |
|---|
| 110 | } |
|---|
| 111 | |
|---|
| 112 | i+=5+pitch*height; |
|---|
| 113 | } |
|---|
| 114 | } |
|---|
| 115 | p_is_idx_created=TRUE; |
|---|
| 116 | } |
|---|
| 117 | |
|---|
| 118 | |
|---|
| 119 | void BMF_TermFontManager() |
|---|
| 120 | { |
|---|
| 121 | /* ÇØÁÙ °Í ¾øÀ½ */ |
|---|
| 122 | } |
|---|
| 123 | |
|---|
| 124 | void BMF_AddFont(UINT8 *pdta) |
|---|
| 125 | { |
|---|
| 126 | /* ÇØÁÙ °Í ¾øÀ½ */ |
|---|
| 127 | |
|---|
| 128 | } |
|---|
| 129 | |
|---|
| 130 | |
|---|
| 131 | void BMF_SetFont(BMF_FC *fc, int style) |
|---|
| 132 | { |
|---|
| 133 | /* ÇØÁÙ °Í ¾øÀ½ */ |
|---|
| 134 | if(!fc) return; |
|---|
| 135 | |
|---|
| 136 | if(style<BMF_STYLE0) style=BMF_STYLE0; |
|---|
| 137 | if(style>BMF_STYLE1) style=BMF_STYLE1; |
|---|
| 138 | |
|---|
| 139 | fc->font_style=style; |
|---|
| 140 | |
|---|
| 141 | } |
|---|
| 142 | |
|---|
| 143 | void BMF_SetSize(BMF_FC *fc, int width, int height) |
|---|
| 144 | { |
|---|
| 145 | if(!fc) return; |
|---|
| 146 | |
|---|
| 147 | fc->xSize=width; |
|---|
| 148 | fc->ySize=height; |
|---|
| 149 | } |
|---|
| 150 | |
|---|
| 151 | void BMF_SetItalic(BMF_FC *fc, BOOL bSet) |
|---|
| 152 | { |
|---|
| 153 | /* TODO */ |
|---|
| 154 | fc->bItalic=bSet; |
|---|
| 155 | } |
|---|
| 156 | |
|---|
| 157 | void BMF_SetBold(BMF_FC *fc, BOOL bSet) |
|---|
| 158 | { |
|---|
| 159 | /* TODO */ |
|---|
| 160 | fc->bBold=bSet; |
|---|
| 161 | } |
|---|
| 162 | |
|---|
| 163 | void BMF_SetEdgeType(BMF_FC *fc, int type) |
|---|
| 164 | { |
|---|
| 165 | /* TODO */ |
|---|
| 166 | } |
|---|
| 167 | |
|---|
| 168 | void BMF_SetRasterType(BMF_FC *fc, int raster) |
|---|
| 169 | { |
|---|
| 170 | /* ÇØÁÙ °Í ¾øÀ½ */ |
|---|
| 171 | } |
|---|
| 172 | |
|---|
| 173 | |
|---|
| 174 | #define USE_SMOOTH_ITALIC 1 |
|---|
| 175 | |
|---|
| 176 | |
|---|
| 177 | |
|---|
| 178 | |
|---|
| 179 | BMF_BOOL BMF_GetCharImage(BMF_FC *fc, BMF_CODE code, BMF_IMAGE *image) |
|---|
| 180 | { |
|---|
| 181 | UINT8 *array, *data_array; |
|---|
| 182 | int *idx_table; |
|---|
| 183 | int i, idx; |
|---|
| 184 | |
|---|
| 185 | UINT16 fcode; |
|---|
| 186 | int fx, fy, fw, fh, pitch; |
|---|
| 187 | int pi, pj; |
|---|
| 188 | int depth; /* 1, 4, 8 bit supported */ |
|---|
| 189 | |
|---|
| 190 | static UINT8 imageBuf[1024], tempBuf[1024]; |
|---|
| 191 | |
|---|
| 192 | if(!fc) goto label_failed; |
|---|
| 193 | |
|---|
| 194 | if(!p_is_idx_created) { |
|---|
| 195 | BMF_InitFontContext(fc,0,0); |
|---|
| 196 | } |
|---|
| 197 | |
|---|
| 198 | for(i=0, idx=-1; i<NUM_FONT; i++) { |
|---|
| 199 | if(fc->font_style!=p_font_array[i].style) continue; |
|---|
| 200 | |
|---|
| 201 | if(p_font_array[i].fsize>=fc->ySize) { |
|---|
| 202 | idx=i; |
|---|
| 203 | break; |
|---|
| 204 | } |
|---|
| 205 | } |
|---|
| 206 | |
|---|
| 207 | if(idx==-1) { /* ÇØ´ç font styleÀÌ ¾øÀ¸¸é ºñ½ÁÇÑ size¸¦ ¼±ÅÃÇÔ */ |
|---|
| 208 | for(i=0; i<NUM_FONT; i++) { |
|---|
| 209 | if(p_font_array[i].fsize>=fc->ySize) { |
|---|
| 210 | idx=i; |
|---|
| 211 | break; |
|---|
| 212 | } |
|---|
| 213 | } |
|---|
| 214 | } |
|---|
| 215 | |
|---|
| 216 | if(idx==-1) idx=0; /* ºñ½ÁÇÑ sizeµµ ¾øÀ¸¸é ù ¹øÂ° */ |
|---|
| 217 | |
|---|
| 218 | array=p_font_array[idx].pdata; |
|---|
| 219 | idx_table=p_idx_table[idx]; |
|---|
| 220 | depth=p_font_array[idx].depth; |
|---|
| 221 | |
|---|
| 222 | if(idx_table[code>>4]==(UINT16)-1) goto label_failed; |
|---|
| 223 | |
|---|
| 224 | for(i=idx_table[code>>4];;) |
|---|
| 225 | { |
|---|
| 226 | fcode=(array[i]<<8) | array[i+1]; |
|---|
| 227 | |
|---|
| 228 | if(fcode<code) { |
|---|
| 229 | fw=array[i+2]>>2; |
|---|
| 230 | fh=((array[i+2]&0x3)<<4) | (array[i+3]>>4); |
|---|
| 231 | |
|---|
| 232 | if(depth==1) { |
|---|
| 233 | if(fw==0) pitch=0; |
|---|
| 234 | else pitch=((fw-1)/16)*2+2; |
|---|
| 235 | } |
|---|
| 236 | else if(depth==4) { |
|---|
| 237 | if(fw==0) pitch=0; |
|---|
| 238 | else pitch=((fw-1)/4)*2+2; |
|---|
| 239 | } |
|---|
| 240 | else { |
|---|
| 241 | pitch=fw; |
|---|
| 242 | } |
|---|
| 243 | |
|---|
| 244 | i+=5+pitch*fh; |
|---|
| 245 | continue; |
|---|
| 246 | } |
|---|
| 247 | else if(fcode>code) goto label_failed; |
|---|
| 248 | |
|---|
| 249 | fx=((array[i+3]&0xf)<<2) | (array[i+4]>>6); |
|---|
| 250 | fy=array[i+4]&0x3f; |
|---|
| 251 | |
|---|
| 252 | fx-=CALI_X; |
|---|
| 253 | fy-=CALI_Y; |
|---|
| 254 | |
|---|
| 255 | fw=array[i+2]>>2; |
|---|
| 256 | fh=((array[i+2]&0x3)<<4) | (array[i+3]>>4); |
|---|
| 257 | |
|---|
| 258 | i+=5; |
|---|
| 259 | |
|---|
| 260 | if(depth==1) { |
|---|
| 261 | if(fw==0) pitch=0; |
|---|
| 262 | else pitch=((fw-1)/16)*2+2; |
|---|
| 263 | } |
|---|
| 264 | else if(depth==4) { |
|---|
| 265 | if(fw==0) pitch=0; |
|---|
| 266 | else pitch=((fw-1)/4)*2+2; |
|---|
| 267 | } |
|---|
| 268 | else { |
|---|
| 269 | pitch=fw; |
|---|
| 270 | } |
|---|
| 271 | /* JUNGLE ÆùÆ®ÀÇ ÁÂÇ¥ ±âÁØÀº ¿ÞÂÊ À§°¡ ¾Æ´Ï¶ó ¿ÞÂÊ ¾Æ·¡ÀÓ */ |
|---|
| 272 | |
|---|
| 273 | image->bbox.ox=fx; |
|---|
| 274 | image->bbox.oy=fc->ySize-fy-fh+(fc->ySize/4-2);//fy-fh+4; /* (fc->ySize/4-1)´Â º¸Á¤°ª */ |
|---|
| 275 | image->bbox.sx=fw; |
|---|
| 276 | image->bbox.sy=fh; |
|---|
| 277 | |
|---|
| 278 | if(fc->bItalic) { |
|---|
| 279 | #if USE_SMOOTH_ITALIC |
|---|
| 280 | image->bbox.ox-=image->bbox.sy/6; |
|---|
| 281 | image->bbox.sx+=image->bbox.sy/3; |
|---|
| 282 | #else |
|---|
| 283 | image->bbox.ox-=image->bbox.sy/4; |
|---|
| 284 | image->bbox.sx+=image->bbox.sy/2; |
|---|
| 285 | #endif |
|---|
| 286 | |
|---|
| 287 | } |
|---|
| 288 | |
|---|
| 289 | if(fc->bBold) { |
|---|
| 290 | image->bbox.oy--; |
|---|
| 291 | image->bbox.sx++; |
|---|
| 292 | image->bbox.sy++; |
|---|
| 293 | } |
|---|
| 294 | |
|---|
| 295 | |
|---|
| 296 | image->bSize=image->bbox.sx; /* 1pixel´ç 1byte */ |
|---|
| 297 | image->lSize=image->bbox.sx*image->bbox.sy; |
|---|
| 298 | |
|---|
| 299 | #if 0 |
|---|
| 300 | |
|---|
| 301 | image->width=image->bbox.sx; |
|---|
| 302 | |
|---|
| 303 | #if USE_SMOOTH_ITALIC |
|---|
| 304 | if(fc->bItalic) image->width-=image->bbox.sy/3; |
|---|
| 305 | #else |
|---|
| 306 | if(fc->bItalic) image->width-=image->bbox.sy/2; |
|---|
| 307 | #endif |
|---|
| 308 | |
|---|
| 309 | if(image->width > fc->xSize) { |
|---|
| 310 | image->width=fc->xSize; |
|---|
| 311 | image->bbox.ox=-(image->width-fc->xSize)/2; |
|---|
| 312 | } |
|---|
| 313 | |
|---|
| 314 | if(image->width < fc->xSize/4) { |
|---|
| 315 | image->width=fc->xSize/4; |
|---|
| 316 | image->bbox.ox+=(fc->xSize/2-image->width)/2; |
|---|
| 317 | } |
|---|
| 318 | |
|---|
| 319 | #else |
|---|
| 320 | if(code==0x20 || code==0xa0) |
|---|
| 321 | image->width=fc->xSize/3; |
|---|
| 322 | else |
|---|
| 323 | image->width=image->bbox.sx; |
|---|
| 324 | |
|---|
| 325 | #if USE_SMOOTH_ITALIC |
|---|
| 326 | if(fc->bItalic) image->width-=image->bbox.sy/9; |
|---|
| 327 | #else |
|---|
| 328 | if(fc->bItalic) image->width-=image->bbox.sy/6; |
|---|
| 329 | #endif |
|---|
| 330 | |
|---|
| 331 | #endif |
|---|
| 332 | |
|---|
| 333 | image->height=fc->ySize; |
|---|
| 334 | |
|---|
| 335 | image->type=BMF_IMAGE_TYPE_BITMAP_65; |
|---|
| 336 | |
|---|
| 337 | /* »ç¿ëÇÏÁö ¾ÊÀ½ */ |
|---|
| 338 | image->xAdvance=0; |
|---|
| 339 | image->yAdvance=0; |
|---|
| 340 | |
|---|
| 341 | memset(imageBuf, 0, sizeof(imageBuf)); |
|---|
| 342 | |
|---|
| 343 | image->data=imageBuf; |
|---|
| 344 | |
|---|
| 345 | for(pj=0; pj<fh; pj++) { |
|---|
| 346 | int ny=fh-pj-1; |
|---|
| 347 | |
|---|
| 348 | for(pi=0; pi<fw; pi++) { |
|---|
| 349 | |
|---|
| 350 | if(depth==1) { |
|---|
| 351 | if((array[i+pitch*pj+pi/8]&(1<<(7-(pi%8))))==0) continue; |
|---|
| 352 | |
|---|
| 353 | if(fc->bItalic) { |
|---|
| 354 | #if USE_SMOOTH_ITALIC |
|---|
| 355 | int nx=pi+ny/3; |
|---|
| 356 | #else |
|---|
| 357 | int nx=pi+ny/2; |
|---|
| 358 | #endif |
|---|
| 359 | image->data[ny*image->bbox.sx+nx]=255; |
|---|
| 360 | |
|---|
| 361 | if(fc->bBold) { |
|---|
| 362 | image->data[ny*image->bbox.sx+nx+1]=255; |
|---|
| 363 | image->data[(ny+1)*image->bbox.sx+nx]=255; |
|---|
| 364 | image->data[(ny+1)*image->bbox.sx+nx+1]=255; |
|---|
| 365 | } |
|---|
| 366 | |
|---|
| 367 | } |
|---|
| 368 | else { |
|---|
| 369 | image->data[ny*image->bbox.sx+pi]=255; |
|---|
| 370 | |
|---|
| 371 | if(fc->bBold) { |
|---|
| 372 | image->data[ny*image->bbox.sx+pi+1]=255; |
|---|
| 373 | image->data[(ny+1)*image->bbox.sx+pi]=255; |
|---|
| 374 | image->data[(ny+1)*image->bbox.sx+pi+1]=255; |
|---|
| 375 | } |
|---|
| 376 | } |
|---|
| 377 | } /* depth==1 */ |
|---|
| 378 | else if(depth==4) { |
|---|
| 379 | if(pi%2==0) |
|---|
| 380 | image->data[ny*image->bbox.sx+pi]=(array[i+pitch*pj+pi/2]&0xf0); |
|---|
| 381 | else |
|---|
| 382 | image->data[ny*image->bbox.sx+pi]=(array[i+pitch*pj+pi/2]&0x0f)<<4; |
|---|
| 383 | } |
|---|
| 384 | else { /* italic, bold Áö¿ø ¾ÈÇÔ */ |
|---|
| 385 | image->data[ny*image->bbox.sx+pi]=array[i+pitch*pj+pi]; |
|---|
| 386 | } |
|---|
| 387 | } |
|---|
| 388 | } |
|---|
| 389 | |
|---|
| 390 | return 1; |
|---|
| 391 | } |
|---|
| 392 | |
|---|
| 393 | label_failed : |
|---|
| 394 | /* ¸øÃ£À½ */ |
|---|
| 395 | //printf("label failed code(0x%x)\n", code); |
|---|
| 396 | image->bbox.ox=0; |
|---|
| 397 | image->bbox.oy=0; |
|---|
| 398 | image->bbox.sx=0; |
|---|
| 399 | image->bbox.sy=0; |
|---|
| 400 | image->width=0; |
|---|
| 401 | |
|---|
| 402 | image->type=BMF_IMAGE_TYPE_NULL_GLYPH; |
|---|
| 403 | return 0; |
|---|
| 404 | |
|---|
| 405 | } |
|---|
| 406 | |
|---|
| 407 | |
|---|
| 408 | |
|---|
| 409 | #if 0 |
|---|
| 410 | __APIs_For_DMG__() {} |
|---|
| 411 | #endif |
|---|
| 412 | |
|---|
| 413 | |
|---|
| 414 | #define CH_BLANK 0x20 |
|---|
| 415 | #define MARGIN (p_reg_font_attr.size>=36?2:0) |
|---|
| 416 | |
|---|
| 417 | |
|---|
| 418 | static BMF_FC p_reg_fc; |
|---|
| 419 | static BMF_FontAttr p_reg_font_attr; |
|---|
| 420 | |
|---|
| 421 | |
|---|
| 422 | |
|---|
| 423 | /* antialias dhl graphic¿¡¼ ±×´ë·Î °¡Á®¿È */ |
|---|
| 424 | static UINT32 p_antialias_argb8888_pixels(UINT32 bg_pixel, UINT32 fg_pixel, int alpha) |
|---|
| 425 | { |
|---|
| 426 | int a1,r1,g1,b1; |
|---|
| 427 | int a2,r2,g2,b2; |
|---|
| 428 | |
|---|
| 429 | /* no change */ |
|---|
| 430 | if (alpha <= 0) |
|---|
| 431 | return bg_pixel; |
|---|
| 432 | else if (alpha >= 255) |
|---|
| 433 | return fg_pixel; |
|---|
| 434 | |
|---|
| 435 | DHL_DECOMPOSE_ARGB8888(bg_pixel,a1,r1,g1,b1); |
|---|
| 436 | DHL_DECOMPOSE_ARGB8888(fg_pixel,a2,r2,g2,b2); |
|---|
| 437 | |
|---|
| 438 | /* blend them */ |
|---|
| 439 | DHL_BLEND(r1,r2,alpha); |
|---|
| 440 | DHL_BLEND(g1,g2,alpha); |
|---|
| 441 | DHL_BLEND(b1,b2,alpha); |
|---|
| 442 | DHL_BLEND(a1,a2,alpha); /* TODO: is this right? */ |
|---|
| 443 | |
|---|
| 444 | return DHL_COMPOSE_ARGB8888(a1,r1,g1,b1); |
|---|
| 445 | } |
|---|
| 446 | |
|---|
| 447 | |
|---|
| 448 | static UINT32 p_antialias_argb4444_pixels(UINT32 bg_pixel, UINT32 fg_pixel, int alpha) |
|---|
| 449 | { |
|---|
| 450 | int a1,r1,g1,b1; |
|---|
| 451 | int a2,r2,g2,b2; |
|---|
| 452 | |
|---|
| 453 | /* no change */ |
|---|
| 454 | if (alpha <= 0) |
|---|
| 455 | return bg_pixel; |
|---|
| 456 | else if (alpha >= 255) |
|---|
| 457 | return fg_pixel; |
|---|
| 458 | |
|---|
| 459 | DHL_DECOMPOSE_ARGB4444(bg_pixel,a1,r1,g1,b1); |
|---|
| 460 | DHL_DECOMPOSE_ARGB4444(fg_pixel,a2,r2,g2,b2); |
|---|
| 461 | |
|---|
| 462 | /* blend them */ |
|---|
| 463 | DHL_BLEND(r1,r2,alpha); |
|---|
| 464 | DHL_BLEND(g1,g2,alpha); |
|---|
| 465 | DHL_BLEND(b1,b2,alpha); |
|---|
| 466 | DHL_BLEND(a1,a2,alpha); |
|---|
| 467 | |
|---|
| 468 | return DHL_COMPOSE_ARGB4444(a1,r1,g1,b1); |
|---|
| 469 | } |
|---|
| 470 | |
|---|
| 471 | |
|---|
| 472 | static UINT32 p_antialias_rgb565_pixels(UINT32 bg_pixel, UINT32 fg_pixel, int alpha) |
|---|
| 473 | { |
|---|
| 474 | int a1,r1,g1,b1; |
|---|
| 475 | int a2,r2,g2,b2; |
|---|
| 476 | |
|---|
| 477 | /* no change */ |
|---|
| 478 | if (alpha <= 0) |
|---|
| 479 | return bg_pixel; |
|---|
| 480 | else if (alpha >= 255) |
|---|
| 481 | return fg_pixel; |
|---|
| 482 | |
|---|
| 483 | DHL_DECOMPOSE_RGB565(bg_pixel,r1,g1,b1); |
|---|
| 484 | DHL_DECOMPOSE_RGB565(fg_pixel,r2,g2,b2); |
|---|
| 485 | |
|---|
| 486 | /* blend them */ |
|---|
| 487 | DHL_BLEND(r1,r2,alpha); |
|---|
| 488 | DHL_BLEND(g1,g2,alpha); |
|---|
| 489 | DHL_BLEND(b1,b2,alpha); |
|---|
| 490 | |
|---|
| 491 | return DHL_COMPOSE_RGB565(r1,g1,b1); |
|---|
| 492 | } |
|---|
| 493 | |
|---|
| 494 | |
|---|
| 495 | static UINT32 p_antialias_argb1555_pixels(UINT32 bg_pixel, UINT32 fg_pixel, int alpha) |
|---|
| 496 | { |
|---|
| 497 | int a1,r1,g1,b1; |
|---|
| 498 | int a2,r2,g2,b2; |
|---|
| 499 | |
|---|
| 500 | /* no change */ |
|---|
| 501 | if (alpha <= 0) |
|---|
| 502 | return bg_pixel; |
|---|
| 503 | else if (alpha >= 255) |
|---|
| 504 | return fg_pixel; |
|---|
| 505 | |
|---|
| 506 | DHL_DECOMPOSE_ARGB1555(bg_pixel,a1,r1,g1,b1); |
|---|
| 507 | DHL_DECOMPOSE_ARGB1555(fg_pixel,a2,r2,g2,b2); |
|---|
| 508 | |
|---|
| 509 | /* blend them */ |
|---|
| 510 | DHL_BLEND(r1,r2,alpha); |
|---|
| 511 | DHL_BLEND(g1,g2,alpha); |
|---|
| 512 | DHL_BLEND(b1,b2,alpha); |
|---|
| 513 | DHL_BLEND(a1,a2,alpha); |
|---|
| 514 | |
|---|
| 515 | return DHL_COMPOSE_ARGB1555(a1,r1,g1,b1); |
|---|
| 516 | } |
|---|
| 517 | |
|---|
| 518 | |
|---|
| 519 | int BMF_PrintCh(tDHL_PlaneID id, int x, int y, UINT16 ch, UINT32 c_font) |
|---|
| 520 | { |
|---|
| 521 | int i, j; |
|---|
| 522 | int x_margin; |
|---|
| 523 | |
|---|
| 524 | UINT8 *p; |
|---|
| 525 | BMF_IMAGE image; |
|---|
| 526 | |
|---|
| 527 | UINT32 color, c_bg; |
|---|
| 528 | |
|---|
| 529 | int ch_width; |
|---|
| 530 | int ch_sx, ch_sy, ch_ox, ch_oy, bsize; |
|---|
| 531 | UINT8 *pdata; |
|---|
| 532 | |
|---|
| 533 | void *plane_addr; |
|---|
| 534 | int plane_pitch; |
|---|
| 535 | tDHL_PixelType pixel_type; |
|---|
| 536 | |
|---|
| 537 | if(ch==0) return 0; /* ch°¡ 0ÀÌ¸é ¹Ù·Î returnÇØ¹ö¸°´Ù. */ |
|---|
| 538 | |
|---|
| 539 | if(DHL_OK!=DHL_GetPlaneMemory(id, &plane_addr) |
|---|
| 540 | || DHL_OK!=DHL_GetPlanePitch(id, &plane_pitch)) { |
|---|
| 541 | DHL_OS_Printf("%s : plane is not inited yet\n", __FUNCTION__); |
|---|
| 542 | return 0; |
|---|
| 543 | } |
|---|
| 544 | |
|---|
| 545 | DHL_GetPlanePixelType(id, &pixel_type); |
|---|
| 546 | |
|---|
| 547 | |
|---|
| 548 | BMF_GetCharImage(&p_reg_fc, ch, &image); |
|---|
| 549 | if(image.type != BMF_IMAGE_TYPE_BITMAP_65) { |
|---|
| 550 | DHL_OS_Printf("getting image failed(ch:0x%x) !!\n", ch); |
|---|
| 551 | BMF_GetCharImage(&p_reg_fc, CH_BLANK, &image); |
|---|
| 552 | } |
|---|
| 553 | |
|---|
| 554 | if(image.type != BMF_IMAGE_TYPE_BITMAP_65) { |
|---|
| 555 | DHL_OS_Printf("getting image from BMF font engine failed!!!(0x%x:%c)\n", ch, ch); |
|---|
| 556 | return 0; |
|---|
| 557 | } |
|---|
| 558 | |
|---|
| 559 | ch_width=image.width; |
|---|
| 560 | ch_sx=image.bbox.sx; |
|---|
| 561 | ch_sy=image.bbox.sy; |
|---|
| 562 | ch_ox=image.bbox.ox; |
|---|
| 563 | ch_oy=image.bbox.oy; |
|---|
| 564 | bsize=image.bSize; |
|---|
| 565 | pdata=image.data; |
|---|
| 566 | |
|---|
| 567 | label_font_drawing : |
|---|
| 568 | |
|---|
| 569 | #if 0 |
|---|
| 570 | x_margin=MARGIN; //sizeÀÇ 1/10ÀÌ marginÀÌ µÊ |
|---|
| 571 | #else |
|---|
| 572 | x_margin=0; |
|---|
| 573 | #endif |
|---|
| 574 | |
|---|
| 575 | |
|---|
| 576 | if(p_reg_font_attr.is_underline) { //underline |
|---|
| 577 | DHL_DrawHLine(id, x, y+p_reg_font_attr.size*(1-x_margin), ch_width+x_margin*2, c_font); |
|---|
| 578 | } |
|---|
| 579 | |
|---|
| 580 | if(pixel_type==eDHL_PIXELTYPE_ARGB4444) { |
|---|
| 581 | c_font=DHL_COMPOSE_ARGB4444(c_font>>24, (c_font>>16)&0xff, (c_font>>8)&0xff, c_font&0xff); |
|---|
| 582 | } |
|---|
| 583 | else if(pixel_type==eDHL_PIXELTYPE_RGB565) { |
|---|
| 584 | c_font=DHL_COMPOSE_RGB565((c_font>>16)&0xff, (c_font>>8)&0xff, c_font&0xff); |
|---|
| 585 | } |
|---|
| 586 | else if(pixel_type==eDHL_PIXELTYPE_ARGB1555) { |
|---|
| 587 | c_font=DHL_COMPOSE_ARGB1555(c_font>>24, (c_font>>16)&0xff, (c_font>>8)&0xff, c_font&0xff); |
|---|
| 588 | } |
|---|
| 589 | |
|---|
| 590 | |
|---|
| 591 | if(ch>=0x200 && !p_reg_font_attr.is_unicode) { |
|---|
| 592 | //¿Ï¼ºÇüÀ» unicode·Î º¯°æÇÔ. |
|---|
| 593 | ch=DMG_Ksx1001toUnicode(ch); |
|---|
| 594 | } |
|---|
| 595 | |
|---|
| 596 | for(j=0, p=pdata; j<ch_sy; j++, p+=bsize) { |
|---|
| 597 | for(i=0; i<ch_sx; i++) { |
|---|
| 598 | |
|---|
| 599 | if(p[i]==0) continue; |
|---|
| 600 | |
|---|
| 601 | if(pixel_type==eDHL_PIXELTYPE_ARGB8888) { |
|---|
| 602 | c_bg=DHL_GET_PIXEL32(plane_addr, plane_pitch, x+ch_ox+x_margin+i, |
|---|
| 603 | y+p_reg_font_attr.size-ch_oy-j); |
|---|
| 604 | color=p_antialias_argb8888_pixels(c_bg, c_font, p[i]); |
|---|
| 605 | DHL_SET_PIXEL32(plane_addr, plane_pitch, x+ch_ox+x_margin+i, |
|---|
| 606 | y+p_reg_font_attr.size-ch_oy-j, color); |
|---|
| 607 | } |
|---|
| 608 | else if(pixel_type==eDHL_PIXELTYPE_ARGB4444) { |
|---|
| 609 | c_bg=DHL_GET_PIXEL16(plane_addr, plane_pitch, x+ch_ox+x_margin+i, |
|---|
| 610 | y+p_reg_font_attr.size-ch_oy-j); |
|---|
| 611 | color=p_antialias_argb4444_pixels(c_bg, c_font, p[i]); |
|---|
| 612 | DHL_SET_PIXEL16(plane_addr, plane_pitch, x+ch_ox+x_margin+i, |
|---|
| 613 | y+p_reg_font_attr.size-ch_oy-j, color); |
|---|
| 614 | } |
|---|
| 615 | else if(pixel_type==eDHL_PIXELTYPE_RGB565) { |
|---|
| 616 | c_bg=DHL_GET_PIXEL16(plane_addr, plane_pitch, x+ch_ox+x_margin+i, |
|---|
| 617 | y+p_reg_font_attr.size-ch_oy-j); |
|---|
| 618 | color=p_antialias_rgb565_pixels(c_bg, c_font, p[i]); |
|---|
| 619 | DHL_SET_PIXEL16(plane_addr, plane_pitch, x+ch_ox+x_margin+i, |
|---|
| 620 | y+p_reg_font_attr.size-ch_oy-j, color); |
|---|
| 621 | } |
|---|
| 622 | else if(pixel_type==eDHL_PIXELTYPE_ARGB1555) { |
|---|
| 623 | c_bg=DHL_GET_PIXEL16(plane_addr, plane_pitch, x+ch_ox+x_margin+i, |
|---|
| 624 | y+p_reg_font_attr.size-ch_oy-j); |
|---|
| 625 | color=p_antialias_argb1555_pixels(c_bg, c_font, p[i]); |
|---|
| 626 | DHL_SET_PIXEL16(plane_addr, plane_pitch, x+ch_ox+x_margin+i, |
|---|
| 627 | y+p_reg_font_attr.size-ch_oy-j, color); |
|---|
| 628 | } |
|---|
| 629 | |
|---|
| 630 | } |
|---|
| 631 | } |
|---|
| 632 | |
|---|
| 633 | DHL_PostDraw(id, x, y, ch_width+x_margin*2, p_reg_font_attr.size); |
|---|
| 634 | |
|---|
| 635 | return ch_ox+ch_width+x_margin*2; |
|---|
| 636 | } |
|---|
| 637 | |
|---|
| 638 | |
|---|
| 639 | int BMF_GetChWidth(UINT16 ch) |
|---|
| 640 | { |
|---|
| 641 | BMF_IMAGE image; |
|---|
| 642 | |
|---|
| 643 | BMF_GetCharImage(&p_reg_fc, ch, &image); |
|---|
| 644 | if(image.type != BMF_IMAGE_TYPE_BITMAP_65) { |
|---|
| 645 | BMF_GetCharImage(&p_reg_fc, CH_BLANK, &image); |
|---|
| 646 | } |
|---|
| 647 | |
|---|
| 648 | return image.bbox.ox+image.width+MARGIN*2; |
|---|
| 649 | } |
|---|
| 650 | |
|---|
| 651 | |
|---|
| 652 | int BMF_GetChHeight(UINT16 ch) |
|---|
| 653 | { |
|---|
| 654 | BMF_IMAGE image; |
|---|
| 655 | |
|---|
| 656 | BMF_GetCharImage(&p_reg_fc, ch, &image); |
|---|
| 657 | if(image.type != BMF_IMAGE_TYPE_BITMAP_65) { |
|---|
| 658 | BMF_GetCharImage(&p_reg_fc, CH_BLANK, &image); |
|---|
| 659 | } |
|---|
| 660 | |
|---|
| 661 | //return image.bbox.oy+image.height; |
|---|
| 662 | return image.height*11/10; |
|---|
| 663 | } |
|---|
| 664 | |
|---|
| 665 | |
|---|
| 666 | |
|---|
| 667 | void BMF_GetFontAttr(BMF_FontAttr *pfont_attr) |
|---|
| 668 | { |
|---|
| 669 | memcpy(pfont_attr, &p_reg_font_attr, sizeof(*pfont_attr)); |
|---|
| 670 | } |
|---|
| 671 | |
|---|
| 672 | |
|---|
| 673 | |
|---|
| 674 | void BMF_SetFontAttr(BMF_FontAttr *pfont_attr) |
|---|
| 675 | { |
|---|
| 676 | |
|---|
| 677 | if(pfont_attr->size!=p_reg_font_attr.size) |
|---|
| 678 | BMF_SetSize(&p_reg_fc, pfont_attr->size, pfont_attr->size); |
|---|
| 679 | |
|---|
| 680 | if(pfont_attr->is_bold!=p_reg_font_attr.is_bold) |
|---|
| 681 | BMF_SetBold(&p_reg_fc, pfont_attr->is_bold?1:0); |
|---|
| 682 | |
|---|
| 683 | if(pfont_attr->is_italic!=p_reg_font_attr.is_italic) |
|---|
| 684 | BMF_SetItalic(&p_reg_fc, pfont_attr->is_italic?1:0); |
|---|
| 685 | |
|---|
| 686 | if(pfont_attr->font_style!=p_reg_font_attr.font_style) |
|---|
| 687 | BMF_SetFont(&p_reg_fc, pfont_attr->font_style); |
|---|
| 688 | |
|---|
| 689 | if(pfont_attr->edge_type!=p_reg_font_attr.edge_type) |
|---|
| 690 | BMF_SetEdgeType(&p_reg_fc, pfont_attr->edge_type); |
|---|
| 691 | |
|---|
| 692 | memcpy(&p_reg_font_attr, pfont_attr, sizeof(p_reg_font_attr)); |
|---|
| 693 | } |
|---|
| 694 | |
|---|
| 695 | |
|---|
| 696 | void BMF_FontInit(BMF_FontAttr *pfont_attr) |
|---|
| 697 | { |
|---|
| 698 | BMF_InitFontManager(0, 0, 0, 0, 0, 0); |
|---|
| 699 | |
|---|
| 700 | BMF_InitFontContext(&p_reg_fc, 0, 0); |
|---|
| 701 | |
|---|
| 702 | BMF_SetSize(&p_reg_fc, pfont_attr->size, 0); |
|---|
| 703 | BMF_SetBold(&p_reg_fc, 0); |
|---|
| 704 | BMF_SetItalic(&p_reg_fc, 0); |
|---|
| 705 | BMF_SetFont(&p_reg_fc, 0); |
|---|
| 706 | BMF_SetEdgeType(&p_reg_fc, 0); |
|---|
| 707 | |
|---|
| 708 | BMF_SetFontAttr(pfont_attr); |
|---|
| 709 | } |
|---|
| 710 | |
|---|
| 711 | |
|---|
| 712 | |
|---|
| 713 | #if 0 |
|---|
| 714 | ___Debug___() |
|---|
| 715 | #endif |
|---|
| 716 | |
|---|
| 717 | |
|---|
| 718 | |
|---|
| 719 | |
|---|
| 720 | |
|---|
| 721 | |
|---|
| 722 | |
|---|
| 723 | |
|---|
| 724 | |
|---|
| 725 | |
|---|
| 726 | |
|---|
| 727 | |
|---|
| 728 | |
|---|
| 729 | |
|---|
| 730 | |
|---|
| 731 | |
|---|
| 732 | |
|---|
| 733 | |
|---|