int quality = 80, compress = 9, ok = 0;
char *encoding = NULL;
Image_Entry *ie;
- Eina_Bool putback = EINA_FALSE, tofree = EINA_FALSE, no_convert = EINA_FALSE;
+ Eina_Bool putback = EINA_FALSE, tofree = EINA_FALSE, tgv = EINA_FALSE, free_data = EINA_FALSE;
Evas_Colorspace cspace = EVAS_COLORSPACE_ARGB8888;
- int want_cspace = EVAS_COLORSPACE_ARGB8888;
+ Evas_Colorspace want_cspace = EVAS_COLORSPACE_ARGB8888;
int imagew, imageh;
void *pixels;
o->proxyrendering = EINA_FALSE;
}
+ cspace = ENFN->image_file_colorspace_get(ENDT, pixels);
+ want_cspace = cspace;
+
if (flags)
{
- const char *ext = NULL;
char *p, *pp;
char *tflags;
else break;
}
- if (file) ext = strrchr(file, '.');
- if (encoding && ext && !strcasecmp(ext, ".tgv"))
+ if (file)
+ {
+ const char *ext = strrchr(file, '.');
+ if (ext && !strcasecmp(ext, ".tgv"))
+ tgv = EINA_TRUE;
+ }
+
+ if (encoding && tgv)
{
if (!strcmp(encoding, "auto"))
- want_cspace = -1;
+ want_cspace = cspace;
else if (!strcmp(encoding, "etc1"))
want_cspace = EVAS_COLORSPACE_ETC1;
else if (!strcmp(encoding, "etc2"))
}
}
- if (!ENFN->image_data_direct_get)
- pixels = ENFN->image_data_get(ENDT, pixels, 0, &data, &o->load_error, &tofree);
- else
+ if (ENFN->image_data_direct_get && (o->cur->orient == EVAS_IMAGE_ORIENT_NONE))
{
+ Evas_Colorspace cs;
Eina_Slice slice;
- if (ENFN->image_data_direct_get(ENDT, pixels, 0, &slice, &cspace))
- {
- if ((want_cspace != (int) cspace) && (want_cspace != -1))
- cspace = EVAS_COLORSPACE_ARGB8888;
- }
- else
+
+ ENFN->image_colorspace_set(ENDT, pixels, want_cspace);
+ ok = ENFN->image_data_direct_get(ENDT, pixels, 0, &slice, &cs, EINA_TRUE);
+ if (ok && (want_cspace == cs))
{
- cspace = ENFN->image_file_colorspace_get(ENDT, pixels);
- if ((want_cspace != (int) cspace) && (want_cspace != -1))
- cspace = EVAS_COLORSPACE_ARGB8888;
- else
- {
- ENFN->image_colorspace_set(ENDT, pixels, cspace);
- no_convert = EINA_TRUE;
- }
+ data = (DATA32 *) slice.mem;
+ putback = EINA_FALSE;
}
+ else ENFN->image_colorspace_set(ENDT, pixels, cspace);
+ }
+
+ if (!data)
+ {
+ cspace = EVAS_COLORSPACE_ARGB8888;
+ ENFN->image_colorspace_set(ENDT, pixels, cspace);
pixels = ENFN->image_data_get(ENDT, pixels, 0, &data, &o->load_error, &tofree);
}
- if (!pixels)
+ if (EINA_UNLIKELY(cspace != o->cur->cspace))
{
- WRN("Could not get image pixels.");
- return EINA_FALSE;
+ EINA_COW_IMAGE_STATE_WRITE_BEGIN(o, state_write)
+ state_write->cspace = cspace;
+ EINA_COW_IMAGE_STATE_WRITE_END(o, state_write)
}
- switch (cspace)
+ if (!pixels || !data)
{
- case EVAS_COLORSPACE_ARGB8888:
- break;
- case EVAS_COLORSPACE_ETC1:
- case EVAS_COLORSPACE_ETC1_ALPHA:
- case EVAS_COLORSPACE_RGB8_ETC2:
- case EVAS_COLORSPACE_RGBA8_ETC2_EAC:
- break;
- default:
- DBG("Need to convert colorspace before saving");
- cspace = EVAS_COLORSPACE_ARGB8888;
- break;
+ WRN("Could not get image pixels.");
+ return EINA_FALSE;
}
ie = evas_cache_image_data(evas_common_image_cache_get(),
if (ie)
{
RGBA_Image *im = (RGBA_Image *) ie;
- DATA32 *old_data = NULL;
- // FIXME: Something is fishy here... what about the previous pointer?
- if ((o->cur->cspace == cspace) || no_convert)
- im->image.data = data;
- else
- {
- old_data = im->image.data;
- im->image.data = _evas_image_data_convert_internal(o, data, EVAS_COLORSPACE_ARGB8888);
- }
- if (im->image.data)
- {
- ok = evas_common_save_image_to_file(im, file, key, quality, compress, encoding);
-
- if (old_data)
- {
- free(im->image.data);
- im->image.data = old_data;
- }
- }
+ ok = evas_common_save_image_to_file(im, file, key, quality, compress, encoding);
evas_cache_image_drop(ie);
}
+ else ok = EINA_FALSE;
if (tofree)
ENFN->image_free(ENDT, pixels);
else if (putback)
o->engine_data = ENFN->image_data_put(ENDT, pixels, data);
+ if (free_data) free(data);
+
free(encoding);
return ok;
}
void *(*image_dirty_region) (void *data, void *image, int x, int y, int w, int h);
void *(*image_data_get) (void *data, void *image, int to_write, DATA32 **image_data, int *err, Eina_Bool *tofree);
void *(*image_data_put) (void *data, void *image, DATA32 *image_data);
- Eina_Bool (*image_data_direct_get) (void *data, void *image, int plane, Eina_Slice *slice, Evas_Colorspace *cspace);
+ Eina_Bool (*image_data_direct_get) (void *data, void *image, int plane, Eina_Slice *slice, Evas_Colorspace *cspace, Eina_Bool load);
void (*image_data_preload_request) (void *data, void *image, const Eo *target);
void (*image_data_preload_cancel) (void *data, void *image, const Eo *target);
void *(*image_alpha_set) (void *data, void *image, int has_alpha);
static Eina_Bool
eng_image_data_direct_get(void *data EINA_UNUSED, void *image, int plane,
- Eina_Slice *slice, Evas_Colorspace *cspace)
+ Eina_Slice *slice, Evas_Colorspace *cspace,
+ Eina_Bool load)
{
Evas_GL_Image *im = image;
return EINA_FALSE;
if (cspace) *cspace = im->im->cache_entry.space;
+ if (load)
+ {
+ if (evas_cache_image_load_data(&im->im->cache_entry) != 0)
+ return EINA_FALSE;
+ }
return _evas_common_rgba_image_plane_get(im->im, plane, slice);
}
if (im->native.data)
return im;
- if (im->im &&
- im->orient != EVAS_IMAGE_ORIENT_NONE)
- {
- im_new = _rotate_image_data(data, image);
- if (!im_new)
- {
- if (err) *err = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED;
- ERR("Rotation failed.");
- return im;
- }
- evas_gl_common_image_free(im);
-
- *image_data = im_new->im->image.data;
- return im_new;
- }
+ if ((tofree != NULL) && im->im && (im->orient != EVAS_IMAGE_ORIENT_NONE))
+ goto rotate_image;
#ifdef GL_GLES
re->window_use(re->software.ob);
if (!im->im)
{
- // FIXME: Should we create an FBO and draw the texture there, to then read it back?
- ERR("GL image has no source data, failed to get pixel data");
- if (err) *err = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED;
- return NULL;
+ if (tofree)
+ goto rotate_image;
+ else
+ {
+ ERR("GL image has no source data, failed to get pixel data");
+ if (err) *err = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED;
+ return NULL;
+ }
}
#ifdef EVAS_CSERVE2
else
#endif
error = evas_cache_image_load_data(&im->im->cache_entry);
+
+ if (error != EVAS_LOAD_ERROR_NONE)
+ {
+ if (tofree)
+ goto rotate_image;
+ else
+ {
+ ERR("Failed to reload pixels of this GL image.");
+ if (err) *err = error;
+ return NULL;
+ }
+ }
+
evas_gl_common_image_alloc_ensure(im);
switch (im->cs.space)
{
}
if (err) *err = error;
return im;
+
+rotate_image:
+ // rotate data for image save
+ im_new = _rotate_image_data(data, image);
+ if (!im_new)
+ {
+ if (err) *err = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED;
+ ERR("Image rotation failed.");
+ return im;
+ }
+ *tofree = EINA_TRUE;
+ *image_data = im_new->im->image.data;
+ return im_new;
}
static void *