From e47dbc02ea75f5976aa08c137c2cd92491c5dc8f Mon Sep 17 00:00:00 2001 From: Cedric BAIL Date: Mon, 17 Mar 2014 19:28:22 +0900 Subject: [PATCH] evas: let TGV loader choose which encoding it want. If region is specified we will not allow ETC1 colorspace as it would basically break at the frontier as we would be unable to generate a duplicate of the border as GPU require if you want nice and correct rendering. So no region and ETC1 output at the same time. --- .../evas/loaders/tgv/evas_image_load_tgv.c | 51 ++++++++++++++----- 1 file changed, 39 insertions(+), 12 deletions(-) diff --git a/src/modules/evas/loaders/tgv/evas_image_load_tgv.c b/src/modules/evas/loaders/tgv/evas_image_load_tgv.c index 308d0b6f22..36a2fdfdc9 100644 --- a/src/modules/evas/loaders/tgv/evas_image_load_tgv.c +++ b/src/modules/evas/loaders/tgv/evas_image_load_tgv.c @@ -58,6 +58,10 @@ struct _Evas_Loader_Internal Eina_Bool compress; }; +static const Evas_Colorspace cspaces[2] = { + EVAS_COLORSPACE_ETC1, + EVAS_COLORSPACE_ARGB8888 +}; static void * evas_image_load_file_open_tgv(Eina_File *f, Eina_Stringshare *key EINA_UNUSED, @@ -162,6 +166,7 @@ evas_image_load_file_head_tgv(void *loader_data, { loader->region.w = loader->size.width; loader->region.h = loader->size.height; + prop->cspaces = cspaces; // ETC1 colorspace doesn't work with region } else { @@ -218,6 +223,7 @@ evas_image_load_file_data_tgv(void *loader_data, unsigned int length, offset; unsigned int x, y; unsigned int block_count; + unsigned int etc1_width = 0; Eina_Bool r = EINA_FALSE; length = eina_file_size_get(loader->f); @@ -233,6 +239,15 @@ evas_image_load_file_data_tgv(void *loader_data, loader->region.x, loader->region.y, prop->w, prop->h); + if (prop->cspace == EVAS_COLORSPACE_ETC1) + { + if (master.x % 4 || + master.y % 4) + abort(); + + etc1_width = (prop->w / 4 + (prop->w % 4 ? 1 : 0)) * 8; + } + // Allocate space for each ETC1 block (64bytes per 4 * 4 pixels group) block_count = loader->block.width * loader->block.height / (4 * 4); if (loader->compress) @@ -291,20 +306,32 @@ evas_image_load_file_data_tgv(void *loader_data, if (!eina_rectangle_intersection(¤t_etc, ¤t)) continue ; - if (!rg_etc1_unpack_block(it, temporary, 0)) + switch (prop->cspace) { - fprintf(stderr, "HOUSTON WE HAVE A PROBLEM ! Block starting at {%i, %i} is corrupted !\n", x + j, y + i); - continue ; - } + case EVAS_COLORSPACE_ARGB8888: + if (!rg_etc1_unpack_block(it, temporary, 0)) + { + fprintf(stderr, "HOUSTON WE HAVE A PROBLEM ! Block starting at {%i, %i} is corrupted !\n", x + j, y + i); + continue ; + } - offset_x = current_etc.x - x - j; - offset_y = current_etc.y - y - i; - for (k = 0; k < current_etc.h; k++) - { - memcpy(&p[current_etc.x + - (current_etc.y + k) * loader->region.w], - &temporary[offset_x + (offset_y + k) * 4], - current_etc.w * sizeof (unsigned int)); + offset_x = current_etc.x - x - j; + offset_y = current_etc.y - y - i; + for (k = 0; k < current_etc.h; k++) + { + memcpy(&p[current_etc.x + + (current_etc.y + k) * master.w], + &temporary[offset_x + (offset_y + k) * 4], + current_etc.w * sizeof (unsigned int)); + } + break; + case EVAS_COLORSPACE_ETC1: + memcpy(&p[current_etc.x + + current_etc.y * etc1_width], + it, 8); + break; + default: + abort(); } } }