[evas] Documenting the following:
authorglima <glima@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Thu, 30 Jun 2011 21:55:16 +0000 (21:55 +0000)
committerglima <glima@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Thu, 30 Jun 2011 21:55:16 +0000 (21:55 +0000)
 - evas_object_image_preload
 - evas_object_image_reload
 - evas_object_image_save
 - evas_object_image_scale_hint_get
 - evas_object_image_scale_hint_set
 - evas_object_image_size_get
 - evas_object_image_size_set

git-svn-id: svn+ssh://svn.enlightenment.org/var/svn/e/trunk/evas@60889 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33

doc/examples.dox
src/examples/evas-images2.c
src/lib/Evas.h

index feb3d3c..c0276ad 100644 (file)
  * @dontinclude evas-images2.c
  * @skip noise_img =
  * @until show
- * There's a last command to print it's @b stride value. Since its
- * created with one quarter of the canvas's original width
+ * Since we are creating the data for its pixel buffer ourselves, we
+ * have to set its size with @c evas_object_image_size_set. There's a
+ * last command to print it's @b stride value. Since its created with
+ * one quarter of the canvas's original width
  * @dontinclude evas-images2.c
  * @skip define WIDTH
  * @until define HEIGHT
  * you can check this value.
  *
+ * The image on the top left also has a subtlety: it is @b pre-loaded
+ * on this example.
+ * @dontinclude evas-images2.c
+ * @skip d.logo =
+ * @until show
+ * On real use cases we wouldn't be just printing something like this
+ * @dontinclude evas-images2.c
+ * @skip static void
+ * @until }
+ * naturally.
+ *
+ * The 's' command will save one of the images on the disk, in the png
+ * format:
+ * @dontinclude evas-images2.c
+ * @skip if (strcmp(ev->keyname, "a") == 0)
+ * @until }
+ *
  * The full example follows.
  *
  * @include evas-images2.c
index 5ba251a..df9b8f8 100644 (file)
@@ -2,8 +2,8 @@
  * Simple Evas example illustrating some image objects functions
  *
  * You'll need at least one engine built for it (excluding the buffer
- * one) and the png image loader also built. See stdout/stderr for
- * output.
+ * one) and the png image loader/saver also built. See stdout/stderr
+ * for output.
  *
  * @verbatim
  * gcc -o evas-images3 evas-images3.c `pkg-config --libs --cflags ecore-evas`
@@ -28,8 +28,12 @@ static const char *commands = \
   "commands are:\n"
   "\tp - change proxy image's source\n"
   "\ts - print noise image's stride value\n"
+  "\ta - save noise image to disk (/tmp dir)\n"
   "\th - print help\n";
 
