From 03257dd7b9e475da40ac36917ad0dc3e3c9e16fd Mon Sep 17 00:00:00 2001 From: raster Date: Tue, 15 Sep 2009 13:34:12 +0000 Subject: [PATCH] add "region" load opt. no loader handles it... yet git-svn-id: svn+ssh://svn.enlightenment.org/var/svn/e/trunk/evas@42494 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33 --- src/bin/evas_cserve_main.c | 14 ++++-- src/lib/Evas.h | 3 ++ src/lib/cache/evas_cache_image.c | 8 ++-- src/lib/canvas/evas_object_image.c | 64 ++++++++++++++++++++++++- src/lib/cserve/evas_cs.h | 3 ++ src/lib/cserve/evas_cs_client.c | 4 ++ src/lib/include/evas_common.h | 3 ++ src/modules/loaders/jpeg/evas_image_load_jpeg.c | 7 +++ 8 files changed, 99 insertions(+), 7 deletions(-) diff --git a/src/bin/evas_cserve_main.c b/src/bin/evas_cserve_main.c index 7a450c5..e363c77 100644 --- a/src/bin/evas_cserve_main.c +++ b/src/bin/evas_cserve_main.c @@ -34,6 +34,9 @@ struct _Lopt int scale_down_by; // if > 1 then use this double dpi; // if > 0.0 use this int w, h; // if > 0 use this + struct { + int x, y, w, h; + } region; }; struct _Img @@ -957,7 +960,7 @@ message(void *fdata, Server *s, Client *c, int opcode, int size, unsigned char * Op_Load *rep; Op_Load_Reply msg; Img *img; - RGBA_Image_Loadopts lopt = {0, 0.0, 0, 0}; + RGBA_Image_Loadopts lopt = {0, 0.0, 0, 0, 0, 0, 0, 0}; char *file = NULL, *key = NULL; D("OP_LOAD %i", c->pid); @@ -969,11 +972,16 @@ message(void *fdata, Server *s, Client *c, int opcode, int size, unsigned char * lopt.dpi = rep->lopt.dpi; lopt.w = rep->lopt.w; lopt.h = rep->lopt.h; + lopt.region.x = rep->lopt.region.x; + lopt.region.y = rep->lopt.region.y; + lopt.region.w = rep->lopt.region.w; + lopt.region.h = rep->lopt.region.h; D("... img_load '%s'", file); if (key) D("'%s'", key); else D(" '%s'", NULL); - D(" lopt { %i %1.1f %i %i}", - lopt.scale_down_by, lopt.dpi, lopt.w, lopt.h); + D(" lopt { %i %1.1f %i %i { %i %i %i %i}}", + lopt.scale_down_by, lopt.dpi, lopt.w, lopt.h, + lopt.region.x, lopt.region.y, lopt.region.w, lopt.region.h); img = img_load(file, key, &lopt); D("... img_load = %p", img); if (img) diff --git a/src/lib/Evas.h b/src/lib/Evas.h index 2b0ae3d..aa27c2e 100644 --- a/src/lib/Evas.h +++ b/src/lib/Evas.h @@ -595,6 +595,9 @@ extern "C" { EAPI void evas_object_image_load_size_get (const Evas_Object *obj, int *w, int *h) EINA_ARG_NONNULL(1); EAPI void evas_object_image_load_scale_down_set (Evas_Object *obj, int scale_down) EINA_ARG_NONNULL(1); EAPI int evas_object_image_load_scale_down_get (const Evas_Object *obj) EINA_WARN_UNUSED_RESULT EINA_ARG_NONNULL(1) EINA_PURE; + EAPI void evas_object_image_load_region_set (Evas_Object *obj, int x, int y, int w, int h) EINA_ARG_NONNULL(1); + EAPI void evas_object_image_load_region_get (const Evas_Object *obj, int *x, int *y, int *w, int *h) EINA_ARG_NONNULL(1); + EAPI void evas_object_image_colorspace_set (Evas_Object *obj, Evas_Colorspace cspace) EINA_ARG_NONNULL(1); EAPI Evas_Colorspace evas_object_image_colorspace_get (const Evas_Object *obj) EINA_WARN_UNUSED_RESULT EINA_ARG_NONNULL(1) EINA_PURE; EAPI void evas_object_image_native_surface_set (Evas_Object *obj, Evas_Native_Surface *surf) EINA_ARG_NONNULL(1, 2); diff --git a/src/lib/cache/evas_cache_image.c b/src/lib/cache/evas_cache_image.c index 515e1e3..d1ffb74 100644 --- a/src/lib/cache/evas_cache_image.c +++ b/src/lib/cache/evas_cache_image.c @@ -239,6 +239,10 @@ _evas_cache_image_entry_new(Evas_Cache_Image *cache, ie->load_opts.dpi = 0; ie->load_opts.w = 0; ie->load_opts.h = 0; + ie->load_opts.region.x = 0; + ie->load_opts.region.y = 0; + ie->load_opts.region.w = 0; + ie->load_opts.region.h = 0; ie->scale = 1; #ifdef BUILD_ASYNC_PRELOAD @@ -603,7 +607,7 @@ evas_cache_image_request(Evas_Cache_Image *cache, const char *file, const char * const char *format; char *hkey; Image_Entry *im; - Evas_Image_Load_Opts prevent = { 0, 0, 0, 0 }; + Evas_Image_Load_Opts prevent = { 0, 0, 0, 0, 0, 0, 0, 0 }; int size; int stat_done = 0; int file_length; @@ -1255,7 +1259,6 @@ _evas_cache_background_load(void *data) pthread_mutex_unlock(&mutex); - printf("load loop!\n"); if (current) { Evas_Cache_Image *cache; @@ -1290,7 +1293,6 @@ _evas_cache_background_load(void *data) _evas_cache_image_async_call(current); current = NULL; } - printf("---\n"); pthread_cond_signal(&cond_done); } diff --git a/src/lib/canvas/evas_object_image.c b/src/lib/canvas/evas_object_image.c index 4ea0e66..b44e219 100644 --- a/src/lib/canvas/evas_object_image.c +++ b/src/lib/canvas/evas_object_image.c @@ -23,7 +23,7 @@ struct _Evas_Object_Image int spread; Evas_Coord_Rectangle fill; struct { - short w, h, stride; + short w, h, stride; } image; struct { short l, r, t, b; @@ -46,6 +46,9 @@ struct _Evas_Object_Image unsigned char scale_down_by; double dpi; short w, h; + struct { + short x, y, w, h; + } region; } load_opts; struct { @@ -292,6 +295,10 @@ evas_object_image_file_set(Evas_Object *obj, const char *file, const char *key) lo.dpi = o->load_opts.dpi; lo.w = o->load_opts.w; lo.h = o->load_opts.h; + lo.region.x = o->load_opts.region.x; + lo.region.y = o->load_opts.region.y; + lo.region.w = o->load_opts.region.w; + lo.region.h = o->load_opts.region.h; o->engine_data = obj->layer->evas->engine.func->image_load(obj->layer->evas->engine.data.output, o->cur.file, o->cur.key, @@ -1725,6 +1732,57 @@ evas_object_image_load_scale_down_get(const Evas_Object *obj) * */ EAPI void +evas_object_image_load_region_set(Evas_Object *obj, int x, int y, int w, int h) +{ + Evas_Object_Image *o; + + MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ); + return; + MAGIC_CHECK_END(); + o = (Evas_Object_Image *)(obj->object_data); + MAGIC_CHECK(o, Evas_Object_Image, MAGIC_OBJ_IMAGE); + return; + MAGIC_CHECK_END(); + if ((o->load_opts.region.x == x) && (o->load_opts.region.y == y) && + (o->load_opts.region.w == w) && (o->load_opts.region.h == h)) return; + o->load_opts.region.x = x; + o->load_opts.region.y = y; + o->load_opts.region.w = w; + o->load_opts.region.h = h; + if (o->cur.file) + { + evas_object_image_unload(obj, 0); + evas_object_image_load(obj); + o->changed = 1; + evas_object_change(obj); + } +} + +EAPI void +evas_object_image_load_region_get(const Evas_Object *obj, int *x, int *y, int *w, int *h) +{ + Evas_Object_Image *o; + + MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ); + return; + MAGIC_CHECK_END(); + o = (Evas_Object_Image *)(obj->object_data); + MAGIC_CHECK(o, Evas_Object_Image, MAGIC_OBJ_IMAGE); + return; + MAGIC_CHECK_END(); + if (x) *x = o->load_opts.region.x; + if (y) *y = o->load_opts.region.y; + if (w) *w = o->load_opts.region.w; + if (h) *h = o->load_opts.region.h; +} + +/** + * To be documented. + * + * FIXME: To be fixed. + * + */ +EAPI void evas_object_image_colorspace_set(Evas_Object *obj, Evas_Colorspace cspace) { Evas_Object_Image *o; @@ -1994,6 +2052,10 @@ evas_object_image_load(Evas_Object *obj) lo.dpi = o->load_opts.dpi; lo.w = o->load_opts.w; lo.h = o->load_opts.h; + lo.region.x = o->load_opts.region.x; + lo.region.y = o->load_opts.region.y; + lo.region.w = o->load_opts.region.w; + lo.region.h = o->load_opts.region.h; o->engine_data = obj->layer->evas->engine.func->image_load(obj->layer->evas->engine.data.output, o->cur.file, o->cur.key, diff --git a/src/lib/cserve/evas_cs.h b/src/lib/cserve/evas_cs.h index 398caee..ffbefd3 100644 --- a/src/lib/cserve/evas_cs.h +++ b/src/lib/cserve/evas_cs.h @@ -134,6 +134,9 @@ typedef struct int scale_down_by; double dpi; int w, h; + struct { + int x, y, w, h; + } region; } lopt; } Op_Load; // +"file""key" typedef struct diff --git a/src/lib/cserve/evas_cs_client.c b/src/lib/cserve/evas_cs_client.c index 4359e5a..e1148a3 100644 --- a/src/lib/cserve/evas_cs_client.c +++ b/src/lib/cserve/evas_cs_client.c @@ -298,6 +298,10 @@ evas_cserve_image_load(Image_Entry *ie, const char *file, const char *key, RGBA_ msg.lopt.dpi = lopt->dpi; msg.lopt.w = lopt->w; msg.lopt.h = lopt->h; + msg.lopt.region.x = lopt->region.x; + msg.lopt.region.y = lopt->region.y; + msg.lopt.region.w = lopt->region.w; + msg.lopt.region.h = lopt->region.h; if (file[0] != '/') { if (getcwd(wdb, sizeof(wdb))) diff --git a/src/lib/include/evas_common.h b/src/lib/include/evas_common.h index 489bc42..93386de 100644 --- a/src/lib/include/evas_common.h +++ b/src/lib/include/evas_common.h @@ -409,6 +409,9 @@ struct _RGBA_Image_Loadopts int scale_down_by; // if > 1 then use this double dpi; // if > 0.0 use this int w, h; // if > 0 use this + struct { + int x, y, w, h; + } region; }; struct _Image_Entry_Flags diff --git a/src/modules/loaders/jpeg/evas_image_load_jpeg.c b/src/modules/loaders/jpeg/evas_image_load_jpeg.c index f169490..aeadc62 100644 --- a/src/modules/loaders/jpeg/evas_image_load_jpeg.c +++ b/src/modules/loaders/jpeg/evas_image_load_jpeg.c @@ -104,6 +104,12 @@ evas_image_load_file_head_jpeg_internal(Image_Entry *ie, FILE *f) /* head decoding */ w = cinfo.output_width; h = cinfo.output_height; + if ((ie->load_opts.region.w > 0) && (ie->load_opts.region.h > 0)) + { + RECTS_CLIP_TO_RECT(ie->load_opts.region.x, ie->load_opts.region.y, + ie->load_opts.region.w, ie->load_opts.region.h, + 0, 0, w, h); + } if ((w < 1) || (h < 1) || (w > IMG_MAX_SIZE) || (h > IMG_MAX_SIZE)) { jpeg_destroy_decompress(&cinfo); @@ -176,6 +182,7 @@ evas_image_load_file_head_jpeg_internal(Image_Entry *ie, FILE *f) jpeg_start_decompress(&cinfo); } + // FIXME: handle region if specified ie->w = cinfo.output_width; ie->h = cinfo.output_height; /* end head decoding */ -- 2.7.4