// TODO this needs more work, must pause to be thread safe, factor out task->value = other->value //. wait: wait for a task to complete, will return its result or throw its error static tlHandle _task_wait(tlTask* task, tlArgs* args) { tlTask* other = tlTaskAs(tlArgsTarget(args)); if (!other) TL_THROW("expected a Task"); trace("task.wait: %s", tl_str(other)); if (tlTaskIsDone(other)) { tlTaskCopyValue(task, other); if (tlTaskHasError(task)) return tlTaskError(task, task->value); assert(task->value); return task->value; } trace("!! parking"); tlArray* deadlock = tlTaskWaitFor(task, other); if (deadlock) return tlDeadlockErrorThrow(task, deadlock); tlHandle already_waiting = A_PTR(a_swap_if(A_VAR(other->waiting), A_VAL(task), 0)); if (already_waiting) { tlWaitQueue* queue = tlWaitQueueCast(already_waiting); if (queue) { tlWaitQueueAdd(queue, task); } else { queue = tlWaitQueueNew(); tlWaitQueue* otherqueue = A_PTR( a_swap_if(A_VAR(other->waiting), A_VAL(queue), A_VAL_NB(already_waiting))); if (otherqueue != already_waiting) queue = tlWaitQueueAs(otherqueue); tlWaitQueueAdd(queue, already_waiting); tlWaitQueueAdd(queue, task); } // TODO try again! } trace("!! >> WAITING << !!"); return null; }
static always_inline void _soft8_convert_from_rgba_pt(const DATA32 * src, DATA8 * dst, DATA8 * alpha) { if (A_VAL(src) == 0) { *dst = 0; *alpha = 0; } else { *dst = GRY_8_FROM_RGB(src); *alpha = A_VAL(src); } }
EFL_ALWAYS_INLINE void _soft8_convert_from_rgba_pt(const DATA32 * src, DATA8 * dst, DATA8 * alpha) { if (A_VAL(src) == 0) { *dst = 0; *alpha = 0; } else { *dst = GRY_8_FROM_RGB(src); *alpha = A_VAL(src); } }
static void __imlib_Rectangle_FillToData(int x, int y, int rw, int rh, DATA32 color, DATA32 * dst, int dstw, int clx, int cly, int clw, int clh, ImlibOp op, char dst_alpha, char blend) { ImlibSpanDrawFunction sfunc; DATA32 *p; if (A_VAL(&color) == 0xff) blend = 0; sfunc = __imlib_GetSpanDrawFunction(op, dst_alpha, blend); if (!sfunc) return; dst += (dstw * cly) + clx; x -= clx; y -= cly; CLIP_RECT_TO_RECT(x, y, rw, rh, 0, 0, clw, clh); if ((rw < 1) || (rh < 1)) return; p = dst + (dstw * y) + x; while (rh--) { sfunc(color, p, rw); p += dstw; } }
static int __imlib_FilterGet(ImlibFilterColor * fil, DATA32 * data, int w, int h, int x, int y) { int i, off, ret; ImlibFilterPixel *pix; DATA32 *p; ret = fil->cons; pix = fil->pixels; for (i = fil->entries; --i >= 0;) { off = x + pix->xoff; if (off < 0) off = 0; if (off >= w) off = w - 1; p = data + off; off = y + pix->yoff; if (off < 0) off = 0; if (off >= h) off = h - 1; p += off * w; ret += A_VAL(p) * pix->a + R_VAL(p) * pix->r + G_VAL(p) * pix->g + B_VAL(p) * pix->b; pix++; } return ret; }
EAPI void evas_common_draw_context_set_color(RGBA_Draw_Context *dc, int r, int g, int b, int a) { R_VAL(&(dc->col.col)) = (DATA8)r; G_VAL(&(dc->col.col)) = (DATA8)g; B_VAL(&(dc->col.col)) = (DATA8)b; A_VAL(&(dc->col.col)) = (DATA8)a; }
/*\ Filter an image with the a, r, g, b filters in fil |*| NB: This is currently not very optimal, and could probably be improved \*/ void __imlib_FilterImage(ImlibImage * im, ImlibFilter * fil) { int x, y, a, r, g, b, ad, rd, gd, bd; DATA32 *data, *p1, *p2; data = malloc(im->w * im->h * sizeof(DATA32)); if (!data) return; ad = __imlib_FilterCalcDiv(&fil->alpha); rd = __imlib_FilterCalcDiv(&fil->red); gd = __imlib_FilterCalcDiv(&fil->green); bd = __imlib_FilterCalcDiv(&fil->blue); p1 = im->data; p2 = data; for (y = 0; y < im->h; y++) { for (x = 0; x < im->w; x++) { *p2 = *p1; if (ad) { a = __imlib_FilterGet(&fil->alpha, im->data, im->w, im->h, x, y); a /= ad; A_VAL(p2) = SATURATE(a); } if (rd) { r = __imlib_FilterGet(&fil->red, im->data, im->w, im->h, x, y); r /= rd; R_VAL(p2) = SATURATE(r); } if (gd) { g = __imlib_FilterGet(&fil->green, im->data, im->w, im->h, x, y); g /= gd; G_VAL(p2) = SATURATE(g); } if (bd) { b = __imlib_FilterGet(&fil->blue, im->data, im->w, im->h, x, y); b /= bd; B_VAL(p2) = SATURATE(b); } p1++; p2++; } } free(im->data); im->data = data; }
EAPI void evas_common_draw_context_set_multiplier(RGBA_Draw_Context *dc, int r, int g, int b, int a) { dc->mul.use = 1; R_VAL(&(dc->mul.col)) = (DATA8)r; G_VAL(&(dc->mul.col)) = (DATA8)g; B_VAL(&(dc->mul.col)) = (DATA8)b; A_VAL(&(dc->mul.col)) = (DATA8)a; }
static inline void _alpha_to_greyscale_convert(uint32_t *data, int len) { for (int k = 0; k < len; k++) { int alpha = A_VAL(data); *data++ = ARGB_JOIN(alpha, alpha, alpha, alpha); } }
static void _soft8_rectangle_draw_int(Soft8_Image * dst, RGBA_Draw_Context * dc, Eina_Rectangle dr) { int dst_offset; if (_is_empty_rectangle(&dr)) return; RECTS_CLIP_TO_RECT(dr.x, dr.y, dr.w, dr.h, 0, 0, dst->cache_entry.w, dst->cache_entry.h); if (_is_empty_rectangle(&dr)) return; if (dc->clip.use) RECTS_CLIP_TO_RECT(dr.x, dr.y, dr.w, dr.h, dc->clip.x, dc->clip.y, dc->clip.w, dc->clip.h); if (_is_empty_rectangle(&dr)) return; if (A_VAL(&dc->col.col) == 0) return; dst_offset = dr.x + (dr.y * dst->stride); if (!dst->cache_entry.flags.alpha) { DATA8 gry8; DATA8 alpha; alpha = A_VAL(&dc->col.col); gry8 = GRY_8_FROM_RGB(&dc->col.col); if (alpha == 0xff) _soft8_rectangle_draw_solid_solid(dst, dst_offset, dr.w, dr.h, gry8); else if (alpha > 0) _soft8_rectangle_draw_transp_solid (dst, dst_offset, dr.w, dr.h, gry8, alpha); } else ERR("Unsupported feature: drawing rectangle to non-opaque destination."); }
void __imlib_DataCmodApply(DATA32 * data, int w, int h, int jump, ImlibImageFlags * fl, ImlibColorModifier * cm) { int x, y; DATA32 *p; /* We might be adding alpha */ if (fl && !(*fl & F_HAS_ALPHA)) { p = data; for (y = 0; y < h; y++) { for (x = 0; x < w; x++) { R_VAL(p) = R_CMOD(cm, R_VAL(p)); G_VAL(p) = G_CMOD(cm, G_VAL(p)); B_VAL(p) = B_CMOD(cm, B_VAL(p)); p++; } p += jump; } return; } p = data; for (y = 0; y < h; y++) { for (x = 0; x < w; x++) { R_VAL(p) = R_CMOD(cm, R_VAL(p)); G_VAL(p) = G_CMOD(cm, G_VAL(p)); B_VAL(p) = B_CMOD(cm, B_VAL(p)); A_VAL(p) = A_CMOD(cm, A_VAL(p)); p++; } p += jump; } }
/*********************************************************************** * Evas helpers **********************************************************************/ static void _context_get_color(RGBA_Draw_Context *dc, int *r, int *g, int *b, int *a) { DATA32 col; if (dc->mul.use) col = dc->mul.col; else col = dc->col.col; *r = R_VAL(&col); *g = G_VAL(&col); *b = B_VAL(&col); *a = A_VAL(&col); }
void __imlib_Rectangle_FillToImage(int x, int y, int w, int h, DATA32 color, ImlibImage * im, int clx, int cly, int clw, int clh, ImlibOp op, char blend) { if ((w < 1) || (h < 1) || (clw < 0)) return; if ((w == 1) || (h == 1)) { (void)__imlib_Line_DrawToImage(x, y, x + w - 1, y + h - 1, color, im, clx, cly, clw, clh, op, blend, 0, 0); return; } if (blend && (!A_VAL(&color))) return; if (clw == 0) { clw = im->w; clx = 0; clh = im->h; cly = 0; } CLIP_RECT_TO_RECT(clx, cly, clw, clh, 0, 0, im->w, im->h); if ((clw < 1) || (clh < 1)) return; CLIP_RECT_TO_RECT(clx, cly, clw, clh, x, y, w, h); if ((clw < 1) || (clh < 1)) return; if (blend && IMAGE_HAS_ALPHA(im)) __imlib_build_pow_lut(); __imlib_Rectangle_FillToData(x, y, w, h, color, im->data, im->w, clx, cly, clw, clh, op, IMAGE_HAS_ALPHA(im), blend); }
EAPI void evas_common_draw_context_set_color(RGBA_Draw_Context *dc, int r, int g, int b, int a) { R_VAL(&(dc->col.col)) = (DATA8)r; G_VAL(&(dc->col.col)) = (DATA8)g; B_VAL(&(dc->col.col)) = (DATA8)b; A_VAL(&(dc->col.col)) = (DATA8)a; #ifdef HAVE_PIXMAN if (dc && dc->col.pixman_color_image) pixman_image_unref(dc->col.pixman_color_image); pixman_color_t pixman_color; pixman_color.alpha = (dc->col.col & 0xff000000) >> 16; pixman_color.red = (dc->col.col & 0x00ff0000) >> 8; pixman_color.green = (dc->col.col & 0x0000ff00); pixman_color.blue = (dc->col.col & 0x000000ff) << 8; dc->col.pixman_color_image = pixman_image_create_solid_fill(&pixman_color); #endif }
void evas_common_image_surface_alpha_tiles_calc(RGBA_Surface *is, int tsize) { int x, y; DATA32 *ptr; if (is->spans) return; if (!is->im->cache_entry.flags.alpha) return; /* FIXME: dont handle alpha only images yet */ if ((is->im->flags & RGBA_IMAGE_ALPHA_ONLY)) return; if (tsize < 0) tsize = 0; is->spans = calloc(1, sizeof(RGBA_Image_Span *) * is->h); if (!is->spans) return; ptr = is->data; for (y = 0; y < is->h; y++) { RGBA_Image_Span *sp; sp = NULL; for (x = 0; x < is->w; x++) { DATA8 a; a = A_VAL(ptr); if (sp) { if (a == 0) { is->spans[y] = eina_inlist_append(is->spans[y], sp); sp = NULL; } else { sp->w++; if ((sp->v == 2) && (a != 255)) sp->v = 1; } } else { if (a == 255) { sp = calloc(1, sizeof(RGBA_Image_Span)); sp->x = x; sp->w = 1; sp->v = 2; } else if (a > 0) { sp = calloc(1, sizeof(RGBA_Image_Span)); sp->x = x; sp->w = 1; sp->v = 1; } } ptr++; } if (sp) { is->spans[y] = eina_inlist_append(is->spans[y], sp); sp = NULL; } } }
/* internal engine routines */ static void * _output_setup(int w, int h, void *dest_buffer, int dest_buffer_row_bytes, int depth_type, int use_color_key, int alpha_threshold, int color_key_r, int color_key_g, int color_key_b, void *(*new_update_region) (int x, int y, int w, int h, int *row_bytes), void (*free_update_region) (int x, int y, int w, int h, void *data), void *(*switch_buffer) (void *data, void *dest_buffer), void *switch_data ) { Render_Engine *re; re = calloc(1, sizeof(Render_Engine)); if (!re) return NULL; /* if we haven't initialized - init (automatic abort if already done) */ evas_common_cpu_init(); evas_common_blend_init(); evas_common_image_init(); evas_common_convert_init(); evas_common_scale_init(); evas_common_rectangle_init(); evas_common_polygon_init(); evas_common_line_init(); evas_common_font_init(); evas_common_draw_init(); evas_common_tilebuf_init(); evas_buffer_outbuf_buf_init(); { Outbuf_Depth dep; DATA32 color_key = 0; dep = OUTBUF_DEPTH_BGR_24BPP_888_888; if (depth_type == EVAS_ENGINE_BUFFER_DEPTH_ARGB32) dep = OUTBUF_DEPTH_ARGB_32BPP_8888_8888; else if (depth_type == EVAS_ENGINE_BUFFER_DEPTH_RGB32) dep = OUTBUF_DEPTH_RGB_32BPP_888_8888; else if (depth_type == EVAS_ENGINE_BUFFER_DEPTH_BGRA32) dep = OUTBUF_DEPTH_BGRA_32BPP_8888_8888; else if (depth_type == EVAS_ENGINE_BUFFER_DEPTH_RGB24) dep = OUTBUF_DEPTH_RGB_24BPP_888_888; else if (depth_type == EVAS_ENGINE_BUFFER_DEPTH_BGR24) dep = OUTBUF_DEPTH_BGR_24BPP_888_888; R_VAL(&color_key) = color_key_r; G_VAL(&color_key) = color_key_g; B_VAL(&color_key) = color_key_b; A_VAL(&color_key) = 0; re->ob = evas_buffer_outbuf_buf_setup_fb(w, h, dep, dest_buffer, dest_buffer_row_bytes, use_color_key, color_key, alpha_threshold, new_update_region, free_update_region, switch_buffer, switch_data); } re->tb = evas_common_tilebuf_new(w, h); evas_common_tilebuf_set_tile_size(re->tb, TILESIZE, TILESIZE); eina_inarray_step_set(&re->previous_rects, sizeof (Eina_Inarray), sizeof (Eina_Rectangle), 8); return re; }
static void __imlib_Rectangle_DrawToData(int x, int y, int rw, int rh, DATA32 color, DATA32 * dst, int dstw, int clx, int cly, int clw, int clh, ImlibOp op, char dst_alpha, char blend) { ImlibPointDrawFunction pfunc; ImlibSpanDrawFunction sfunc; int x0, y0, x1, y1, len; DATA32 *p; if (A_VAL(&color) == 0xff) blend = 0; sfunc = __imlib_GetSpanDrawFunction(op, dst_alpha, blend); pfunc = __imlib_GetPointDrawFunction(op, dst_alpha, blend); if (!pfunc || !sfunc) return; dst += (dstw * cly) + clx; x -= clx; y -= cly; x0 = x; x1 = x + rw - 1; if (x0 < 0) x0 = 0; if (x1 >= clw) x1 = clw - 1; if (y >= 0) { p = dst + (dstw * y) + x0; len = x1 - x0 + 1; sfunc(color, p, len); } if ((y + rh) <= clh) { p = dst + (dstw * (y + rh - 1)) + x0; len = x1 - x0 + 1; sfunc(color, p, len); } y0 = y + 1; y1 = y + rh - 2; if (y0 < 0) y0 = 0; if (y1 >= clh) y1 = clh - 1; len = y1 - y0 + 1; if (len <= 0) return; y1 = len; if (x >= 0) { p = dst + (dstw * y0) + x; while (len--) { pfunc(color, p); p += dstw; } } if ((x + rw) <= clw) { len = y1; p = dst + (dstw * y0) + x + rw - 1; while (len--) { pfunc(color, p); p += dstw; } } }
static Imlib_Image bump_map(Imlib_Image im, pIFunctionParam par) { Imlib_Image map = im; pIFunctionParam ptr; double an = 0, el = 30, d = 0x200; double red = 0x200, green = 0x200, blue = 0x200; double ambient = 0; int free_map = 0; DATA32 *src; DATA32 *mp, *mpy, *mpp; double z, x2, y2; int w, h, i, j, w2, h2, wh2, mx, my; for (ptr = par; ptr; ptr = ptr->next) { ASSIGN_IMAGE("map", map); ASSIGN_INT("angle", an); ASSIGN_INT("elevation", el); ASSIGN_INT("depth", d); ASSIGN_INT("red", red); ASSIGN_INT("green", green); ASSIGN_INT("blue", blue); ASSIGN_INT("ambient", ambient); } if (!map) return im; red /= 0x100; green /= 0x100; blue /= 0x100; ambient /= 0x100; d /= 0x100; imlib_context_set_image(im); src = imlib_image_get_data(); w = imlib_image_get_width(); h = imlib_image_get_height(); imlib_context_set_image(map); mpp = imlib_image_get_data_for_reading_only(); w2 = imlib_image_get_width(); h2 = imlib_image_get_height(); wh2 = w2 * h2; an *= (PI / 180); el *= (PI / 180); x2 = sin(an) * cos(el); y2 = cos(an) * cos(el); z = sin(el); d /= (255 * (255 + 255 + 255)); my = h2; for (j = h; --j >= 0;) { mp = mpp; mpp += w2; if (--my <= 0) { mpp -= wh2; my = h2; } mpy = mpp; mx = w2; for (i = w; --i >= 0;) { double x1, y1, v; int r, g, b, gr; gr = A_VAL(mp) * (R_VAL(mp) + G_VAL(mp) + B_VAL(mp)); y1 = d * (double)(A_VAL(mpy) * (R_VAL(mpy) + G_VAL(mpy) + B_VAL(mpy)) - gr); mp++; mpy++; if (--mx <= 0) { mp -= w2; mpy -= w2; mx = w2; } x1 = d * (double)(A_VAL(mp) * (R_VAL(mp) + G_VAL(mp) + B_VAL(mp)) - gr); v = x1 * x2 + y1 * y2 + z; v /= sqrt((x1 * x1) + (y1 * y1) + 1.0); v += ambient; r = v * R_VAL(src) * red; g = v * G_VAL(src) * green; b = v * B_VAL(src) * blue; if (r < 0) r = 0; if (r > 255) r = 255; if (g < 0) g = 0; if (g > 255) g = 255; if (b < 0) b = 0; if (b > 255) b = 255; R_VAL(src) = r; G_VAL(src) = g; B_VAL(src) = b; src++; } } if (free_map) { imlib_context_set_image(map); imlib_free_image(); } return im; }
static void eng_image_draw(void *data, void *context, void *surface, void *image, int src_x, int src_y, int src_w, int src_h, int dst_x, int dst_y, int dst_w, int dst_h, int smooth) { Render_Engine *re; Evas_Cairo_Context *ctxt; Evas_Cairo_Image *im; DATA32 *pix; re = (Render_Engine *)data; ctxt = (Evas_Cairo_Context *)context; if (!image) return; im = image; evas_common_load_image_data_from_file(im->im); pix = im->im->image->data; if (pix) { if (!im->surface) { im->mulpix = malloc(im->im->image->w * im->im->image->h * sizeof(DATA32)); if (im->mulpix) { int i, n; DATA32 *p; n = im->im->image->w * im->im->image->h; p = im->mulpix; for (i = 0; i < n; i++) { int a; a = A_VAL(pix); R_VAL(p) = (R_VAL(pix) * a) / 255; G_VAL(p) = (G_VAL(pix) * a) / 255; B_VAL(p) = (B_VAL(pix) * a) / 255; A_VAL(p) = a; p++; pix++; } im->surface = cairo_image_surface_create_for_data(im->mulpix, CAIRO_FORMAT_ARGB32, im->im->image->w, im->im->image->h, 0); im->pattern = cairo_pattern_create_for_surface(im->surface); } } if (smooth) cairo_pattern_set_filter(im->pattern, CAIRO_FILTER_BILINEAR); else cairo_pattern_set_filter(im->pattern, CAIRO_FILTER_NEAREST); cairo_save(ctxt->cairo); cairo_translate(ctxt->cairo, dst_x, dst_y); cairo_scale(ctxt->cairo, (double)src_w / (double)dst_w, (double)src_h / (double)dst_h); cairo_move_to(ctxt->cairo, 0, 0); // cairo_set_rgb_color(re->win->cairo, // (double)(R_VAL(((RGBA_Draw_Context *)context)->col.col)) / 255.0, // (double)(R_VAL(((RGBA_Draw_Context *)context)->col.col)) / 255.0, // (double)(R_VAL(((RGBA_Draw_Context *)context)->col.col)) / 255.0); // cairo_set_alpha(re->win->cairo, // (double)(A_VAL(((RGBA_Draw_Context *)context)->col.col)) / 255.0); cairo_set_source_surface(ctxt->cairo, im->surface, im->im->image->w, im->im->image->h); cairo_paint(ctxt->cairo); cairo_restore(ctxt->cairo); } }
static void ensureYieldQueue(tlTask* task) { if (task->yields) return; tlQueue* queue = tlQueueNew(0); a_swap_if(A_VAR(task->yields), A_VAL(queue), 0); }
void evas_common_soft8_polygon_draw(Soft8_Image * dst, RGBA_Draw_Context * dc, RGBA_Polygon_Point * points, int x, int y) { RGBA_Polygon_Point *pt; RGBA_Vertex *point; RGBA_Edge *edges; int num_active_edges; int n; int i, j, k; int y0, y1, yi; int ext_x, ext_y, ext_w, ext_h; int *sorted_index; DATA8 alpha; DATA8 gry8; alpha = A_VAL(&dc->col.col); if (alpha == 0) return; alpha++; gry8 = GRY_8_FROM_RGB(&dc->col.col); ext_x = 0; ext_y = 0; ext_w = dst->cache_entry.w; ext_h = dst->cache_entry.h; if (dc->clip.use) RECTS_CLIP_TO_RECT(ext_x, ext_y, ext_w, ext_h, dc->clip.x, dc->clip.y, dc->clip.w, dc->clip.h); if ((ext_w <= 0) || (ext_h <= 0)) return; n = 0; EINA_INLIST_FOREACH(points, pt) n++; if (n < 3) return; edges = malloc(sizeof(RGBA_Edge) * n); if (!edges) return; point = malloc(sizeof(RGBA_Vertex) * n); if (!point) { free(edges); return; } sorted_index = malloc(sizeof(int) * n); if (!sorted_index) { free(edges); free(point); return; } k = 0; EINA_INLIST_FOREACH(points, pt) { point[k].x = pt->x + x; point[k].y = pt->y + y; point[k].i = k; k++; }
static void _bumpmap(Efx_Bumpmap_Data *ebd) { Evas_Object *o; int w; int h; int i, j; int x; int y; int z; int depth; int red; int green; int blue; int ambient; double z_2, lightx, lighty; int mx; int my; unsigned int *d1; unsigned int *d2; unsigned int *src; unsigned int *mp; unsigned int *mpy; unsigned int *mpp; x = ebd->x; y = ebd->y; z = ebd->z; red = ebd->red / 0x100; green = ebd->green / 0x100; blue = ebd->blue / 0x100; ambient = ebd->ambient / 0x100; depth = ebd->depth / 0x100; depth /= (255 * (255 + 255 + 255)); z_2 = z * z; o = ebd->e->obj; evas_object_image_size_get(o, &w, &h); if ((!w) || (!h)) return; d1 = malloc(w * h * sizeof(int)); memcpy(d1, ebd->img_data, w * h * sizeof(int)); src = d1; d2 = malloc(w * h * sizeof(int)); memcpy(d2, ebd->img_data, w * h * sizeof(int)); mpp = d2; my = h; lighty = -y; for (j = h; --j >= 0;) { mp = mpp; mpp += w; if (--my <= 0) { mpp -= w * h; my = h; } mpy = mpp; mx = w; lightx = -x; i = w - 1; do { double x1, y_1, v; int r, g, b, gr; gr = A_VAL(mp) * (R_VAL(mp) + G_VAL(mp) + B_VAL(mp)); y_1 = depth * (double)(A_VAL(mpy) * (R_VAL(mpy) + G_VAL(mpy) + B_VAL(mpy)) - gr); mp++; mpy++; if (--mx <= 0) { mp -= w; mpy -= w; mx = w; } x1 = depth * (double)(A_VAL(mp) * (R_VAL(mp) + G_VAL(mp) + B_VAL(mp)) - gr); v = x1 * lightx + y_1 * lighty + z; v /= sqrt((x1 * x1) + (y_1 * y_1) + 1.0); v /= sqrt((lightx * lightx) + (lighty * lighty) + z_2); v += ambient; r = v * R_VAL(src) * red; g = v * G_VAL(src) * green; b = v * B_VAL(src) * blue; if (r < 0) r = 0; else if (r > 255) r = 255; if (g < 0) g = 0; else if (g > 255) g = 255; if (b < 0) b = 0; else if (b > 255) b = 255; R_VAL(src) = r; G_VAL(src) = g; B_VAL(src) = b; lightx++; src++; } while (--i >= 0); lighty++; } unsigned int *m; m = (unsigned int *)evas_object_image_data_get(o, 1); memcpy(m, d1, w * h * sizeof(unsigned int)); evas_object_image_data_set(o, m); evas_object_image_data_update_add(o, 0, 0, w, h); free(d1); free(d2); }
Eina_Bool evas_image_load_file_data_eet(Image_Entry *ie, const char *file, const char *key, int *error) { unsigned int w, h; int alpha, compression, quality, lossy, ok; Eet_File *ef; DATA32 *body, *p, *end; DATA32 nas = 0; Eina_Bool res = EINA_FALSE; if (!key) { *error = EVAS_LOAD_ERROR_DOES_NOT_EXIST; return EINA_FALSE; } if (ie->flags.loaded) { *error = EVAS_LOAD_ERROR_NONE; return EINA_TRUE; } ef = eet_open(file, EET_FILE_MODE_READ); if (!ef) { *error = EVAS_LOAD_ERROR_DOES_NOT_EXIST; return EINA_FALSE; } ok = eet_data_image_header_read(ef, key, &w, &h, &alpha, &compression, &quality, &lossy); if (IMG_TOO_BIG(w, h)) { *error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED; goto on_error; } if (!ok) { *error = EVAS_LOAD_ERROR_DOES_NOT_EXIST; goto on_error; } evas_cache_image_surface_alloc(ie, w, h); ok = eet_data_image_read_to_surface(ef, key, 0, 0, evas_cache_image_pixels(ie), w, h, w * 4, &alpha, &compression, &quality, &lossy); if (!ok) { *error = EVAS_LOAD_ERROR_GENERIC; goto on_error; } if (alpha) { ie->flags.alpha = 1; body = evas_cache_image_pixels(ie); end = body +(w * h); for (p = body; p < end; p++) { DATA32 r, g, b, a; a = A_VAL(p); r = R_VAL(p); g = G_VAL(p); b = B_VAL(p); if ((a == 0) || (a == 255)) nas++; if (r > a) r = a; if (g > a) g = a; if (b > a) b = a; *p = ARGB_JOIN(a, r, g, b); } if ((ALPHA_SPARSE_INV_FRACTION * nas) >= (ie->w * ie->h)) ie->flags.alpha_sparse = 1; } // result is already premultiplied now if u compile with edje // evas_common_image_premul(im); *error = EVAS_LOAD_ERROR_NONE; res = EINA_TRUE; on_error: eet_close(ef); return res; }
void evas_buffer_outbuf_buf_push_updated_region(Outbuf *buf, RGBA_Image *update, int x, int y, int w, int h) { /* copy update image to out buf & convert */ switch (buf->depth) { case OUTBUF_DEPTH_RGB_24BPP_888_888: /* copy & pack into 24bpp - if colorkey is enabled... etc. */ { DATA8 thresh; int xx, yy; int row_bytes; DATA8 *dest; DATA32 colorkey; DATA32 *src; DATA8 *dst; colorkey = buf->color_key; thresh = buf->alpha_level; row_bytes = buf->dest_row_bytes; dest = (DATA8 *)(buf->dest) + (y * row_bytes) + (x * 3); if (buf->func.new_update_region) { dest = buf->func.new_update_region(x, y, w, h, &row_bytes); } if (!dest) break; if (buf->use_color_key) { for (yy = 0; yy < h; yy++) { dst = dest + (yy * row_bytes); src = update->image.data + (yy * update->cache_entry.w); for (xx = 0; xx < w; xx++) { if (A_VAL(src) > thresh) { *dst++ = R_VAL(src); *dst++ = G_VAL(src); *dst++ = B_VAL(src); } else { *dst++ = R_VAL(&colorkey); *dst++ = G_VAL(&colorkey); *dst++ = B_VAL(&colorkey); } src++; } } } else { for (yy = 0; yy < h; yy++) { dst = dest + (yy * row_bytes); src = update->image.data + (yy * update->cache_entry.w); for (xx = 0; xx < w; xx++) { *dst++ = R_VAL(src); *dst++ = G_VAL(src); *dst++ = B_VAL(src); src++; } } } if (buf->func.free_update_region) { buf->func.free_update_region(x, y, w, h, dest); } } break; case OUTBUF_DEPTH_BGR_24BPP_888_888: /* copy & pack into 24bpp - if colorkey is enabled... etc. */ { DATA8 thresh; int xx, yy; int row_bytes; DATA8 *dest; DATA32 colorkey; DATA32 *src; DATA8 *dst; colorkey = buf->color_key; thresh = buf->alpha_level; row_bytes = buf->dest_row_bytes; dest = (DATA8 *)(buf->dest) + (y * row_bytes) + (x * 3); if (buf->func.new_update_region) { dest = buf->func.new_update_region(x, y, w, h, &row_bytes); } if (!dest) break; if (buf->use_color_key) { for (yy = 0; yy < h; yy++) { dst = dest + (yy * row_bytes); src = update->image.data + (yy * update->cache_entry.w); for (xx = 0; xx < w; xx++) { if (A_VAL(src) > thresh) { *dst++ = B_VAL(src); *dst++ = G_VAL(src); *dst++ = R_VAL(src); } else { *dst++ = B_VAL(&colorkey); *dst++ = G_VAL(&colorkey); *dst++ = R_VAL(&colorkey); } src++; } } } else { for (yy = 0; yy < h; yy++) { dst = dest + (yy * row_bytes); src = update->image.data + (yy * update->cache_entry.w); for (xx = 0; xx < w; xx++) { *dst++ = B_VAL(src); *dst++ = G_VAL(src); *dst++ = R_VAL(src); src++; } } } if (buf->func.free_update_region) { buf->func.free_update_region(x, y, w, h, dest); } } break; case OUTBUF_DEPTH_RGB_32BPP_888_8888: case OUTBUF_DEPTH_ARGB_32BPP_8888_8888: { DATA32 *dest, *src, *dst; int yy, row_bytes; row_bytes = buf->dest_row_bytes; dest = (DATA32 *)((DATA8 *)(buf->dest) + (y * row_bytes) + (x * 4)); if (buf->func.new_update_region) { dest = buf->func.new_update_region(x, y, w, h, &row_bytes); } /* no need src == dest */ if (!buf->priv.back_buf) { Gfx_Func_Copy func; func = evas_common_draw_func_copy_get(w, 0); if (func) { for (yy = 0; yy < h; yy++) { src = update->image.data + (yy * update->cache_entry.w); dst = (DATA32 *)((DATA8 *)(buf->dest) + ((y + yy) * row_bytes)); func(src, dst, w); } } } if (buf->func.free_update_region) { buf->func.free_update_region(x, y, w, h, dest); } } break; case OUTBUF_DEPTH_BGR_32BPP_888_8888: { DATA32 *src, *dst; DATA8 *dest; int xx, yy, row_bytes; row_bytes = buf->dest_row_bytes; dest = (DATA8 *)(buf->dest) + (y * row_bytes) + (x * 4); if (buf->func.new_update_region) { dest = buf->func.new_update_region(x, y, w, h, &row_bytes); } for (yy = 0; yy < h; yy++) { dst = (DATA32 *)(dest + (yy * row_bytes)); src = update->image.data + (yy * update->cache_entry.w); for (xx = 0; xx < w; xx++) { A_VAL(dst) = B_VAL(src); R_VAL(dst) = G_VAL(src); G_VAL(dst) = R_VAL(src); dst++; src++; } } if (buf->func.free_update_region) { buf->func.free_update_region(x, y, w, h, dest); } } break; case OUTBUF_DEPTH_BGRA_32BPP_8888_8888: { DATA32 *src, *dst; DATA8 *dest; int xx, yy, row_bytes; row_bytes = buf->dest_row_bytes; dest = (DATA8 *)(buf->dest) + (y * row_bytes) + (x * 4); if (buf->func.new_update_region) { dest = buf->func.new_update_region(x, y, w, h, &row_bytes); } for (yy = 0; yy < h; yy++) { dst = (DATA32 *)(dest + (yy * row_bytes)); src = update->image.data + (yy * update->cache_entry.w); for (xx = 0; xx < w; xx++) { A_VAL(dst) = B_VAL(src); R_VAL(dst) = G_VAL(src); G_VAL(dst) = R_VAL(src); dst++; src++; } } if (buf->func.free_update_region) { buf->func.free_update_region(x, y, w, h, dest); } } break; default: break; } }
Eina_Bool evas_image_load_file_data_eet(Evas_Img_Load_Params *ilp, const char *file, const char *key, int *error) { unsigned int w, h; int alpha, compression, quality, lossy, ok; Eet_File *ef; DATA32 *body, *p, *end, *data; DATA32 nas = 0; Eina_Bool res = EINA_FALSE; if (!key) { *error = CSERVE2_DOES_NOT_EXIST; return EINA_FALSE; } ef = eet_open(file, EET_FILE_MODE_READ); if (!ef) { *error = CSERVE2_DOES_NOT_EXIST; return EINA_FALSE; } ok = eet_data_image_header_read(ef, key, &w, &h, &alpha, &compression, &quality, &lossy); if (IMG_TOO_BIG(w, h)) { *error = CSERVE2_RESOURCE_ALLOCATION_FAILED; goto on_error; } if (!ok) { *error = CSERVE2_DOES_NOT_EXIST; goto on_error; } data = ilp->buffer; if (!data) { *error = CSERVE2_RESOURCE_ALLOCATION_FAILED; goto on_error; } ok = eet_data_image_read_to_surface(ef, key, 0, 0, data, w, h, w * 4, &alpha, &compression, &quality, &lossy); if (!ok) { *error = CSERVE2_GENERIC; goto on_error; } if (alpha) { ilp->alpha = 1; body = ilp->buffer; end = body + (w * h); for (p = body; p < end; p++) { DATA32 r, g, b, a; a = A_VAL(p); r = R_VAL(p); g = G_VAL(p); b = B_VAL(p); if ((a == 0) || (a == 255)) nas++; if (r > a) r = a; if (g > a) g = a; if (b > a) b = a; *p = ARGB_JOIN(a, r, g, b); } if ((ALPHA_SPARSE_INV_FRACTION * nas) >= (w * h)) ilp->alpha_sparse = 1; } *error = CSERVE2_NONE; res = EINA_TRUE; on_error: eet_close(ef); return res; }