+const char *file_path = "/tmp/evas-images2-example.png";
+const char *quality_str = "quality=100";
+
 struct test_data
 {
    Ecore_Evas  *ee;
@@ -40,6 +44,15 @@ struct test_data
 static struct test_data d = {0};
 
 static void
+_on_preloaded(void        *data __UNUSED__,
+              Evas        *e __UNUSED__,
+              Evas_Object *obj __UNUSED__,
+              void        *event_info __UNUSED__)
+{
+    fprintf(stdout, "Image has been pre-loaded!\n");
+}
+
+static void
 _on_destroy(Ecore_Evas *ee __UNUSED__)
 {
    ecore_main_loop_quit();
@@ -74,8 +87,8 @@ _on_keydown(void        *data __UNUSED__,
      {
         int stride = evas_object_image_stride_get(d.noise_img);
 
-        fprintf(stdout,"Image has row stride value of %d, which accounts"
-                " for %d pixels\n", stride, stride / 4);
+        fprintf(stdout, "Image has row stride value of %d, which accounts"
+                        " for %d pixels\n", stride, stride / 4);
 
         return;
      }
@@ -93,6 +106,18 @@ _on_keydown(void        *data __UNUSED__,
 
         return;
      }
+
+   if (strcmp(ev->keyname, "a") == 0) /* save noise image to disk */
+     {
+        if (!evas_object_image_save(d.noise_img, file_path, NULL, quality_str))
+          fprintf(stderr, "Cannot save image to '%s' (flags '%s')\n",
+                  file_path, quality_str);
+        else
+          fprintf(stdout, "Image saved to '%s' (flags '%s'), check it out with "
+                          "an image viewer\n", file_path, quality_str);
+
+        return;
+     }
 }
 
 int
@@ -130,6 +155,11 @@ main(void)
      d.bg, EVAS_CALLBACK_KEY_DOWN, _on_keydown, NULL);
 
    d.logo = evas_object_image_filled_add(d.evas);
+
+   evas_object_event_callback_add(
+       d.logo, EVAS_CALLBACK_IMAGE_PRELOADED, _on_preloaded, NULL);
+   evas_object_image_preload(d.logo, EINA_TRUE);
+
    evas_object_image_file_set(d.logo, img_path, NULL);
    evas_object_image_fill_set(d.logo, 0, 0, WIDTH / 2, HEIGHT / 2);
    evas_object_resize(d.logo, WIDTH / 2, HEIGHT / 2);
@@ -143,14 +173,12 @@ main(void)
    evas_object_image_size_set(d.noise_img, WIDTH / 4, HEIGHT / 4);
    evas_object_image_data_set(d.noise_img, pixels);
    evas_object_image_filled_set(d.noise_img, EINA_TRUE);
-   evas_object_move(d.noise_img, (WIDTH * 3)/ 4, 0);
+   evas_object_move(d.noise_img, (WIDTH * 3) / 4, 0);
    evas_object_resize(d.noise_img, WIDTH / 4, HEIGHT / 4);
    evas_object_show(d.noise_img);
    fprintf(stdout, "Creating noise image with size %d, %d\n",
            WIDTH / 4, HEIGHT / 4);
 
-   /* todo: option to save noise image to /tmp dir */
-
    d.proxy_img = evas_object_image_filled_add(d.evas);
    evas_object_image_source_set(d.proxy_img, d.logo);
    evas_object_move(d.proxy_img, WIDTH / 4, HEIGHT / 2);
index b2a0462..d98e749 100644 (file)
@@ -5722,26 +5722,26 @@ EAPI Evas_Fill_Spread         evas_object_image_fill_spread_get        (const Ev
 /**
  * Sets the size of the given image object.
  *
+ * @param obj The given image object.
+ * @param w The new width of the image.
+ * @param h The new height of the image.
+ *
  * This function will scale down or crop the image so that it is
  * treated as if it were at the given size. If the size given is
  * smaller than the image, it will be cropped. If the size given is
  * larger, then the image will be treated as if it were in the upper
  * left hand corner of a larger image that is otherwise transparent.
- *
- * @param obj The given image object.
- * @param w The new width of the image.
- * @param h The new height of the image.
  */
 EAPI void                     evas_object_image_size_set               (Evas_Object *obj, int w, int h) EINA_ARG_NONNULL(1);
 
 /**
  * Retrieves the size of the given image object.
  *
- * See @ref evas_object_image_size_set for more details.
- *
  * @param obj The given image object.
  * @param w Location to store the width of the image in, or @c NULL.
  * @param h Location to store the height of the image in, or @c NULL.
+ *
+ * See @ref evas_object_image_size_set() for more details.
  */
 EAPI void                     evas_object_image_size_get               (const Evas_Object *obj, int *w, int *h) EINA_ARG_NONNULL(1);
 
@@ -5914,46 +5914,53 @@ EAPI void                     evas_object_image_smooth_scale_set       (Evas_Obj
 EAPI Eina_Bool                evas_object_image_smooth_scale_get       (const Evas_Object *obj) EINA_WARN_UNUSED_RESULT EINA_ARG_NONNULL(1) EINA_PURE;
 
 /**
- * Preload image in the background
+ * Preload an image object's image data in the background
  *
- * This function request the preload of the data image in the
- * background. The worked is queued before being processed.
+ * @param obj The given image object.
+ * @param cancel @c EINA_FALSE will add it the preloading work queue,
+ *               @c EINA_TRUE will remove it (if it was issued before).
  *
- * If image data is already loaded, it will callback
- * EVAS_CALLBACK_IMAGE_PRELOADED immediately and do nothing else.
+ * This function requests the preload of the data image in the
+ * background. The work is queued before being processed (because
+ * there might be other pending requests of this type).
  *
- * If cancel is set, it will remove the image from the workqueue.
+ * Whenever the image data gets loaded, Evas will call
+ * #EVAS_CALLBACK_IMAGE_PRELOADED registered callbacks on @p obj (what
+ * may be immediately, if the data was already preloaded before).
  *
- * @param obj The given image object.
- * @param cancel 0 means add to the workqueue, 1 remove it.
+ * Use @c EINA_TRUE for @p cancel on scenarios where you don't need
+ * the image data preloaded anymore.
  */
 EAPI void                     evas_object_image_preload                (Evas_Object *obj, Eina_Bool cancel) EINA_ARG_NONNULL(1);
 
 /**
- * Reload a image of the canvas.
+ * Reload an image object's image data.
  *
  * @param obj The given image object pointer.
  *
- * This function reloads a image of the given canvas.
- *
+ * This function reloads the image data bound to image object @p obj.
  */
 EAPI void                     evas_object_image_reload                 (Evas_Object *obj) EINA_ARG_NONNULL(1);
 
 /**
- * Save the given image object to a file.
+ * Save the given image object's contents to an (image) file.
  *
- * Note that you should pass the filename extension when saving.  If
- * the file supports multiple data stored in it as eet, you can
- * specify the key to be used as the index of the image in this file.
+ * @param obj The given image object.
+ * @param file The filename to be used to save the image (extension
+ *        obligatory).
+ * @param key The image key in the file (if an Eet one), or @c NULL,
+ *        otherwise.
+ * @param flags String containing the flags to be used (@c NULL for
+ *        none).
+ *
+ * The extension suffix on @p file will determine which <b>saver
+ * module</b> Evas is to use when saving, thus the final file's
+ * format. If the file supports multiple data stored in it (Eet ones),
+ * you can specify the key to be used as the index of the image in it.
  *
  * You can specify some flags when saving the image.  Currently
- * acceptable flags are quality and compress.  Eg.: "quality=100
- * compress=9"
- *
- * @param obj The given image object.
- * @param file The filename to be used to save the image.
- * @param key The image key in file, or @c NULL.
- * @param flags String containing the flags to be used.
+ * acceptable flags are @c quality and @c compress. Eg.: @c
+ * "quality=100 compress=9"
  */
 EAPI Eina_Bool                evas_object_image_save                   (const Evas_Object *obj, const char *file, const char *key, const char *flags)  EINA_ARG_NONNULL(1, 2);
 
@@ -6133,8 +6140,10 @@ EAPI Evas_Native_Surface     *evas_object_image_native_surface_get     (const Ev
  * @param obj The given canvas pointer.
  * @param hint The scale hint value.
  *
- * This function sets the scale hint value of the given image of the canvas.
+ * This function sets the scale hint value of the given image of the
+ * canvas, which will affect how Evas is to scale it.
  *
+ * @see evas_object_image_scale_hint_get()
  */
 EAPI void                     evas_object_image_scale_hint_set         (Evas_Object *obj, Evas_Image_Scale_Hint hint) EINA_ARG_NONNULL(1);
 
@@ -6143,8 +6152,10 @@ EAPI void                     evas_object_image_scale_hint_set         (Evas_Obj
  *
  * @param obj The given canvas pointer.
  *
- * This function returns the scale hint value of the given image of the canvas.
+ * This function returns the scale hint value of the given image of
+ * the canvas.
  *
+ * @see evas_object_image_scale_hint_set()
  */
 EAPI Evas_Image_Scale_Hint    evas_object_image_scale_hint_get         (const Evas_Object *obj) EINA_WARN_UNUSED_RESULT EINA_ARG_NONNULL(1) EINA_PURE;