image: add image_linear_alloc()

This commit is contained in:
Lephe 2022-05-15 13:26:59 +01:00
parent 09c13676d3
commit c2ff07427b
No known key found for this signature in database
GPG key ID: 1BBA026E13FC0495
3 changed files with 23 additions and 0 deletions

View file

@ -176,6 +176,7 @@ set(SOURCES_CG
src/image/image_hflip_alloc.c
src/image/image_linear.c
src/image/image_linear.S
src/image/image_linear_alloc.c
src/image/image_rotate.c
src/image/image_rotate_around.c
src/image/image_rotate_around_scale.c

View file

@ -6,6 +6,8 @@ bool image_copy_palette(image_t const *src, image_t *dst, int size)
{
if(!image_valid(src) || !dst)
return false;
if(!IMAGE_IS_INDEXED(dst->format))
return true;
if(size < 0)
size = src->color_count;

View file

@ -0,0 +1,20 @@
#include <gint/image.h>
image_t *image_linear_alloc(image_t const *src, struct image_linear_map *map)
{
if(!image_valid(src) || IMAGE_IS_P4(src->format))
return NULL;
int f = IMAGE_IS_RGB16(src->format) ? IMAGE_RGB565A : IMAGE_P8_RGB565A;
image_t *dst = image_alloc(map->dst_w, map->dst_h, f);
if(!dst)
return NULL;
if(f == IMAGE_P8_RGB565A && !image_copy_palette(src, dst, -1)) {
image_free(dst);
return NULL;
}
image_clear(dst);
image_linear(src, dst, map);
return dst;
}