Create texture_image_color_convert

This commit is contained in:
twinaphex 2015-05-04 10:16:47 +02:00
parent ef98d02185
commit 0704c7f0c7
2 changed files with 30 additions and 11 deletions

View File

@ -62,18 +62,10 @@ bool texture_image_set_color_shifts(unsigned *r_shift, unsigned *g_shift,
return use_rgba; return use_rgba;
} }
#ifdef HAVE_RPNG bool texture_image_color_convert(unsigned r_shift,
static bool rpng_image_load_argb_shift(const char *path, unsigned g_shift, unsigned b_shift, unsigned a_shift,
struct texture_image *out_img, struct texture_image *out_img)
unsigned a_shift, unsigned r_shift,
unsigned g_shift, unsigned b_shift)
{ {
bool ret = rpng_load_image_argb(path,
&out_img->pixels, &out_img->width, &out_img->height);
if (!ret)
return false;
/* This is quite uncommon. */ /* This is quite uncommon. */
if (a_shift != 24 || r_shift != 16 || g_shift != 8 || b_shift != 0) if (a_shift != 24 || r_shift != 16 || g_shift != 8 || b_shift != 0)
{ {
@ -91,8 +83,28 @@ static bool rpng_image_load_argb_shift(const char *path,
pixels[i] = (a << a_shift) | pixels[i] = (a << a_shift) |
(r << r_shift) | (g << g_shift) | (b << b_shift); (r << r_shift) | (g << g_shift) | (b << b_shift);
} }
return true;
} }
return false;
}
#ifdef HAVE_RPNG
static bool rpng_image_load_argb_shift(const char *path,
struct texture_image *out_img,
unsigned a_shift, unsigned r_shift,
unsigned g_shift, unsigned b_shift)
{
bool ret = rpng_load_image_argb(path,
&out_img->pixels, &out_img->width, &out_img->height);
if (!ret)
return false;
texture_image_color_convert(r_shift, g_shift, b_shift,
a_shift, out_img);
return true; return true;
} }
#endif #endif

View File

@ -41,6 +41,13 @@ struct texture_image
uint32_t *pixels; uint32_t *pixels;
}; };
bool texture_image_set_color_shifts(unsigned *r_shift, unsigned *g_shift,
unsigned *b_shift, unsigned *a_shift);
bool texture_image_color_convert(unsigned r_shift,
unsigned g_shift, unsigned b_shift, unsigned a_shift,
struct texture_image *out_img);
bool texture_image_load(struct texture_image *img, const char *path); bool texture_image_load(struct texture_image *img, const char *path);
void texture_image_free(struct texture_image *img); void texture_image_free(struct texture_image *img);