X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?p=dosdemo;a=blobdiff_plain;f=tools%2Fcsprite%2Fsrc%2Fimage.c;h=84bad815de78e5318ce09d11dd255d7ada605319;hp=18e8609efbac78b389e7276b97cba496e285e78a;hb=bebb02a472ecf3ba95366bbd3934478433cd9498;hpb=02d3f6c78597600d2b100748aa54241228b9ca09 diff --git a/tools/csprite/src/image.c b/tools/csprite/src/image.c index 18e8609..84bad81 100644 --- a/tools/csprite/src/image.c +++ b/tools/csprite/src/image.c @@ -1,5 +1,6 @@ #include #include +#include #include #include #include @@ -186,6 +187,51 @@ int save_image(struct image *img, const char *fname) return 0; } +int conv_image_rgb565(struct image *img16, struct image *img) +{ + int i, j; + uint16_t *dptr; + unsigned char *sptr; + + if(!img->cmap_ncolors && img->bpp < 24) { + fprintf(stderr, "unsupported conversion from %dbpp to 16bpp 565\n", img->bpp); + return -1; + } + + img16->width = img->width; + img16->height = img->height; + img16->nchan = img->nchan; + img16->bpp = 16; + img16->scansz = img16->pitch = img->width * 2; + if(!(img16->pixels = malloc(img16->height * img16->scansz))) { + return -1; + } + + sptr = img->pixels; + dptr = (uint16_t*)img16->pixels; + + for(i=0; iheight; i++) { + for(j=0; jwidth; j++) { + unsigned int r, g, b; + if(img->bpp <= 8 && img->cmap_ncolors) { + int idx = *sptr++ % img->cmap_ncolors; + r = img->cmap[idx].r >> 3; + g = img->cmap[idx].g >> 2; + b = img->cmap[idx].b >> 3; + } else if(img->nchan == 1) { + g = (*sptr++ >> 2) & 0x3f; + r = b = g >> 1; + } else { + r = (*sptr++ >> 3) & 0x1f; + g = (*sptr++ >> 2) & 0x3f; + b = (*sptr++ >> 3) & 0x1f; + } + *dptr++ = (r << 11) | (g << 5) | b; + } + } + return 0; +} + int cmp_image(struct image *a, struct image *b) {