⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 native.c

📁 国人开发的嵌入式浏览器
💻 C
📖 第 1 页 / 共 3 页
字号:
}/* * Convertion between GAL_Color and gal_pixel * borrowed  from gl lib. */static gal_pixel mapcolor (GAL_GC gc, GAL_Color *color){    unsigned int v;    switch (gc.psd->bpp) {    case 1:        if ((color->b + color->g + color->r) > 128*3)            v = 1;        else            v = 0;        return v;    case 2:        v = 0;        if (color->b >= 64)            v += 1;        if (color->g >= 64)            v += 2;        if (color->r >= 64)            v += 4;        if (color->b >= 192 || color->g >= 192 || color->r >= 192)            v += 8;        v>>=2;        return v;    case 4:        /* Now this is real fun. Map to standard EGA palette. */        v = 0;        if (color->b >= 64)            v += 1;        if (color->g >= 64)            v += 2;        if (color->r >= 64)            v += 4;        if (color->b >= 192 || color->g >= 192 || color->r >= 192)            v += 8;        return v;    case 8:        return RGB2PIXEL332 (color->r, color->g, color->b);    case 15:        return RGB2PIXEL555 (color->r, color->g, color->b);    case 16:        return RGB2PIXEL565 (color->r, color->g, color->b);    case 24:    case 32:        return RGB2PIXEL888 (color->r, color->g, color->b);    }    return -1;}static int unmappixel (GAL_GC gc, gal_pixel pixel, GAL_Color* color){    switch (gc.psd->bpp) {    case 1:        if (pixel) {            color->r = 255;            color->g = 255;            color->b = 255;        }        else {            color->r = 0;            color->g = 0;            color->b = 0;        }        break;    case 2:    case 4:        color->r = SysPixelColor [pixel].r;        color->g = SysPixelColor [pixel].g;        color->b = SysPixelColor [pixel].b;        break;    case 8:        color->r = PIXEL332RED (pixel) << 5;        color->g = PIXEL332GREEN (pixel) << 5;        color->b = PIXEL332BLUE (pixel) << 6;        break;    case 15:        color->r = PIXEL555RED (pixel) << 3;        color->g = PIXEL555GREEN (pixel) << 3;        color->b = PIXEL555BLUE (pixel) << 3;        break;    case 16:        color->r = PIXEL565RED (pixel) << 3;        color->g = PIXEL565GREEN (pixel) << 2;        color->b = PIXEL565BLUE (pixel) << 3;        break;    case 24:    case 32:        color->r = PIXEL888RED (pixel);        color->g = PIXEL888GREEN (pixel);        color->b = PIXEL888BLUE (pixel);        break;    }        return 0;}/* * Palette operations */static int getpalette (GAL_GC gc, int s, int len, GAL_Color* cmap){    gc.psd->GetPalette(gc.psd,s,len,cmap);    return 0;}static int setpalette (GAL_GC gc, int s, int len, GAL_Color* cmap){    gc.psd->SetPalette(gc.psd,s,len,cmap);    return 0;}/* * Specical functions work for <=8 bit color mode. */static int setcolorfulpalette (GAL_GC gc){    int i;    GAL_Color pal[256];    if (gc.psd->bpp > 8)    return 0;    switch ( gc.psd->bpp ) {    case 1:        for (i = 0; i < 2; i++) {            pal[i].b = SysPixelColor[i*15].b;            pal[i].g = SysPixelColor[i*15].g;            pal[i].r = SysPixelColor[i*15].r;            pal[i].a = 0;        }        gc.psd->SetPalette(gc.psd,0,2,pal);        break;    case 2:        for (i = 0; i < 4; i++) {            pal[i].b = SysPixelColor[i*4].b;            pal[i].g = SysPixelColor[i*4].g;            pal[i].r = SysPixelColor[i*4].r;            pal[i].a = 0;        }        gc.psd->SetPalette(gc.psd,0,4,pal);        break;    case 4:        for (i = 0; i < 16; i++) {            pal[i].b = SysPixelColor[i].b;            pal[i].g = SysPixelColor[i].g;            pal[i].r = SysPixelColor[i].r;            pal[i].a = 0;        }        gc.psd->SetPalette(gc.psd,0,16,pal);            break;    case 8:        for (i = 0; i < 256; i++) {#if 1            pal[i].r = PIXEL332RED (i) << 5;            pal[i].g = PIXEL332GREEN (i) << 5;            pal[i].b = PIXEL332BLUE (i) << 6;#else            pal[i].b = (i & 7) * (64 / 2);        /* 3 bits */            pal[i].g = ((i & 56) >> 3) * (64 / 2);    /* 3 bits */            pal[i].r = ((i & 192) >> 6) * (64);        /* 2 bits */#endif            pal[i].a = 0;        }        gc.psd->SetPalette (gc.psd, 0, 256, pal);            break;    default:        break;    }            return 0;}/* * Box operations * TODO: Currently we did not do clpping in putbox() or getbox() or other. * If we do clipping at early, we can spend time... */static size_t boxsize (GAL_GC gc, int w, int h){    if ((w <= 0) || (h <= 0)) return -1;    return w * h * bytesperpixel (gc);}static int fillbox (GAL_GC gc, int x, int y, int w, int h, gal_pixel pixel){    if ((w <= 0) || (h <= 0)) return -1;    BLOCK_DRAW_SEM;    if (_COOR_TRANS && gc.psd == cur_gfx->phygc.psd)        rotaterect (&x, &y, &w, &h, _ROT_DIR_CCW?gc.psd->xres:gc.psd->yres, _ROT_DIR_CCW?0:1);    if (native_gen_clipbox (gc.psd, &x, &y, &w, &h) == CLIP_INVISIBLE)        goto ret;    gc.psd->FillRect (gc.psd, x, y, w, h, pixel) ;    if (gc.psd->UpdateRect) gc.psd->UpdateRect (gc.psd, x, y, x + w, y + h);ret:    UNBLOCK_DRAW_SEM;    return 0;}static void putbox_helper (GAL_GC gc, int x, int y, int w, int h, void* buf, int pitch){    int bpp = bytesperpixel (gc);    gal_uint8 *tmpptr= (gal_uint8*) buf;    rotaterect (&x, &y, &w, &h, _ROT_DIR_CCW?gc.psd->xres:gc.psd->yres, _ROT_DIR_CCW?1:0);    if ( y < 0 ) {        h += y;        tmpptr -= y * pitch;        y = 0;    }    if ( x < 0 ) {        w += x;        tmpptr -= bpp * x;        x = 0;    }    if ( x + w -1 >= gc.psd->yres)         w = gc.psd->yres - x;    if ( y + h -1 >= gc.psd->xres)         h = gc.psd->xres - y;    rotatepoint (&x, &y, _ROT_DIR_CCW?gc.psd->xres:gc.psd->yres, _ROT_DIR_CCW?0:1);    if (_ROT_DIR_CCW) {        while (h > 0) {            gc.psd->PutBox (gc.psd, x, y, 1, w, tmpptr);            tmpptr += pitch;            x--;            h--;        }    }    else {        char* reversi = alloca (w * bpp);        y -= w - 1;        while (h > 0) {            reverse_buff (reversi, tmpptr, w, bpp);            gc.psd->PutBox (gc.psd, x, y, 1, w, reversi);            tmpptr += pitch;            x++;            h--;        }    }}static int putbox_wrapper (GAL_GC gc, int x, int y, int w, int h, void* buf, int pitch){    if ((w <= 0) || (h <= 0)) return -1;        BLOCK_DRAW_SEM;    if (_COOR_TRANS && gc.psd == cur_gfx->phygc.psd) {        rotaterect (&x, &y, &w, &h, _ROT_DIR_CCW?gc.psd->xres:gc.psd->yres, _ROT_DIR_CCW?0:1);        if (gc.psd->doclip) {            if ((x + w - 1 < gc.psd->clipminx) || (x >= gc.psd->clipmaxx))                goto inv_args;            if ((y + h - 1 < gc.psd->clipminy) || (y >= gc.psd->clipmaxy))                goto inv_args;        } else {            if ((x + w - 1 < 0) || (x >= gc.psd->xres))                goto inv_args;            if ((y + h - 1 < 0) || (y >= gc.psd->yres))                goto inv_args;        }        putbox_helper (gc, x, y, w, h, buf, pitch);    }    else {        if (gc.psd->doclip) {            if ((x + w - 1 < gc.psd->clipminx) || (x >= gc.psd->clipmaxx))                goto inv_args;            if ((y + h - 1 < gc.psd->clipminy) || (y >= gc.psd->clipmaxy))                goto inv_args;        } else {            if ((x + w - 1 < 0) || (x >= gc.psd->xres))                goto inv_args;            if ((y + h - 1 < 0) || (y >= gc.psd->yres))                goto inv_args;        }        gc.psd->PutBox (gc.psd, x, y, w, h, buf);   /* ignore pitch */    }    if (gc.psd->UpdateRect) gc.psd->UpdateRect (gc.psd, x, y, x + w, y + h);inv_args:    UNBLOCK_DRAW_SEM;    return 0;}static int putbox (GAL_GC gc, int x, int y, int w, int h, void* buf){    return putbox_wrapper (gc, x, y, w, h, buf, w * bytesperpixel (gc));}static int putboxmask ( GAL_GC gc, int x, int y, int w, int h, void* buf, gal_pixel cxx){    int oldw = w, bpp = 0;    gal_uint8 *tmpptr= (gal_uint8*) buf;    if ((w <= 0) || (h <= 0)) return -1;    BLOCK_DRAW_SEM;    if (_COOR_TRANS && gc.psd == cur_gfx->phygc.psd) {        rotaterect (&x, &y, &w, &h, _ROT_DIR_CCW?gc.psd->xres:gc.psd->yres, _ROT_DIR_CCW?0:1);        if (gc.psd->doclip) {            if ((x + w - 1 < gc.psd->clipminx) || (x >= gc.psd->clipmaxx))                goto inv_args;            if ((y + h - 1 < gc.psd->clipminy) || (y >= gc.psd->clipmaxy))                goto inv_args;        } else {            if ((x + w - 1 < 0) || (x >= gc.psd->xres))                goto inv_args;            if ((y + h - 1 < 0) || (y >= gc.psd->yres))                goto inv_args;        }        rotaterect (&x, &y, &w, &h, _ROT_DIR_CCW?gc.psd->xres:gc.psd->yres, _ROT_DIR_CCW?1:0);        bpp = bytesperpixel (gc);        if ( y < 0 ) {            h += y;            tmpptr -= y * bpp * w;            y = 0;        }        if ( x < 0 ) {            w += x;            tmpptr -= bpp * x;            x = 0;        }                if ( x + w -1 >= gc.psd->yres)             w = gc.psd->yres - x ;        if ( y + h -1 >= gc.psd->xres)             h = gc.psd->xres - y ;        rotatepoint (&x, &y, _ROT_DIR_CCW?gc.psd->xres:gc.psd->yres, _ROT_DIR_CCW?0:1);        if (_ROT_DIR_CCW) {            while (h > 0) {                gc.psd->PutBoxMask (gc.psd, x, y, 1, w, tmpptr, cxx);                    tmpptr += bpp * oldw;                x--;                h--;            }        }        else {            char* reversi = alloca (w * bpp);                y -= w - 1;            while (h > 0) {                reverse_buff (reversi, tmpptr, w, bpp);                gc.psd->PutBoxMask (gc.psd, x, y, 1, w, reversi, cxx);                    tmpptr += bpp * oldw;                x++;                h--;            }        }    }    else {        if (gc.psd->doclip) {            if ((x + w - 1 < gc.psd->clipminx) || (x >= gc.psd->clipmaxx))                goto inv_args;            if ((y + h - 1 < gc.psd->clipminy) || (y >= gc.psd->clipmaxy))                goto inv_args;        } else {            if ((x + w - 1 < 0) || (x >= gc.psd->xres))                goto inv_args;            if ((y + h - 1 < 0) || (y >= gc.psd->yres))                goto inv_args;        }        gc.psd->PutBoxMask (gc.psd, x, y, w, h, buf, cxx);    }    if (gc.psd->UpdateRect) gc.psd->UpdateRect (gc.psd, x, y, x + w, y + h);inv_args:    UNBLOCK_DRAW_SEM;    return 0;}static void getbox_helper (GAL_GC gc, int x, int y, int w, int h, void* buf, int pitch){    int bpp = bytesperpixel (gc);    gal_uint8 *tmpptr= (gal_uint8*) buf;    if ( y < 0 ) {        h += y;        tmpptr -= y * pitch;        y = 0;    }    if ( x < 0 ) {        w += x;        tmpptr -= bpp * x;        x = 0;    }            if ( x + w -1 >= gc.psd->yres)         w = gc.psd->yres - x ;    if ( y + h -1 >= gc.psd->xres)         h = gc.psd->xres - y ;    rotatepoint (&x, &y, _ROT_DIR_CCW?gc.psd->xres:gc.psd->yres, _ROT_DIR_CCW?0:1);    if (_ROT_DIR_CCW) {        while (h > 0) {            gc.psd->GetBox (gc.psd, x, y, 1, w, tmpptr);            tmpptr += pitch;            x--;            h--;        }    }    else {        char* reversi = alloca (w * bpp);        y -= w - 1;        while (h > 0) {            gc.psd->GetBox (gc.psd, x, y, 1, w, reversi);            reverse_buff (tmpptr, reversi, w, bpp);            tmpptr += pitch;            x++;            h--;        }    }}static int getbox_wrapper (GAL_GC gc, int x, int y, int w, int h, void* buf, int pitch){    if ((w <= 0) || (h <= 0)) return -1;    if (_COOR_TRANS && gc.psd == cur_gfx->phygc.psd) {        if ((x + w - 1 < 0) || (x >= gc.psd->yres))            return -1;        if ((y + h - 1 < 0) || (y >= gc.psd->xres))            return -1;        getbox_helper (gc, x, y, w, h, buf, pitch);    }    else {        if ((x + w - 1 < 0) || (x >= gc.psd->xres))            return -1;        if ((y + h - 1 < 0) || (y >= gc.psd->yres))            return -1;        gc.psd->GetBox (gc.psd, x, y, w, h, buf);   /* ignore pitch */    }    return 0;}static int getbox (GAL_GC gc, int x, int y, int w, int h, void* buf){    return getbox_wrapper (gc, x, y, w, h, buf, w * bytesperpixel (gc));}static int scalebox (GAL_GC gc, int sw, int sh, void* srcbuf,        int dw, int dh, void* dstbuf){    return native_gen_scalebox (gc.psd, sw, sh, srcbuf, dw, dh, dstbuf);}static int copybox (GAL_GC gc, int x, int y, int w, int h, int nx, int ny){    int org_w = w, org_h = h;    if ((w <= 0) || (h <= 0)) return -1;    if (_COOR_TRANS && gc.psd == cur_gfx->phygc.psd) {        rotaterect (&x, &y, &w, &h, _ROT_DIR_CCW?gc.psd->xres:gc.psd->yres, _ROT_DIR_CCW?0:1);        rotaterect (&nx, &ny, &org_w, &org_h, _ROT_DIR_CCW?gc.psd->xres:gc.psd->yres, _ROT_DIR_CCW?0:1);    }    if ((x >= gc.psd->xres) || (x + w - 1 < 0)) return -1;    if ((y >= gc.psd->yres) || (y + h - 1 < 0)) return -1;    if (x < 0) { nx -= x; w += x; x = 0; }    if (y < 0) { ny -= y; h += y; y = 0; }    if (x + w - 1 >= gc.psd->xres) w = gc.psd->xres - x;    if (y + h - 1 >= gc.psd->yres) h = gc.psd->yres - y;            BLOCK_DRAW_SEM;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -