From 3684b749be064c6a51262c701f03f33290724ada Mon Sep 17 00:00:00 2001 From: Cedric BAIL Date: Thu, 20 Mar 2014 19:29:57 +0900 Subject: [PATCH] evas: add support for GL_LUMINANCE_ALPHA and GL_LUMINANCE when loading image from disk. --- .../evas/engines/gl_common/evas_gl_common.h | 2 +- .../evas/engines/gl_common/evas_gl_image.c | 48 +++++++++++++++++-- .../evas/engines/gl_common/evas_gl_texture.c | 37 ++++++++------ 3 files changed, 67 insertions(+), 20 deletions(-) diff --git a/src/modules/evas/engines/gl_common/evas_gl_common.h b/src/modules/evas/engines/gl_common/evas_gl_common.h index 70db622e32..12f1349e8c 100644 --- a/src/modules/evas/engines/gl_common/evas_gl_common.h +++ b/src/modules/evas/engines/gl_common/evas_gl_common.h @@ -405,7 +405,7 @@ struct _Evas_GL_Shared struct { Eina_List *whole; - Eina_List *atlas[33][3]; + Eina_List *atlas[33][5]; } tex; Eina_Hash *native_pm_hash; diff --git a/src/modules/evas/engines/gl_common/evas_gl_image.c b/src/modules/evas/engines/gl_common/evas_gl_image.c index daa975255c..a89d79deca 100644 --- a/src/modules/evas/engines/gl_common/evas_gl_image.c +++ b/src/modules/evas/engines/gl_common/evas_gl_image.c @@ -122,11 +122,18 @@ evas_gl_common_image_unref(Evas_GL_Image *im) } } +static const Evas_Colorspace known_cspace[] = { + EVAS_COLORSPACE_GRY8, + EVAS_COLORSPACE_AGRY88, + EVAS_COLORSPACE_ARGB8888 +}; + static Evas_GL_Image * _evas_gl_common_image(Evas_Engine_GL_Context *gc, RGBA_Image *im_im, Evas_Image_Load_Opts *lo, int *error) { Evas_GL_Image *im; Eina_List *l; + int cspace = EVAS_COLORSPACE_ARGB8888; /* i'd LOVe to do this, but we can't because we load to load header * to get image size to know if its too big or not! so this disallows @@ -168,17 +175,39 @@ _evas_gl_common_image(Evas_Engine_GL_Context *gc, RGBA_Image *im_im, Evas_Image_ *error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED; return NULL; } + if (im_im->cache_entry.cspaces) + { + unsigned int i; + + for (i = 0; im_im->cache_entry.cspaces[i] != EVAS_COLORSPACE_ARGB8888; i++) + { + unsigned int j; + + for (j = 0; + known_cspace[j] != EVAS_COLORSPACE_ARGB8888; + j++) + if (known_cspace[j] == im_im->cache_entry.cspaces[i]) + break; + + if (known_cspace[j] == im_im->cache_entry.cspaces[i]) + break; + } + + cspace = im_im->cache_entry.cspaces[i]; + im_im->cache_entry.space = cspace; + } + im->references = 1; im->im = im_im; im->gc = gc; im->cached = 1; - im->cs.space = EVAS_COLORSPACE_ARGB8888; + im->cs.space = cspace; im->alpha = im->im->cache_entry.flags.alpha; im->w = im->im->cache_entry.w; im->h = im->im->cache_entry.h; if (lo) im->load_opts = *lo; gc->shared->images = eina_list_prepend(gc->shared->images, im); - return im; + return im; } Evas_GL_Image * @@ -286,6 +315,8 @@ evas_gl_common_image_new_from_data(Evas_Engine_GL_Context *gc, unsigned int w, u switch (cspace) { case EVAS_COLORSPACE_ARGB8888: + case EVAS_COLORSPACE_GRY8: + case EVAS_COLORSPACE_AGRY88: break; case EVAS_COLORSPACE_YCBCR422P601_PL: case EVAS_COLORSPACE_YCBCR422P709_PL: @@ -329,6 +360,7 @@ evas_gl_common_image_new_from_copied_data(Evas_Engine_GL_Context *gc, unsigned i { case EVAS_COLORSPACE_ARGB8888: case EVAS_COLORSPACE_GRY8: + case EVAS_COLORSPACE_AGRY88: break; case EVAS_COLORSPACE_YCBCR422P601_PL: case EVAS_COLORSPACE_YCBCR422P709_PL: @@ -378,7 +410,9 @@ evas_gl_common_image_new(Evas_Engine_GL_Context *gc, unsigned int w, unsigned in switch (cspace) { case EVAS_COLORSPACE_ARGB8888: - break; + case EVAS_COLORSPACE_GRY8: + case EVAS_COLORSPACE_AGRY88: + break; case EVAS_COLORSPACE_YCBCR422P601_PL: case EVAS_COLORSPACE_YCBCR422P709_PL: case EVAS_COLORSPACE_YCBCR422601_PL: @@ -512,7 +546,9 @@ evas_gl_common_image_content_hint_set(Evas_GL_Image *im, int hint) if (!im->gc->shared->info.sec_image_map) return; if (!im->gc->shared->info.bgra) return; // does not handle yuv yet. - if (im->cs.space != EVAS_COLORSPACE_ARGB8888) return; + if (im->cs.space != EVAS_COLORSPACE_ARGB8888 || + im->cs.space != EVAS_COLORSPACE_GRY8 || + im->cs.space != EVAS_COLORSPACE_AGRY88) return; if (im->content_hint == EVAS_IMAGE_CONTENT_HINT_DYNAMIC) { if (im->cs.data) @@ -567,7 +603,7 @@ evas_gl_common_image_content_hint_set(Evas_GL_Image *im, int hint) im->im = (RGBA_Image *)evas_cache_image_empty(evas_common_image_cache_get()); im->im->cache_entry.flags.alpha = im->alpha; - im->cs.space = EVAS_COLORSPACE_ARGB8888; + im->im->cache_entry.space = im->cs.space; evas_cache_image_colorspace(&im->im->cache_entry, im->cs.space); im->im = (RGBA_Image *)evas_cache_image_size_set(&im->im->cache_entry, im->w, im->h); if (!im->tex) @@ -687,6 +723,8 @@ evas_gl_common_image_update(Evas_Engine_GL_Context *gc, Evas_GL_Image *im) switch (im->cs.space) { case EVAS_COLORSPACE_ARGB8888: + case EVAS_COLORSPACE_GRY8: + case EVAS_COLORSPACE_AGRY88: if ((im->tex) && ((im->dirty) || (ie->animated.animated) || (ie->flags.updated_data))) { diff --git a/src/modules/evas/engines/gl_common/evas_gl_texture.c b/src/modules/evas/engines/gl_common/evas_gl_texture.c index 2b379485da..8db6a8c40f 100644 --- a/src/modules/evas/engines/gl_common/evas_gl_texture.c +++ b/src/modules/evas/engines/gl_common/evas_gl_texture.c @@ -42,17 +42,21 @@ static const struct { Eina_Bool alpha; Eina_Bool bgra; + Evas_Colorspace cspace; + const GLenum *intformat; const GLenum *format; } matching_format[] = { - { EINA_TRUE, EINA_TRUE, &bgra_ifmt, &bgra_fmt }, - { EINA_TRUE, EINA_FALSE, &rgba_ifmt, &rgba_fmt }, - { EINA_FALSE, EINA_TRUE, &bgr_ifmt, &bgr_fmt }, + { EINA_TRUE, EINA_TRUE, EVAS_COLORSPACE_ARGB8888, &bgra_ifmt, &bgra_fmt }, + { EINA_TRUE, EINA_FALSE, EVAS_COLORSPACE_ARGB8888, &rgba_ifmt, &rgba_fmt }, + { EINA_FALSE, EINA_TRUE, EVAS_COLORSPACE_ARGB8888, &bgr_ifmt, &bgr_fmt }, #ifdef GL_GLES - { EINA_FALSE, EINA_FALSE, &rgba_ifmt, &rgba_fmt } + { EINA_FALSE, EINA_FALSE, EVAS_COLORSPACE_ARGB8888, &rgba_ifmt, &rgba_fmt }, #else - { EINA_FALSE, EINA_FALSE, &rgb_ifmt, &rgb_fmt } + { EINA_FALSE, EINA_FALSE, EVAS_COLORSPACE_ARGB8888, &rgb_ifmt, &rgb_fmt }, #endif + { EINA_FALSE, EINA_FALSE, EVAS_COLORSPACE_GRY8, &lum_fmt, &lum_ifmt }, + { EINA_TRUE, EINA_FALSE, EVAS_COLORSPACE_AGRY88, &lum_alpha_fmt, &lum_alpha_ifmt } }; static const GLenum matching_rgba[] = { GL_RGBA4, GL_RGBA8, GL_RGBA12, GL_RGBA16, 0x0 }; @@ -92,7 +96,7 @@ _evas_gl_texture_match(GLenum intfmt, GLenum intfmtret) } static int -_evas_gl_texture_search_format(Eina_Bool alpha, Eina_Bool bgra) +_evas_gl_texture_search_format(Eina_Bool alpha, Eina_Bool bgra, Evas_Colorspace cspace) { unsigned int i; @@ -101,7 +105,8 @@ _evas_gl_texture_search_format(Eina_Bool alpha, Eina_Bool bgra) for (i = 0; i < sizeof (matching_format) / sizeof (matching_format[0]); ++i) if (matching_format[i].alpha == alpha && - matching_format[i].bgra == bgra) + matching_format[i].bgra == bgra && + matching_format[i].cspace == cspace) return i; abort(); @@ -188,7 +193,11 @@ _tex_format_index(GLuint format) case GL_LUMINANCE12: case GL_LUMINANCE16: return 3; - // XXX: luminance_alpha not supported at all + case GL_LUMINANCE4_ALPHA4: + case GL_LUMINANCE8_ALPHA8: + case GL_LUMINANCE12_ALPHA12: + case GL_LUMINANCE16_ALPHA16: + return 4; default: return 0; } @@ -430,7 +439,7 @@ evas_gl_common_texture_new(Evas_Engine_GL_Context *gc, RGBA_Image *im) #define TEX_HREP 1 #define TEX_VREP 1 - lformat = _evas_gl_texture_search_format(im->cache_entry.flags.alpha, gc->shared->info.bgra); + lformat = _evas_gl_texture_search_format(im->cache_entry.flags.alpha, gc->shared->info.bgra, im->cache_entry.space); tex->pt = _pool_tex_find(gc, im->cache_entry.w + TEX_HREP + 2, im->cache_entry.h + TEX_VREP, @@ -841,7 +850,7 @@ evas_gl_common_texture_native_new(Evas_Engine_GL_Context *gc, unsigned int w, un tex = evas_gl_common_texture_alloc(gc, w, h, alpha); if (!tex) return NULL; - lformat = _evas_gl_texture_search_format(alpha, gc->shared->info.bgra); + lformat = _evas_gl_texture_search_format(alpha, gc->shared->info.bgra, EVAS_COLORSPACE_ARGB8888); tex->pt = _pool_tex_native_new(gc, w, h, *matching_format[lformat].intformat, *matching_format[lformat].format, @@ -864,7 +873,7 @@ evas_gl_common_texture_render_new(Evas_Engine_GL_Context *gc, unsigned int w, un tex = evas_gl_common_texture_alloc(gc, w, h, alpha); if (!tex) return NULL; - lformat = _evas_gl_texture_search_format(alpha, gc->shared->info.bgra); + lformat = _evas_gl_texture_search_format(alpha, gc->shared->info.bgra, EVAS_COLORSPACE_ARGB8888); tex->pt = _pool_tex_render_new(gc, w, h, *matching_format[lformat].intformat, *matching_format[lformat].format); @@ -886,7 +895,7 @@ evas_gl_common_texture_dynamic_new(Evas_Engine_GL_Context *gc, Evas_GL_Image *im tex = evas_gl_common_texture_alloc(gc, im->w, im->h, im->alpha); if (!tex) return NULL; - lformat = _evas_gl_texture_search_format(tex->alpha, gc->shared->info.bgra); + lformat = _evas_gl_texture_search_format(tex->alpha, gc->shared->info.bgra, EVAS_COLORSPACE_ARGB8888); tex->pt = _pool_tex_dynamic_new(gc, tex->w, tex->h, *matching_format[lformat].intformat, *matching_format[lformat].format); @@ -912,7 +921,7 @@ evas_gl_common_texture_update(Evas_GL_Texture *tex, RGBA_Image *im) pt_unref(tex->pt); tex->alpha = im->cache_entry.flags.alpha; - lformat = _evas_gl_texture_search_format(tex->alpha, tex->gc->shared->info.bgra); + lformat = _evas_gl_texture_search_format(tex->alpha, tex->gc->shared->info.bgra, im->cache_entry.space); // FIXME: why a 'render' new here ??? tex->pt = _pool_tex_render_new(tex->gc, tex->w, tex->h, *matching_format[lformat].intformat, @@ -953,7 +962,7 @@ evas_gl_common_texture_update(Evas_GL_Texture *tex, RGBA_Image *im) // out is a miniature of the texture, upload that now and schedule the data for later. // Creating the mini picture texture - lformat = _evas_gl_texture_search_format(tex->alpha, tex->gc->shared->info.bgra); + lformat = _evas_gl_texture_search_format(tex->alpha, tex->gc->shared->info.bgra, im->cache_entry.space); tex->ptt = _pool_tex_find(tex->gc, EVAS_GL_TILE_SIZE, EVAS_GL_TILE_SIZE, *matching_format[lformat].intformat, *matching_format[lformat].format,