X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;f=libs%2Fimago%2Fsrc%2Fconv.c;h=501b3c4758ce9d1b61b89e2ffbf9e19adb458810;hb=refs%2Fheads%2Fmaster;hp=bd7fb2d3600ad9ff10f85e575f14706071020492;hpb=046fa888e4df754a20736303c27f497163edf4db;p=eradicate diff --git a/libs/imago/src/conv.c b/libs/imago/src/conv.c index bd7fb2d..501b3c4 100644 --- a/libs/imago/src/conv.c +++ b/libs/imago/src/conv.c @@ -32,6 +32,7 @@ struct pixel { static void unpack_grey8(struct pixel *unp, void *pptr, int count); static void unpack_rgb24(struct pixel *unp, void *pptr, int count); static void unpack_rgba32(struct pixel *unp, void *pptr, int count); +static void unpack_bgra32(struct pixel *unp, void *pptr, int count); static void unpack_greyf(struct pixel *unp, void *pptr, int count); static void unpack_rgbf(struct pixel *unp, void *pptr, int count); static void unpack_rgbaf(struct pixel *unp, void *pptr, int count); @@ -40,6 +41,7 @@ static void unpack_rgb565(struct pixel *unp, void *pptr, int count); static void pack_grey8(void *pptr, struct pixel *unp, int count); static void pack_rgb24(void *pptr, struct pixel *unp, int count); static void pack_rgba32(void *pptr, struct pixel *unp, int count); +static void pack_bgra32(void *pptr, struct pixel *unp, int count); static void pack_greyf(void *pptr, struct pixel *unp, int count); static void pack_rgbf(void *pptr, struct pixel *unp, int count); static void pack_rgbaf(void *pptr, struct pixel *unp, int count); @@ -50,6 +52,7 @@ static void (*unpack[])(struct pixel*, void*, int) = { unpack_grey8, unpack_rgb24, unpack_rgba32, + unpack_bgra32, unpack_greyf, unpack_rgbf, unpack_rgbaf, @@ -61,6 +64,7 @@ static void (*pack[])(void*, struct pixel*, int) = { pack_grey8, pack_rgb24, pack_rgba32, + pack_bgra32, pack_greyf, pack_rgbf, pack_rgbaf, @@ -145,6 +149,20 @@ static void unpack_rgba32(struct pixel *unp, void *pptr, int count) } } +static void unpack_bgra32(struct pixel *unp, void *pptr, int count) +{ + int i; + unsigned char *pix = pptr; + + for(i=0; ib = (float)*pix++ / 255.0; + unp->g = (float)*pix++ / 255.0; + unp->r = (float)*pix++ / 255.0; + unp->a = (float)*pix++ / 255.0; + unp++; + } +} + static void unpack_greyf(struct pixel *unp, void *pptr, int count) { int i; @@ -192,12 +210,12 @@ static void unpack_rgb565(struct pixel *unp, void *pptr, int count) for(i=0; i> 2) & 0xfc; if(g & 4) g |= 3; /* ditto */ - b = (p >> 8) & 0xf8; - if(b & 8) r |= 7; /* same */ + r = (p >> 8) & 0xf8; + if(r & 8) r |= 7; /* same */ unp->r = (float)r / 255.0f; unp->g = (float)g / 255.0f; @@ -256,6 +274,25 @@ static void pack_rgba32(void *pptr, struct pixel *unp, int count) } } +static void pack_bgra32(void *pptr, struct pixel *unp, int count) +{ + int i; + unsigned char *pix = pptr; + + for(i=0; ir * 255.0); + int g = (int)(unp->g * 255.0); + int b = (int)(unp->b * 255.0); + int a = (int)(unp->a * 255.0); + + *pix++ = CLAMP(b, 0, 255); + *pix++ = CLAMP(g, 0, 255); + *pix++ = CLAMP(r, 0, 255); + *pix++ = CLAMP(a, 0, 255); + unp++; + } +} + static void pack_greyf(void *pptr, struct pixel *unp, int count) { int i; @@ -292,13 +329,13 @@ static void pack_rgb565(void *pptr, struct pixel *unp, int count) uint16_t *pix = pptr; for(i=0; ir * 255.0f); - uint16_t g = (uint16_t)(unp->g * 255.0f); - uint16_t b = (uint16_t)(unp->b * 255.0f); - if(r > 255) r = 255; - if(g > 255) g = 255; - if(b > 255) b = 255; - *pix++ = (r >> 3) | ((g & 0x3f) << 2) | ((b & 0x1f) << 8); + uint16_t r = (uint16_t)(unp->r * 31.0f); + uint16_t g = (uint16_t)(unp->g * 63.0f); + uint16_t b = (uint16_t)(unp->b * 31.0f); + if(r > 31) r = 31; + if(g > 63) g = 63; + if(b > 31) b = 31; + *pix++ = (r << 11) | (g << 5) | b; unp++; } }