1 #include "evas_common.h"
2 #include "evas_engine.h"
6 evas_buffer_outbuf_buf_init(void)
11 evas_buffer_outbuf_buf_free(Outbuf *buf)
13 if (buf->priv.back_buf)
15 evas_cache_image_drop(&buf->priv.back_buf->cache_entry);
21 evas_buffer_outbuf_buf_setup_fb(int w, int h, Outbuf_Depth depth, void *dest, int dest_row_bytes, int use_color_key, DATA32 color_key, int alpha_level,
22 void * (*new_update_region) (int x, int y, int w, int h, int *row_bytes),
23 void (*free_update_region) (int x, int y, int w, int h, void *data)
30 buf = calloc(1, sizeof(Outbuf));
31 if (!buf) return NULL;
38 buf->dest_row_bytes = dest_row_bytes;
40 buf->alpha_level = alpha_level;
41 buf->color_key = color_key;
42 buf->use_color_key = use_color_key;
44 buf->func.new_update_region = new_update_region;
45 buf->func.free_update_region = free_update_region;
48 if ((buf->depth == OUTBUF_DEPTH_RGB_24BPP_888_888) ||
49 (buf->depth == OUTBUF_DEPTH_BGR_24BPP_888_888))
52 if ((buf->depth == OUTBUF_DEPTH_ARGB_32BPP_8888_8888) &&
53 (buf->dest) && (buf->dest_row_bytes == (buf->w * sizeof(DATA32))))
55 for (y = 0; y < h; y++)
56 memset(((unsigned char *)(buf->dest)) + (y * buf->dest_row_bytes),
58 buf->priv.back_buf = (RGBA_Image *) evas_cache_image_data(evas_common_image_cache_get(),
61 1, EVAS_COLORSPACE_ARGB8888);
63 else if ((buf->depth == OUTBUF_DEPTH_RGB_32BPP_888_8888) &&
64 (buf->dest) && (buf->dest_row_bytes == (buf->w * sizeof(DATA32))))
66 buf->priv.back_buf = (RGBA_Image *) evas_cache_image_data(evas_common_image_cache_get(),
69 0, EVAS_COLORSPACE_ARGB8888);
76 evas_buffer_outbuf_buf_new_region_for_update(Outbuf *buf, int x, int y, int w, int h, int *cx, int *cy, int *cw, int *ch)
81 if (buf->priv.back_buf)
83 *cx = x; *cy = y; *cw = w; *ch = h;
84 if (buf->priv.back_buf->cache_entry.flags.alpha)
87 ptr = buf->priv.back_buf->image.data + (y * buf->priv.back_buf->cache_entry.w) + x;
93 ptr += (buf->priv.back_buf->cache_entry.w - w);
96 return buf->priv.back_buf;
100 *cx = 0; *cy = 0; *cw = w; *ch = h;
101 im = (RGBA_Image *) evas_cache_image_empty(evas_common_image_cache_get());
104 if (((buf->depth == OUTBUF_DEPTH_ARGB_32BPP_8888_8888)) ||
105 ((buf->depth == OUTBUF_DEPTH_BGRA_32BPP_8888_8888)))
107 im->cache_entry.flags.alpha = 1;
108 im = (RGBA_Image *) evas_cache_image_size_set(&im->cache_entry, w, h);
111 memset(im->image.data, 0, w * h * sizeof(DATA32));
120 evas_buffer_outbuf_buf_free_region_for_update(Outbuf *buf, RGBA_Image *update)
122 if (update != buf->priv.back_buf) evas_cache_image_drop(&update->cache_entry);
126 evas_buffer_outbuf_buf_push_updated_region(Outbuf *buf, RGBA_Image *update, int x, int y, int w, int h)
128 /* copy update image to out buf & convert */
131 case OUTBUF_DEPTH_RGB_24BPP_888_888:
132 /* copy & pack into 24bpp - if colorkey is enabled... etc. */
142 colorkey = buf->color_key;
143 thresh = buf->alpha_level;
144 row_bytes = buf->dest_row_bytes;
145 dest = (DATA8 *)(buf->dest) + (y * row_bytes) + (x * 3);
146 if (buf->func.new_update_region)
148 dest = buf->func.new_update_region(x, y, w, h, &row_bytes);
151 if (buf->use_color_key)
153 for (yy = 0; yy < h; yy++)
155 dst = dest + (yy * row_bytes);
156 src = update->image.data + (yy * update->cache_entry.w);
157 for (xx = 0; xx < w; xx++)
159 if (A_VAL(src) > thresh)
167 *dst++ = R_VAL(&colorkey);
168 *dst++ = G_VAL(&colorkey);
169 *dst++ = B_VAL(&colorkey);
177 for (yy = 0; yy < h; yy++)
179 dst = dest + (yy * row_bytes);
180 src = update->image.data + (yy * update->cache_entry.w);
181 for (xx = 0; xx < w; xx++)
190 if (buf->func.free_update_region)
192 buf->func.free_update_region(x, y, w, h, dest);
196 case OUTBUF_DEPTH_BGR_24BPP_888_888:
197 /* copy & pack into 24bpp - if colorkey is enabled... etc. */
207 colorkey = buf->color_key;
208 thresh = buf->alpha_level;
209 row_bytes = buf->dest_row_bytes;
210 dest = (DATA8 *)(buf->dest) + (y * row_bytes) + (x * 3);
211 if (buf->func.new_update_region)
213 dest = buf->func.new_update_region(x, y, w, h, &row_bytes);
216 if (buf->use_color_key)
218 for (yy = 0; yy < h; yy++)
220 dst = dest + (yy * row_bytes);
221 src = update->image.data + (yy * update->cache_entry.w);
222 for (xx = 0; xx < w; xx++)
224 if (A_VAL(src) > thresh)
232 *dst++ = B_VAL(&colorkey);
233 *dst++ = G_VAL(&colorkey);
234 *dst++ = R_VAL(&colorkey);
242 for (yy = 0; yy < h; yy++)
244 dst = dest + (yy * row_bytes);
245 src = update->image.data + (yy * update->cache_entry.w);
246 for (xx = 0; xx < w; xx++)
255 if (buf->func.free_update_region)
257 buf->func.free_update_region(x, y, w, h, dest);
261 case OUTBUF_DEPTH_RGB_32BPP_888_8888:
262 case OUTBUF_DEPTH_ARGB_32BPP_8888_8888:
264 DATA32 *dest, *src, *dst;
267 row_bytes = buf->dest_row_bytes;
268 dest = (DATA8 *)(buf->dest) + (y * row_bytes) + (x * 4);
269 if (buf->func.new_update_region)
271 dest = buf->func.new_update_region(x, y, w, h, &row_bytes);
273 /* no need src == dest */
274 if (!buf->priv.back_buf)
278 func = evas_common_draw_func_copy_get(w, 0);
281 for (yy = 0; yy < h; yy++)
283 src = update->image.data + (yy * update->cache_entry.w);
284 dst = (DATA8 *)(buf->dest) + ((y + yy) * row_bytes);
290 if (buf->func.free_update_region)
292 buf->func.free_update_region(x, y, w, h, dest);
296 case OUTBUF_DEPTH_BGR_32BPP_888_8888:
300 int xx, yy, row_bytes;
302 row_bytes = buf->dest_row_bytes;
303 dest = (DATA8 *)(buf->dest) + (y * row_bytes) + (x * 4);
304 if (buf->func.new_update_region)
306 dest = buf->func.new_update_region(x, y, w, h, &row_bytes);
308 for (yy = 0; yy < h; yy++)
310 dst = dest + (yy * row_bytes);
311 src = update->image.data + (yy * update->cache_entry.w);
312 for (xx = 0; xx < w; xx++)
314 A_VAL(dst) = B_VAL(src);
315 R_VAL(dst) = G_VAL(src);
316 G_VAL(dst) = R_VAL(src);
321 if (buf->func.free_update_region)
323 buf->func.free_update_region(x, y, w, h, dest);
327 case OUTBUF_DEPTH_BGRA_32BPP_8888_8888:
331 int xx, yy, row_bytes;
333 row_bytes = buf->dest_row_bytes;
334 dest = (DATA8 *)(buf->dest) + (y * row_bytes) + (x * 4);
335 if (buf->func.new_update_region)
337 dest = buf->func.new_update_region(x, y, w, h, &row_bytes);
339 for (yy = 0; yy < h; yy++)
341 dst = dest + (yy * row_bytes);
342 src = update->image.data + (yy * update->cache_entry.w);
343 for (xx = 0; xx < w; xx++)
345 A_VAL(dst) = B_VAL(src);
346 R_VAL(dst) = G_VAL(src);
347 G_VAL(dst) = R_VAL(src);
352 if (buf->func.free_update_region)
354 buf->func.free_update_region(x, y, w, h, dest);