1 #include "evas_gl_private.h"
4 evas_gl_common_image_load(Evas_GL_Context *gc, const char *file, const char *key, Evas_Image_Load_Opts *lo)
10 im_im = evas_common_load_image_from_file(file, key, lo);
11 if (!im_im) return NULL;
13 for (l = gc->images; l; l = l->next)
18 evas_cache_image_drop(&im_im->cache_entry);
19 gc->images = evas_list_remove_list(gc->images, l);
20 gc->images = evas_list_prepend(gc->images, im);
26 im = calloc(1, sizeof(Evas_GL_Image));
38 im->cs.space = EVAS_COLORSPACE_ARGB8888;
39 if (lo) im->load_opts = *lo;
40 gc->images = evas_list_prepend(gc->images, im);
45 evas_gl_common_image_new_from_data(Evas_GL_Context *gc, int w, int h, DATA32 *data, int alpha, int cspace)
50 for (l = gc->images; l; l = l->next)
53 if (((void *)(im->im->image.data) == (void *)data) &&
54 (im->im->cache_entry.w == w) &&
55 (im->im->cache_entry.h == h))
57 gc->images = evas_list_remove_list(gc->images, l);
58 gc->images = evas_list_prepend(gc->images, im);
63 im = calloc(1, sizeof(Evas_GL_Image));
66 im->im = (RGBA_Image *) evas_cache_image_data(evas_common_image_cache_get(),
67 w, h, data, alpha, cspace);
74 im->cs.space = cspace;
77 case EVAS_COLORSPACE_ARGB8888:
79 case EVAS_COLORSPACE_YCBCR422P601_PL:
80 case EVAS_COLORSPACE_YCBCR422P709_PL:
81 if (im->tex) evas_gl_common_texture_free(im->tex);
92 gc->images = evas_list_prepend(gc->images, im);
94 printf("new im cs = %i\n", im->cs.space);
99 evas_gl_common_image_new_from_copied_data(Evas_GL_Context *gc, int w, int h, DATA32 *data, int alpha, int cspace)
103 im = calloc(1, sizeof(Evas_GL_Image));
104 if (!im) return NULL;
106 im->im = (RGBA_Image *) evas_cache_image_copied_data(evas_common_image_cache_get(),
107 w, h, data, alpha, cspace);
114 im->cs.space = cspace;
117 case EVAS_COLORSPACE_ARGB8888:
119 case EVAS_COLORSPACE_YCBCR422P601_PL:
120 case EVAS_COLORSPACE_YCBCR422P709_PL:
121 if (im->tex) evas_gl_common_texture_free(im->tex);
124 im->cs.data = calloc(1, im->im->cache_entry.h * sizeof(unsigned char *) * 2);
125 if ((data) && (im->cs.data))
126 memcpy(im->cs.data, data, im->im->cache_entry.h * sizeof(unsigned char *) * 2);
136 evas_gl_common_image_new(Evas_GL_Context *gc, int w, int h, int alpha, int cspace)
140 im = calloc(1, sizeof(Evas_GL_Image));
141 if (!im) return NULL;
143 im->im = (RGBA_Image *) evas_cache_image_empty(evas_common_image_cache_get());
150 im->cs.space = cspace;
151 im->im->cache_entry.flags.alpha = alpha ? 1 : 0;
152 evas_cache_image_colorspace(&im->im->cache_entry, cspace);
153 im->im = (RGBA_Image *) evas_cache_image_size_set(&im->im->cache_entry, w, h);
156 case EVAS_COLORSPACE_ARGB8888:
158 case EVAS_COLORSPACE_YCBCR422P601_PL:
159 case EVAS_COLORSPACE_YCBCR422P709_PL:
160 // if (im->tex) evas_gl_common_texture_free(im->tex);
163 im->cs.data = calloc(1, im->im->cache_entry.h * sizeof(unsigned char *) * 2);
173 evas_gl_common_image_free(Evas_GL_Image *im)
176 if (im->references > 0) return;
180 if (!im->cs.no_free) free(im->cs.data);
182 if (im->cached) im->gc->images = evas_list_remove(im->gc->images, im);
183 if (im->im) evas_cache_image_drop(&im->im->cache_entry);
184 if (im->tex) evas_gl_common_texture_free(im->tex);
189 evas_gl_common_image_dirty(Evas_GL_Image *im)
191 im->im = (RGBA_Image *) evas_cache_image_dirty(&im->im->cache_entry, 0, 0, im->im->cache_entry.w, im->im->cache_entry.h);
196 evas_gl_common_image_draw(Evas_GL_Context *gc, Evas_GL_Image *im, int sx, int sy, int sw, int sh, int dx, int dy, int dw, int dh, int smooth)
198 RGBA_Draw_Context *dc;
200 double tx1, ty1, tx2, ty2;
209 a = (dc->mul.col >> 24) & 0xff;
210 r = (dc->mul.col >> 16) & 0xff;
211 g = (dc->mul.col >> 8 ) & 0xff;
212 b = (dc->mul.col ) & 0xff;
219 if (!gc->ext.arb_program && (im->cs.space == EVAS_COLORSPACE_YCBCR422P601_PL
220 || im->cs.space == EVAS_COLORSPACE_YCBCR422P709_PL))
222 if ((im->cs.data) && (*((unsigned char **)im->cs.data)))
224 if (im->dirty || !im->im->image.data)
226 free(im->im->image.data);
227 im->im->image.data = malloc(im->im->cache_entry.w * im->im->cache_entry.h * sizeof(DATA32));
228 if (im->im->image.data)
229 evas_common_convert_yuv_420p_601_rgba(im->cs.data,
230 (void *)im->im->image.data,
231 im->im->cache_entry.w, im->im->cache_entry.h);
234 space = EVAS_COLORSPACE_ARGB8888;
237 space = im->cs.space;
239 /* leak in this switch */
242 case EVAS_COLORSPACE_ARGB8888:
243 evas_cache_image_load_data(&im->im->cache_entry);
244 if ((im->tex) && (im->dirty))
246 evas_gl_common_texture_update(im->tex, im->im, im->tex->smooth);
250 im->tex = evas_gl_common_texture_new(gc, im->im, smooth);
251 ow = (dw * im->tex->tw) / sw;
252 oh = (dh * im->tex->th) / sh;
253 if (im->tex->rectangle)
262 tx1 = (double)(sx ) / (double)(im->tex->w);
263 ty1 = (double)(sy ) / (double)(im->tex->h);
264 tx2 = (double)(sx + sw) / (double)(im->tex->w);
265 ty2 = (double)(sy + sh) / (double)(im->tex->h);
267 evas_gl_common_context_texture_set(gc, im->tex, smooth, ow, oh);
269 case EVAS_COLORSPACE_YCBCR422P601_PL:
270 case EVAS_COLORSPACE_YCBCR422P709_PL:
271 if ((im->tex) && (im->dirty))
273 evas_gl_common_ycbcr601pl_texture_update(im->tex, im->cs.data, im->im->cache_entry.w, im->im->cache_entry.h, smooth);
276 if ((!im->tex) && (im->cs.data) && (*((unsigned char **)im->cs.data)))
278 im->tex = evas_gl_common_ycbcr601pl_texture_new(gc, im->cs.data, im->im->cache_entry.w, im->im->cache_entry.h, smooth);
280 if (!im->tex) return;
281 ow = (dw * im->tex->tw) / sw;
282 oh = (dh * im->tex->th) / sh;
283 if (im->tex->rectangle)
292 tx1 = (double)(sx ) / (double)(im->tex->w);
293 ty1 = (double)(sy ) / (double)(im->tex->h);
294 tx2 = (double)(sx + sw) / (double)(im->tex->w);
295 ty2 = (double)(sy + sh) / (double)(im->tex->h);
297 evas_gl_common_context_texture_set(gc, im->tex, smooth, ow, oh);
305 // if ((!im->tex->have_mipmaps) && (smooth) &&
306 // ((im->tex->uw < im->tex->tw) || (im->tex->uh < im->tex->th)) &&
307 // (!gc->ext.sgis_generate_mipmap))
308 // evas_gl_common_texture_mipmaps_build(im->tex, im->im, smooth);
310 evas_gl_common_context_color_set(gc, r, g, b, a);
311 if ((a < 255) || im->im->cache_entry.flags.alpha)
312 evas_gl_common_context_blend_set(gc, 1);
313 else evas_gl_common_context_blend_set(gc, 0);
315 evas_gl_common_context_clip_set(gc, 1,
316 dc->clip.x, dc->clip.y,
317 dc->clip.w, dc->clip.h);
319 evas_gl_common_context_clip_set(gc, 0,
321 evas_gl_common_context_read_buf_set(gc, GL_BACK);
322 evas_gl_common_context_write_buf_set(gc, GL_BACK);
325 glTexCoord2d(tx1, ty1); glVertex2i(dx , dy );
326 glTexCoord2d(tx2, ty1); glVertex2i(dx + dw, dy );
327 glTexCoord2d(tx2, ty2); glVertex2i(dx + dw, dy + dh);
328 glTexCoord2d(tx1, ty2); glVertex2i(dx , dy + dh);