示例#1
0
int
evas_common_save_image_to_file(RGBA_Image *im, const char *file, const char *key, int quality, int compress)
{
   Evas_Image_Save_Func *evas_image_save_func = NULL;
   char *p;
   char *saver = NULL;

   p = strrchr(file, '.');
   if (p)
     {
	p++;

	if (!strcasecmp(p, "png"))
          saver = "png";
	if ((!strcasecmp(p, "jpg")) || (!strcasecmp(p, "jpeg")) ||
	    (!strcasecmp(p, "jfif")))
          saver = "jpeg";
	if ((!strcasecmp(p, "eet")) || (!strcasecmp(p, "edj")) ||
            (!strcasecmp(p, "eap")))
          saver = "eet";
	if (!strcasecmp(p, "webp"))
          saver = "webp";
        if (!strcasecmp(p, "tgv"))
          saver = "tgv";
     }

   if (saver)
     {
        Evas_Module *em;

	em = evas_module_find_type(EVAS_MODULE_TYPE_IMAGE_SAVER, saver);
	if (em)
	  {
	     evas_module_use(em);
	     if (evas_module_load(em))
	       {
		  evas_image_save_func = em->functions;
		  return evas_image_save_func->image_save(im, file, key, quality, compress);
	       }
	  }
     }
   return 0;
}
示例#2
0
EAPI int
_evas_module_engine_inherit(Evas_Func *funcs, char *name)
{
   Evas_Module *em;

   em = evas_module_find_type(EVAS_MODULE_TYPE_ENGINE, name);
   if (em)
     {
	if (evas_module_load(em))
	  {
	     /* FIXME: no way to unref */
	     evas_module_ref(em);
	     evas_module_use(em);
	     *funcs = *((Evas_Func *)(em->functions));
	     return 1;
	  }
     }
   return 0;
}
示例#3
0
static Error_Type
image_load(const char *file, const char *key, const char *shmfile,
           Slave_Msg_Image_Load *params, Slave_Msg_Image_Loaded *result,
           const char *loader)
{
   Evas_Module *module;
   Eina_File *fd;
   Evas_Image_Load_Func *funcs = NULL;
   Evas_Image_Load_Opts *opts = &params->opts;
   Evas_Image_Property property;
   Evas_Image_Animated animated;
   Error_Type ret = CSERVE2_GENERIC;
   void *loader_data = NULL;
   Eina_Bool ok;
   Eina_Stringshare *skey = NULL;
   int error;

   fd = eina_file_open(file, EINA_FALSE);
   if (!fd)
     {
        return CSERVE2_DOES_NOT_EXIST; // FIXME: maybe check errno
     }

   char *map = _cserve2_shm_map(shmfile, params->shm.mmap_size,
                                params->shm.mmap_offset);
   if (map == MAP_FAILED)
     {
        eina_file_close(fd);
        return CSERVE2_RESOURCE_ALLOCATION_FAILED;
     }

   module = evas_module_find_type(EVAS_MODULE_TYPE_IMAGE_LOADER, loader);
   if (!module)
     {
        printf("LOAD failed at %s:%d: no module found for loader %s\n",
               __FUNCTION__, __LINE__, loader);
        goto done;
     }

   memset(&property, 0, sizeof (property));
   property.w = params->w;
   property.h = params->h;

   skey = eina_stringshare_add(key);
   loader_data = _image_file_open(fd, skey, opts, module, &property, &animated, &funcs);
   if (!loader_data)
     {
        printf("LOAD failed at %s:%d: could not open image %s:%s\n",
               __FUNCTION__, __LINE__, file, skey);
        goto done;
     }

   ok = funcs->file_data(loader_data, &property, map, &error);
   if (!ok || (error != EVAS_LOAD_ERROR_NONE))
     {
        printf("LOAD failed at %s:%d: file_data failed for loader %s: error %d\n",
               __FUNCTION__, __LINE__, loader, error);
        goto done;
     }

   result->w = property.w;
   result->h = property.h;

   if (property.alpha)
     {
        result->alpha_sparse = evas_cserve2_image_premul_data((unsigned int *) map,
                                                              result->w * result->h);
     }

   //printf("LOAD successful: %dx%d alpha_sparse %d\n",
   //       result->w, result->h, result->alpha_sparse);

   ret = CSERVE2_NONE;

done:
   eina_file_close(fd);
   _cserve2_shm_unmap(map, params->shm.mmap_size);
   if (funcs)
     {
        if (loader_data)
          funcs->file_close(loader_data);
        evas_module_unload(module);
     }
   eina_stringshare_del(skey);

   return ret;
}
示例#4
0
static Error_Type
image_open(const char *file, const char *key,
           Slave_Msg_Image_Opened *result, const char **use_loader)
{
   Evas_Module *module;
   Eina_File *fd;
   const char *loader = NULL;
   const int filelen = strlen(file);
   unsigned int i;
   Error_Type ret = CSERVE2_NONE;
   Eina_Stringshare *skey = eina_stringshare_add(key);
   Evas_Image_Load_Opts load_opts;

   memset(&load_opts, 0, sizeof(load_opts));

   fd = eina_file_open(file, EINA_FALSE);
   if (!fd)
     {
        return CSERVE2_DOES_NOT_EXIST; // FIXME: maybe check errno
     }

   if (!*use_loader)
     goto try_extension;

   loader = *use_loader;
   module = evas_module_find_type(EVAS_MODULE_TYPE_IMAGE_LOADER, loader);
   if (module)
     {
        if (_image_file_header(fd, skey, &load_opts, result, module))
          goto success;
     }

try_extension:
   loader = NULL;
   for (i = 0; i < sizeof(map_loaders) / sizeof(map_loaders[0]); i++)
     {
        int extlen = strlen(map_loaders[i].extension);
        if (extlen > filelen) continue;
        if (!strcasecmp(map_loaders[i].extension, file + filelen - extlen))
          {
             loader = map_loaders[i].loader;
             break;
          }
     }

   if (loader)
     {
        module = evas_module_find_type(EVAS_MODULE_TYPE_IMAGE_LOADER, loader);
        if (_image_file_header(fd, skey, &load_opts, result, module))
          goto success;
        loader = NULL;
        module = NULL;
     }

   // Try all known modules
   for (i = 0; i < sizeof(loaders_name) / sizeof(loaders_name[0]); i++)
     {
        loader = loaders_name[i];
        module = evas_module_find_type(EVAS_MODULE_TYPE_IMAGE_LOADER, loader);
        if (!module) continue;
        if (_image_file_header(fd, skey, &load_opts, result, module))
          goto success;
     }

   ret = CSERVE2_UNKNOWN_FORMAT;
   goto end;

success:
   ret = CSERVE2_NONE;
   *use_loader = loader;

   // FIXME: Do we really need to unload the module now?
   evas_module_unload(module);

end:
   eina_file_close(fd);
   eina_stringshare_del(skey);
   return ret;
}