?? gfx_drawlib.c.svn-base
字號:
/* * * Copyright (c) Sigma Designs, Inc. 2004. All rights reserved. * *//** @file gfx_drawlib.c @brief gfx_drawlib api @author Raul Chirinos */#define ALLOW_OS_CODE#include "../include/gfx_drawlib.h"#include "../include/gfx_drawcontrol.h"#include <stdlib.h>#include "../include/stream.h"#include "../include/subreader.h"//#include "rmalloc.h"#if 1#define GFXDBG ENABLE#else#define GFXDBG DISABLE#endif/* for simple glyph flags */#define ONOROFF 0x01#define XSHORT 0x02#define YSHORT 0x04#define REPEAT 0x08#define XSAME 0x10#define YSAME 0x20#define Y_GOES_HERE 0x40#define X_GOES_HERE 0x80extern sub_context subs;/* for compound glyph flags */#define ARG_1_AND_2_ARE_WORDS 0x0001#define ARGS_ARE_XY_VALUES 0x0002#define XY_BOUND_TO_GRID 0x0004#define WE_HAVE_A_SCALE 0x0008#define MORE_COMPONENTS 0x0020#define WE_HAVE_AN_X_AND_Y_SCALE 0x0040#define WE_HAVE_A_TWO_BY_TWO 0x0080#define WE_HAVE_INSTRUCTIONS 0x0100#define USE_MY_METRICS 0x0200#define INVALID_GLYPH 0xFFFFFFFF#define LAT1_CHAR_NO 191#define IS_ASCII(a) ((a)>=32 && (a)<=126)#define IS_LATIN1(a) ((a)>=160 && (a)<=255)#define IS_VALID_CHAR(a) (IS_ASCII(a) ? 1 : IS_LATIN1(a))#define CLIP(A,L,H) RMmin(RMmax(A, L), H)static RMint8 width[2048] ={ -1, };static RMint8 size[2048] ={ -1, };static RMint8 height[2048] ={ -1, };static RMbool init = FALSE;/* #define WITH_TTF */struct table_ptrs{ RMuint8 *head_table; RMuint8 *hhea_table; RMuint8 *cmap_table; RMuint8 *hmtx_table; RMuint8 *glyf_start; RMuint8 *maxp_table; RMuint8 *loca_table;};struct ttf_charmap{ RMuint16 segCountX2; RMuint16 *ttf_cmap;};struct lib_index_entry{ RMuint32 index; RMuint32 addr;};struct glyph_lib_index{ struct lib_index_entry tab[2048]; RMuint32 cnt; RMuint32 size; RMuint32 sub_cnt;};// global dataGFXLib_data gdata;RMstatus draw_char(struct RUA *pRua, RMuint32 char_index, RMuint32 char_size, RMuint32 fg_color, RMuint32 bg_color, Point *point, GFXLib_rect *out_rect);static RMstatus rtk86_unload_font(struct RUA *pRua);static int CompFunc(const void *p1, const void *p2){ return ((((GFXLib_objectdata*) p1)->zindex) - (((GFXLib_objectdata*) p2)->zindex));}/* initialize gfx */RMstatus gfxInit(struct RUA *pRua){ RMuint32 gfx_count; struct GFXEngine_DRAMSize_in_type dramSizeIn; struct GFXEngine_DRAMSize_out_type dramSizeOut; RMuint32 i;//,j; RMstatus status; // stream_t* fd; // RMascii buffer[10]; // init vars RMMemset(&gdata, 0, sizeof(gdata)); gdata.gfx = 0xff; gdata.tvType = TVTYPE_4_3; ResetBmpBuffers(); dramSizeIn.CommandFIFOCount = GFX_FIFOCOUNT; status = RUAExchangeProperty(pRua, EMHWLIB_MODULE(GFXEngine, 0), RMGFXEnginePropertyID_DRAMSize, &dramSizeIn, sizeof(dramSizeIn), &dramSizeOut, sizeof(dramSizeOut)); if (RMFAILED(status)) { RMDBGLOG((GFXDBG, "Error getting dram size for gfx engine\n")); return RM_ERROR; } gdata.profile.CommandFIFOCount = dramSizeIn.CommandFIFOCount; gdata.profile.Priority = 1; gdata.profile.CachedSize = dramSizeOut.CachedSize; gdata.profile.UncachedSize = dramSizeOut.UncachedSize; if (gdata.profile.CachedSize > 0) { gdata.profile.CachedAddress = RUAMalloc(pRua, 0, RUA_DRAM_CACHED, gdata.profile.CachedSize); // printf("gfx cached addr: 0x%08lx, size 0x%08lx, end: 0x%08lx\n", gdata.profile.CachedAddress, gdata.profile.CachedSize, gdata.profile.CachedAddress + gdata.profile.CachedSize); } else { gdata.profile.CachedAddress = 0; } gdata.profile.UncachedSize = dramSizeOut.UncachedSize; if (gdata.profile.UncachedSize > 0) { gdata.profile.UncachedAddress = RUAMalloc(pRua, 0, RUA_DRAM_UNCACHED, gdata.profile.UncachedSize); // printf("gfx uncached addr: 0x%08lx, size 0x%08lx, end: 0x%08lx\n", gdata.profile.UncachedAddress, gdata.profile.UncachedSize, gdata.profile.UncachedAddress + gdata.profile.UncachedSize); } else { gdata.profile.UncachedAddress = 0; } gdata.gfx = GFXEngine; status = RUAExchangeProperty(pRua, EMHWLIB_MODULE(Enumerator, 0), RMEnumeratorPropertyID_CategoryIDToNumberOfInstances, &gdata.gfx, sizeof(gdata.gfx), &gfx_count, sizeof(gfx_count)); if (RMFAILED(status)) { RMDBGLOG((GFXDBG, "Error getting gfx engine count\n")); return RM_ERROR; } for (i = 0; i < gfx_count; i++) { gdata.gfx = EMHWLIB_MODULE(GFXEngine, i); status = RUASetProperty(pRua, gdata.gfx, RMGFXEnginePropertyID_Open, &gdata.profile, sizeof(gdata.profile), 0); if (status == RM_OK) break; } if (i == gfx_count) { RMDBGLOG((GFXDBG, "Cannot open a gfx engine [0..%lu[\n", gfx_count)); return RM_ERROR; } gdata.font_type = rtk_font_type_None; gfxLoadFontFile(pRua, "subfont.ttf"); // i = 0; // fd=open_stream_gfx ("Revolution.OS.2001.DVDRip.XviD-RETRO.sub", NULL, &i); // stream_fill_buffer(fd); // // for(i = 0; i < 65535; i ++){ // buffer[0] = stream_read_char(fd); // printf("%c", buffer[0]); // } // // free_stream(fd); //[RC] NEED CLEAN UP JOB!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! InitPrefetch(); return RM_OK;}/* unInitialize gfx */RMstatus gfxUnInit(struct RUA *pRua){ RMuint32 close_profile = 0; RMstatus status; ClosePrefetch(); if (pRua == NULL || gdata.gfx == 0xff) return RM_ERROR; status = RUASetProperty(pRua, gdata.gfx, RMGFXEnginePropertyID_Close, &close_profile, sizeof(close_profile), 0); if (RMFAILED(status)) { RMDBGLOG((GFXDBG, "Error cannot close gfx engine\n")); } if (gdata.profile.CachedAddress > 0) { RUAFree(pRua, gdata.profile.CachedAddress); gdata.profile.CachedAddress = 0; } if (gdata.profile.UncachedAddress > 0) { RUAFree(pRua, gdata.profile.UncachedAddress); gdata.profile.UncachedAddress = 0; } if (gdata.font_type != rtk_font_type_None) { rtk86_unload_font(pRua); } // free drawing buffer FreeBaseBuffer(pRua); FreeBackBuffer(pRua, &gdata.backBuffer); printf("exit\n"); return RM_OK;}static inline void rtk86_fill_charset(struct ttf_charset *charset, enum rtk_charset_type type){ RMuint16 index, last_used = 0; for (index = 0; index < 2048; index++) { // switch(type){ // case rtk_charset_type_DTVCC: // case rtk_charset_type_LATIN1: if ((index >= 0xa0) && (index < 0x100)) { charset->unicodes[index] = index; last_used = index; // break; } // if((index == 0x410)) // charset->unicodes[144] = index; if ((index >= 0x0400) && (index <= 0x0450)) { charset->unicodes[index] = index; last_used = index; // RMDBGLOG((GFXDBG, "kirilica\n")); // break; } // charset->unicodes[index] = 0; // break; /* no break */ // case rtk_charset_type_ASCII: if ((index >= 0x20) && (index < 0x7f)) { charset->unicodes[index] = index; last_used = index; } // else{ // charset->unicodes[index] = 0; // } // break; // } } charset->char_count = last_used; /* if( type == DTVCC_charset){ */ /* ADD_CHARSET_PAIR( charset, 8216, 0x91); */ /* ADD_CHARSET_PAIR( charset, 8217, 0x92); */ /* ADD_CHARSET_PAIR( charset, 8220, 0x93); */ /* ADD_CHARSET_PAIR( charset, 8221, 0x94); */ /* ADD_CHARSET_PAIR( charset, 8230, 0x85); */ /* ADD_CHARSET_PAIR( charset, 8226, 0x95); */ /* ADD_CHARSET_PAIR( charset, 8482, 0x99); */ /* ADD_CHARSET_PAIR( charset, 352 , 0x8a); */ /* ADD_CHARSET_PAIR( charset, 353 , 0x9a); */ /* ADD_CHARSET_PAIR( charset, 338 , 0x8c); */ /* ADD_CHARSET_PAIR( charset, 339 , 0x9c); */ /* ADD_CHARSET_PAIR( charset, 8480, 0x9d); */ /* ADD_CHARSET_PAIR( charset, 376 , 0x9f); */ /* ADD_CHARSET_PAIR( charset, 8216, 0x91); */ /* } */ /* return RM_OK; */}static inline void get_glyph_pos(RMuint32 glyphno, struct table_ptrs *tp, RMuint8 **pos, RMuint32 *len){ RMbool long_off = RMbeBufToUint16(tp->head_table + 50/*indexToLocFormat_off*/) ? TRUE : FALSE; if (long_off) { *pos = tp->glyf_start + RMbeBufToUint32(tp->loca_table + 4 * glyphno); if (len != NULL) *len = RMbeBufToUint32(tp->loca_table + 4 * (glyphno + 1)) - RMbeBufToUint32(tp->loca_table + 4 * glyphno); } else { *pos = tp->glyf_start + 2 * RMbeBufToUint16(tp->loca_table + 2 * glyphno); if (len != NULL) *len = 2 * (RMbeBufToUint16(tp->loca_table + 2 * (glyphno + 1)) - RMbeBufToUint16(tp->loca_table + 2 * glyphno)); }}static inline RMuint32 get_glyph_index(RMuint32 char_code){ if (char_code >= 0x20 && char_code < 0x7f) return (char_code - 32); else if (char_code >= 0xa0 && char_code <= 0xff) return (char_code - 65); else if (char_code >= 0x7f && char_code <= 0x9f) return (char_code + 64); else if (char_code >= 0x00 && char_code <= 0x1f) return (char_code + 192); return INVALID_GLYPH;}static inline RMuint32 get_glyph_index_from_charmap(struct ttf_charmap *charmap, RMuint16 char_code){ RMuint32 i; RMuint32 glyph_no = 0; RMuint16 segCount = charmap->segCountX2 / 2; RMuint16 *endCount = charmap->ttf_cmap; RMuint16 *startCount = &(endCount[segCount + 1]); RMuint16 *idDelta = &(startCount[segCount]); RMuint16 *idRangeOffset = &(idDelta[segCount]); for (i = 0; (i < segCount) && (char_code > endCount[i]); i++) ; if (char_code >= startCount[i]) { if (idRangeOffset[i]) { glyph_no = *(idRangeOffset[i] / 2 + (char_code - startCount[i]) + &idRangeOffset[i]); } else { glyph_no = char_code; } glyph_no += idDelta[i]; glyph_no &= 0xffff; } else { return 0; } return glyph_no;}static inline RMbool search_glyph_lib(struct glyph_lib_index *lib_index, RMuint32 glyph_index, RMuint32 *addr, RMuint32 *size){ RMuint8 i; for (i = 0; i < lib_index->cnt; i++) { if (lib_index->tab[i].index == glyph_index) { if ((addr != NULL) && (size != NULL)) { *addr = lib_index->tab[i].addr; *size = (RMuint32) lib_index->tab[i + 1].addr - (RMuint32) lib_index->tab[i].addr; } return TRUE; } } return FALSE;}static inline RMuint32 get_glyph_size(RMuint32 glyph_index, struct glyph_lib_index *lib_index, struct table_ptrs *tp){ RMuint32 len, inst_size, glyph_size; RMint16 n_contours; RMuint8 *pos; get_glyph_pos(glyph_index, tp, &pos, &len); if (!len) { return 0; } n_contours = (RMint16) RMbeBufToUint16(pos); if (n_contours > 0) { /* skip if the glyph is already marked for upload */ if (search_glyph_lib(lib_index, glyph_index, NULL, NULL)) { return 1; } pos += 10 + 2 * n_contours; /*skip n_contours(2), xmin(2), ymin(2), xmax(2), ymax(2), all endpoints (x2) */ inst_size = RMbeBufToUint16(pos); glyph_size = len + 2 - 10 - inst_size + ((n_contours & 0x1) ? 2 : 0); /* force each glyph to start into a 4-byte boundary */ if (glyph_size & 0x3) glyph_size += 4 - (glyph_size & 0x3); lib_index->size += glyph_size; lib_index->tab[lib_index->cnt].index = glyph_index; lib_index->cnt++; return 1; } else { RMuint16 flags, sub_glyph_index = 0; RMuint32 sub_glyph_count; sub_glyph_count = 0; pos += 10; /*skip bounding box*/ do { flags = RMbeBufToUint16(pos); pos += 2; sub_glyph_index = RMbeBufToUint16(pos); pos += 2; sub_glyph_count += get_glyph_size(sub_glyph_index, lib_index, tp); if (flags & ARG_1_AND_2_ARE_WORDS) pos += 4; else pos += 2; if (flags & WE_HAVE_A_SCALE) pos += 2; else if (flags & WE_HAVE_AN_X_AND_Y_SCALE) pos += 4; else if (flags & WE_HAVE_A_TWO_BY_TWO) pos += 8; } while (flags & MORE_COMPONENTS); lib_index->sub_cnt += sub_glyph_count; return sub_glyph_count; }}static inline RMstatus create_glyph_lib(struct RUA *pRUA, struct glyph_lib_index *lib_index, struct table_ptrs *tp){ RMstatus err; RMuint8 *pos, *xpos, *ypos, *mapped_lib, *glyph_start; RMuint8 flags = 0, repeat = 0; RMint16 n_contours; RMuint32 i, j, k, x_size, last_k, n_points, inst_size; RMuint32 lib, lib_pos; lib = RUAMalloc(pRUA, 0, RUA_DRAM_UNCACHED, lib_index->size); if (lib == 0) { RMDBGLOG((GFXDBG, "Error allocating font buffer \n")); return RM_ERROR; } lib_pos = lib; err = RUALock(pRUA, lib, lib_index->size); if (RMFAILED(err)) { RMDBGLOG((GFXDBG, "Error locking font buffer \n")); return err; }
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -