void EflResources::initCb__( void*         _this
                           , Ecore_Thread* _th )
{
    ASSERT( _this && _th
          , "NULL pointers passed to thread function." );
    EflResources* rh( static_cast< EflResources* >( _this ) );

    std::for_each( init_images__.begin()
                 , init_images__.end()
                 , [&]( std::string const _path )
    {
        Evas_Object* object = evas_object_image_add( rh->window__ );
        evas_object_image_load_size_set( object
                                       , rh->max_width__
                                       , rh->max_height__ );
        evas_object_image_file_set( object
                                  , _path.c_str()
                                  , nullptr );
        CCallbackHandler::evasEventCallback( object
                                           , CALLBACK_IMAGE_PRELOADED
                                           , [=](){ ++( rh->resources_loaded__ );
                                                    rh->signals__[LOADING]->emit(); } );
        rh->preloaded_images__[_path] = object;
        evas_object_image_preload( object
                                 , 0 );
    } );
}
void EflResources::preloadCachedImageCb__( std::string const& _path )
{
    if( 0 < preloaded_images__.count( _path ) )
    {
        Evas_Object* object = preloaded_images__[_path];

        evas_object_image_load_size_set( object
                                       , max_width__
                                       , max_height__ );
        std::string cached_file( cache_dir + _path );
        evas_object_image_file_set( object
                                  , cached_file.c_str()
                                  , nullptr );
        if( EVAS_LOAD_ERROR_NONE != evas_object_image_load_error_get( object ) )
        {
            signals__[PRELOAD_FAIL]->emit();
            LOGGER( "Failed to load image file: " + _path );
        }
        else
        {
            CCallbackHandler::evasEventCallback( object
                                               , CALLBACK_IMAGE_PRELOADED
                                               , [=](){ signals__[PRELOAD_SUCCESS]->emit(); } );
            evas_object_image_preload( object
                                     , 0 );
        }
    }
}
Beispiel #3
0
EAPI void
e_icon_scale_size_set(Evas_Object *obj, int size)
{
   E_Smart_Data *sd;

   if (evas_object_smart_smart_get(obj) != _e_smart) SMARTERRNR();
   if (!(sd = evas_object_smart_data_get(obj))) return;
   sd->size = size;
   if (sd->edje) return;
   evas_object_image_load_size_set(sd->obj, sd->size, sd->size);
}
Beispiel #4
0
EAPI Eina_Bool
e_icon_fdo_icon_set(Evas_Object *obj, const char *icon)
{
   E_Smart_Data *sd;
   const char *path;
   int len;

   if (!icon) return EINA_FALSE;
   if (evas_object_smart_smart_get(obj) != _e_smart) SMARTERR(0);
   if (icon[0] == '/') return e_icon_file_set(obj, icon);

   if (!(sd = evas_object_smart_data_get(obj)))
     return EINA_FALSE;

   if (sd->timer) ecore_timer_del(sd->timer);
   sd->timer = NULL;
   if (sd->guessing_animation) ecore_timer_del(sd->guessing_animation);
   sd->guessing_animation = NULL;
   sd->frame = 0;
   sd->frame_count = 0;
   sd->edje = EINA_FALSE;

   eina_stringshare_replace(&sd->fdo, icon);
   if (!sd->fdo) return EINA_FALSE;

   path = efreet_icon_path_find(e_config->icon_theme, sd->fdo, sd->size);
   if (!path) return EINA_FALSE;

   len = strlen(icon);
   if ((len > 4) && (!strcasecmp(icon + len - 4, ".edj")))
     return e_icon_file_edje_set(obj, path, "icon");

   /* smart code here */
   _e_icon_obj_prepare(obj, sd);
   sd->loading = 0;
   if (sd->size != 0)
     evas_object_image_load_size_set(sd->obj, sd->size, sd->size);
   if (sd->preload) evas_object_hide(sd->obj);
   evas_object_image_file_set(sd->obj, path, NULL);
   if (evas_object_image_load_error_get(sd->obj) != EVAS_LOAD_ERROR_NONE)
     return EINA_FALSE;
   if (sd->preload)
     {
        sd->loading = 1;
        evas_object_image_preload(sd->obj, 0);
     }
   else if (evas_object_visible_get(obj))
     evas_object_show(sd->obj);
   _e_icon_smart_reconfigure(sd);
   return EINA_TRUE;
}
Beispiel #5
0
EAPI Eina_Bool
e_icon_file_key_set(Evas_Object *obj, const char *file, const char *key)
{
   E_Smart_Data *sd;

   if (evas_object_smart_smart_get(obj) != _e_smart) SMARTERR(0);
   if (!(sd = evas_object_smart_data_get(obj)))
     return EINA_FALSE;

   /* smart code here */
   sd->loading = 0;
   if (sd->fdo)
     {
        eina_stringshare_del(sd->fdo);
        sd->fdo = NULL;
     }

   if (sd->timer) ecore_timer_del(sd->timer);
   sd->timer = NULL;
   if (sd->guessing_animation) ecore_timer_del(sd->guessing_animation);
   sd->guessing_animation = NULL;
   sd->frame = 0;
   sd->frame_count = 0;
   sd->edje = EINA_FALSE;

   _e_icon_obj_prepare(obj, sd);
   if (sd->size != 0)
     evas_object_image_load_size_set(sd->obj, sd->size, sd->size);
   if (sd->preload) evas_object_hide(sd->obj);
   evas_object_image_file_set(sd->obj, file, key);
   if (evas_object_image_load_error_get(sd->obj) != EVAS_LOAD_ERROR_NONE)
     return EINA_FALSE;
   if (!_handle_anim(sd))
     {
        if (sd->preload)
          {
             sd->loading = 1;
             evas_object_image_preload(sd->obj, 0);
          }
        else if (evas_object_visible_get(obj))
          evas_object_show(sd->obj);
     }
   _e_icon_smart_reconfigure(sd);
   return EINA_TRUE;
}
Beispiel #6
0
static void _walle_wall_populate(Walle *walle, const char *directory, const char *theme)
{
    Evas_Object *o;
    Evas_Coord ow, oh, w, h;
    Eina_List *files = NULL;
    char *file = NULL;
    char filename[4096];

    if (!ecore_file_is_dir(directory) && ecore_file_dir_is_empty(directory))
        return;
    files = ecore_file_ls(directory);
    if (!files)
        return;
    EINA_LIST_FREE(files, file)
    {
    	sprintf(filename, "%s/%s", directory, file);
    	o = evas_object_image_add(walle->evas);
    	evas_object_image_file_set(o, filename, NULL);
    	switch(evas_object_image_load_error_get(o))
    	{
    	case EVAS_LOAD_ERROR_NONE:
    	{
    	    evas_object_event_callback_add(o, EVAS_CALLBACK_RESIZE, _walle_picture_cb_resize, o);
    	    evas_object_image_size_get(o, &w, &h);
    	    oh = 200;
    	    ow = oh * (float)w/(float)h;
    	    evas_object_image_load_size_set(o, ow, oh);
    	    evas_object_image_fill_set(o, 0, 0, ow, oh);
    	    evas_object_resize(o, ow, oh);
    	    evas_object_size_hint_min_set(o, ow, oh);
    	    walle_wall_append(walle->o_wall, o);
    	    walle->pictures = eina_list_append(walle->pictures, o);
    	}
    	break;
    	default:
    	    evas_object_del(o);
    	    break;
    	}
    }
Beispiel #7
0
EAPI Eina_Bool
e_icon_file_set(Evas_Object *obj, const char *file)
{
   E_Smart_Data *sd;
   int len;

   if (!file) return EINA_FALSE;
   if (evas_object_smart_smart_get(obj) != _e_smart) SMARTERR(0);
   if (!(sd = evas_object_smart_data_get(obj)))
     return EINA_FALSE;

   len = strlen(file);
   if ((len > 4) && (!strcasecmp(file + len - 4, ".edj")))
     return e_icon_file_edje_set(obj, file, "icon");

   /* smart code here */
   _e_icon_obj_prepare(obj, sd);
   /* FIXME: 64x64 - unhappy about this. use icon size */
   sd->loading = 0;
   if (sd->fdo)
     {
        eina_stringshare_del(sd->fdo);
        sd->fdo = NULL;
     }

   if (sd->timer) ecore_timer_del(sd->timer);
   sd->timer = NULL;
   if (sd->guessing_animation) ecore_timer_del(sd->guessing_animation);
   sd->guessing_animation = NULL;
   sd->frame = 0;
   sd->frame_count = 0;
   sd->edje = EINA_FALSE;

   if (sd->size != 0)
     evas_object_image_load_size_set(sd->obj, sd->size, sd->size);
   if (sd->preload) evas_object_hide(sd->obj);

#ifdef USE_ICON_CACHE
   if (_e_icon_cache_find(obj, file))
     {
        _e_icon_smart_reconfigure(sd);
        return EINA_TRUE;
     }
#endif

   evas_object_image_file_set(sd->obj, file, NULL);
   if (evas_object_image_load_error_get(sd->obj) != EVAS_LOAD_ERROR_NONE)
     return EINA_FALSE;

   if (!_handle_anim(sd))
     {
        if (sd->preload)
          {
             sd->loading = 1;
             evas_object_image_preload(sd->obj, EINA_FALSE);
          }
        else if (evas_object_visible_get(obj))
          {
             evas_object_show(sd->obj);
#ifdef USE_ICON_CACHE
             _e_icon_cache_icon_loaded(sd->ci);
#endif
          }
     }
#ifdef USE_ICON_CACHE
   else
     {
        evas_object_event_callback_del_full(sd->obj, EVAS_CALLBACK_DEL,
                                            _e_icon_obj_del, obj);
        _cache->load_queue = eina_list_remove(_cache->load_queue, sd->ci);
        eina_stringshare_del(sd->ci->id);
        E_FREE(sd->ci);
        sd->ci = NULL;
     }
#endif

   _e_icon_smart_reconfigure(sd);
   return EINA_TRUE;
}
int main(int argc, char *argv[])
{
    Ecore_Evas *ee;
    Evas_Object *bridge, *img;
    const char *opt, *input, *output, *params;
    int r = 0, w = -1, h = -1, err;
    double scale = -1.0;

    if (argc < 4) {
        fprintf(stderr,
                "Usage:\n"
                "\t%s <percentage%%|WxH|w=W|h=H> <input> <output>"
                " [save-params]\n"
                "where save-params is evas supported parameters, like:\n"
                "\tquality=85\n"
                "\tcompress=9\n",
                argv[0]);
        return 1;
    }

    opt = argv[1];
    input = argv[2];
    output = argv[3];
    params = argv[4];

    if (strncasecmp(opt, "w=", 2) == 0) {
        char *end = NULL;
        w = strtol(opt + 2, &end, 10);
        if (!end || *end != '\0') {
            fprintf(stderr, "ERROR: invalid decimal integer '%s'\n",
                    opt + 2);
            return 1;
        } else if (w < 1) {
            fprintf(stderr, "ERROR: invalid width %d, must be >= 1\n", w);
            return 1;
        }
    } else if (strncasecmp(opt, "h=", 2) == 0) {
        char *end = NULL;
        h = strtol(opt + 2, &end, 10);
        if (!end || *end != '\0') {
            fprintf(stderr, "ERROR: invalid decimal integer '%s'\n",
                    opt + 2);
            return 1;
        } else if (h < 1) {
            fprintf(stderr, "ERROR: invalid height %d, must be >= 1\n", h);
            return 1;
        }
    } else if (strchr(opt, '%')) {
        char *end = NULL;
        scale = strtod(opt, &end);
        if (!end || *end != '%') {
            fprintf(stderr, "ERROR: invalid percentual '%s'\n", opt);
            return 1;
        } else if (scale <= 0.0) {
            fprintf(stderr, "ERROR: invalid percentual %g, must be > 0.0\n",
                    scale);
            return 1;
        }
        scale /= 100.0;
    } else if (strchr(opt, 'x')) {
        if (sscanf(opt, "%dx%d", &w, &h) != 2) {
            fprintf(stderr, "ERROR: invalid size format '%s'\n", opt);
            return 1;
        } else if (w < 1) {
            fprintf(stderr, "ERROR: invalid width %d, must be >= 1\n", w);
            return 1;
        } else {
            fprintf(stderr, "ERROR: invalid height %d, must be >= 1\n", h);
            return 1;
        }
    } else {
        fprintf(stderr,
                "ERROR: first parameter must be in format:\n"
                "\tpercentage%%    - example: 10%%\n"
                "\tWxH            - example: 1024x768\n"
                "\tw=W            - example: w=1024\n"
                "\th=H            - example: h=768\n"
                "But '%s' was used!\n",
                opt);
        return 1;
    }

    ecore_evas_init();
    evas_init();

    ee = ecore_evas_buffer_new(1, 1);
    bridge = ecore_evas_object_image_new(ee);
    img = evas_object_image_add(ecore_evas_object_evas_get(bridge));
    evas_object_image_smooth_scale_set(img, EINA_TRUE);

    if (w > 0 && h > 0)
        evas_object_image_load_size_set(img, w, h);

    evas_object_image_file_set(img, input, NULL);
    err = evas_object_image_load_error_get(img);
    if (err != EVAS_LOAD_ERROR_NONE) {
        const char *msg = evas_load_error_str(err);
        fprintf(stderr, "ERROR: could not load '%s': %s\n", input, msg);
        r = 1;
        goto end;
    }

    if (w < 1 || h < 1) {
        int iw, ih;
        evas_object_image_size_get(img, &iw, &ih);

        if (iw < 0 || ih < 0) {
            fprintf(stderr, "ERROR: invalid source image size %dx%d (%s)\n",
                    iw, ih, input);
            goto end;
        }

        if (scale > 0) {
            w = ceil(iw * scale);
            h = ceil(ih * scale);
        } else if (w < 1)
            w = ceil(iw * (double)h / (double)ih);
        else if (h < 1)
            h = ceil(ih * (double)w / (double)iw);

        if (iw != w && ih != h)
            evas_object_image_load_size_set(img, w, h);
    }

    printf("output: %s, size: %dx%d, alpha: %s, params: %s\n",
           output, w, h,
           evas_object_image_alpha_get(img) ? "yes" : "no",
           params ? params : "<none>");

    evas_object_image_fill_set(img, 0, 0, w, h);
    evas_object_resize(img, w, h);
    evas_object_show(img);

    evas_object_image_alpha_set(bridge, evas_object_image_alpha_get(img));
    evas_object_image_size_set(bridge, w, h);
    ecore_evas_manual_render(ecore_evas_object_ecore_evas_get(bridge));

    evas_object_image_save(bridge, output, NULL, params);

  end:
    evas_object_del(img);
    evas_object_del(bridge);
    ecore_evas_free(ee);

    evas_shutdown();
    ecore_evas_shutdown();

    return r;
}