This patch adds source image info to the RImage struct.

First, it adds the source image data. This info could be full processed
image or can contains the original file mapped into memory.

This patch also adds the type of source image to RImage. This field is
used to complete the source image data processing.

With this info is possible process the image when needed, not when the
image is loaded from disk.

Finally, this patch adds the functions to create and remove the src data
in the RCreate, RClone, RDestroy functions.

Signed-off-by: Rodolfo García Peñas (kix) <[email protected]>
---
 wrlib/raster.c  | 21 ++++++++++++++++++++-
 wrlib/wraster.h | 15 ++++++++-------
 2 files changed, 28 insertions(+), 8 deletions(-)

diff --git a/wrlib/raster.c b/wrlib/raster.c
index e2a2d99..8e0b650 100644
--- a/wrlib/raster.c
+++ b/wrlib/raster.c
@@ -62,6 +62,10 @@ RImage *RCreateImage(unsigned width, unsigned height, int 
alpha)
        image->height = height;
        image->format = alpha ? RRGBAFormat : RRGBFormat;
        image->refCount = 1;
+       image->srcformat = IM_UNKNOWN;
+       /* We should not allocate memory for image->srcdata, because not
+        * all images use it. The allocation should be done in xpm/png.c */
+       image->srcdata = NULL;
 
        /* the +4 is to give extra bytes at the end of the buffer,
         * so that we can optimize image conversion for MMX(tm).. see convert.c
@@ -93,11 +97,14 @@ void RReleaseImage(RImage * image)
 
        if (image->refCount < 1) {
                free(image->data);
+               if (image->srcdata)
+                       free(image->srcdata);
+
                free(image);
        }
 }
 
-RImage *RCloneImage(RImage * image)
+RImage *RCloneImage(RImage *image)
 {
        RImage *new_image;
 
@@ -108,8 +115,20 @@ RImage *RCloneImage(RImage * image)
                return NULL;
 
        new_image->background = image->background;
+       new_image->srcformat = image->srcformat;
        memcpy(new_image->data, image->data, image->width * image->height * 
(HAS_ALPHA(image) ? 4 : 3));
 
+       /* If png or xpm, with raw data */
+       if (image->srcdata) {
+               new_image->srcdatalen = image->srcdatalen;
+               if (image->srcdatalen > 0)
+                       new_image->srcdata = (unsigned char *) 
malloc(image->srcdatalen);
+               else
+                       return NULL;    /* This MUST not happend. printf 
warning? */
+
+               memcpy(new_image->srcdata, image->srcdata, image->srcdatalen);
+       }
+
        return new_image;
 }
 
diff --git a/wrlib/wraster.h b/wrlib/wraster.h
index 1c13e58..f6a9995 100644
--- a/wrlib/wraster.h
+++ b/wrlib/wraster.h
@@ -193,19 +193,20 @@ enum RImageFormat {
     RRGBAFormat
 };
 
-
 /*
  * internal 24bit+alpha image representation
  */
 typedef struct RImage {
-    unsigned char *data;       /* image data RGBA or RGB */
-    int width, height;    /* size of the image */
-    enum RImageFormat format;
-    RColor background;    /* background color */
-    int refCount;
+       unsigned char *data;            /* image data RGBA or RGB */
+       int width, height;              /* size of the image */
+       enum RImageFormat format;       /* RRGB or RRGBA formats */
+       WRImgFormat srcformat;          /* Source image format */
+       unsigned char *srcdata;         /* Source image data */
+       size_t srcdatalen;              /* Source image data lenght */
+       RColor background;              /* background color */
+       int refCount;
 } RImage;
 
-
 /*
  * internal wrapper for XImage. Used for shm abstraction
  */
-- 
1.8.4.rc3


-- 
To unsubscribe, send mail to [email protected].

Reply via email to