The new function RLoadImage_nodraw loads the image but doesn't run
the code to draw it. The code to draw it depends on the screen for
PNG and XPM images, so now we can create image structs without
screen, and write code screen-independent.

The function RLoadImage_core do now the previous code of RLoadImage
and includes a flag to draw or not the image (call or not the RDraw*
functions). Because the RLoadImage_core needs the RContext info,
we must set to NULL in RLoadImage_nodraw and set the flag to False.

If the flag is set to True, to run the RLoadImage and draw the image
but the RContext is NULL (wrong code), the RDraw{PNG,GIF} returns
NULL as image.

The programmer can call now RLoadImage() (same code before this patch)
and RLoadImage_nodraw().

I wrote this patch with the "RLoadImage_core() + flag" to avoid copy
the full RLoadImage and remove only two lines for RLoadImage_nodraw.

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

diff --git a/wrlib/libwraster.map b/wrlib/libwraster.map
index 2abe767..365daa2 100644
--- a/wrlib/libwraster.map
+++ b/wrlib/libwraster.map
@@ -53,6 +53,7 @@ LIBWRASTER3
     RHSVtoRGB;
     RLightImage;
     RLoadImage;
+    RLoadImage_nodraw;
     RMakeCenteredImage;
     RMakeTiledImage;
     RMessageForError;
diff --git a/wrlib/load.c b/wrlib/load.c
index 1af9678..5f24d51 100644
--- a/wrlib/load.c
+++ b/wrlib/load.c
@@ -189,7 +189,7 @@ static void store_image_in_cache(RImage *image, const char 
*file, struct stat *s
        }
 }
 
-RImage *RLoadImage(RContext *context, const char *file, int index)
+static RImage *RLoadImage_core(RContext *context, const char *file, int index, 
Bool drawflag)
 {
        RImage *image = NULL;
        struct stat st;
@@ -210,7 +210,8 @@ RImage *RLoadImage(RContext *context, const char *file, int 
index)
 
        case IM_XPM:
                image = RLoadXPM(file);
-               image = RDrawXPM(context, image);
+               if (drawflag)
+                       image = RDrawXPM(context, image);
                break;
 
 #ifdef USE_TIFF
@@ -222,7 +223,8 @@ RImage *RLoadImage(RContext *context, const char *file, int 
index)
 #ifdef USE_PNG
        case IM_PNG:
                image = RLoadPNG(file);
-               image = RDrawPNG(context, image);
+               if (drawflag)
+                       image = RDrawPNG(context, image);
                break;
 #endif                         /* USE_PNG */
 
@@ -252,6 +254,19 @@ RImage *RLoadImage(RContext *context, const char *file, 
int index)
        return image;
 }
 
+/* Load and Draw the image on the screen */
+RImage *RLoadImage(RContext *context, const char *file, int index)
+{
+       return RLoadImage_core(context, file, index, True);
+}
+
+/* Load the image, but not draw it on the screen */
+RImage *RLoadImage_nodraw(const char *file, int index)
+{
+       /* RContext is NULL. Screen is not needed */
+       return RLoadImage_core(NULL, file, index, False);
+}
+
 RImage *RDrawImage(RContext *context, RImage *image)
 {
        if (image == NULL)
diff --git a/wrlib/wraster.h b/wrlib/wraster.h
index 88dc4a4..99b7b74 100644
--- a/wrlib/wraster.h
+++ b/wrlib/wraster.h
@@ -414,6 +414,8 @@ void RDrawSegments(RImage *image, const RSegment *segs, int 
nsegs, const RColor
 void ROperateSegments(RImage *image, int operation, const RSegment *segs, int 
nsegs,
                       const RColor *color);
 
+RImage *RLoadImage_nodraw(const char *file, int index);
+
 /*
  * Color convertion
  */
-- 
1.8.4.rc3


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

Reply via email to