This patch adds the function RDrawImage. This function is an interface to the internal functions of wraster, to paint the image on the screen.
Currently libwraster can create and draw RImage structs for these image types: * GIF * JPEG * TIFF * PNG * XPM * PPM The XPM and PNG images needs RContext info to draw the image, but the other types can draw the image directly. So, these patch hides this behaviour and the way to draw an image on the screen is call RLoadImage and then RDrawImage. RDrawImage returns the RImage directly for GIF, JPEG, TIFF and PPM, but it calls RDrawXPM and RDrawPNG for that image types. Signed-off-by: Rodolfo García Peñas (kix) <[email protected]> --- wrlib/imgformat.h | 2 ++ wrlib/load.c | 42 ++++++++++++++++++++++++++++++++++++++++++ wrlib/png.c | 2 -- wrlib/wraster.h | 1 + 4 files changed, 45 insertions(+), 2 deletions(-) diff --git a/wrlib/imgformat.h b/wrlib/imgformat.h index f75c219..ed200b2 100644 --- a/wrlib/imgformat.h +++ b/wrlib/imgformat.h @@ -35,6 +35,7 @@ RImage *RLoadPPM(const char *file); RImage *RLoadXPM(RContext *context, const char *file); +RImage *RDrawXPM(RContext *context, RImage *image); #ifdef USE_TIFF RImage *RLoadTIFF(const char *file, int index); @@ -42,6 +43,7 @@ RImage *RLoadTIFF(const char *file, int index); #ifdef USE_PNG RImage *RLoadPNG(RContext *context, const char *file); +RImage *RDrawPNG(RContext *context, RImage *image); #endif #ifdef USE_JPEG diff --git a/wrlib/load.c b/wrlib/load.c index 94ef564..a8821e0 100644 --- a/wrlib/load.c +++ b/wrlib/load.c @@ -238,6 +238,48 @@ RImage *RLoadImage(RContext * context, const char *file, int index) return image; } +RImage *RDrawImage(RContext *context, RImage *image) +{ + if (image == NULL) + return NULL; + + /* Select the rigth drawer */ + switch (image->srcformat) { + case IM_ERROR: + return NULL; + + case IM_UNKNOWN: + RErrorCode = RERR_BADFORMAT; + return NULL; + + /* Only PNG and XPM needs draw the image, + * other formats had the RImage ready + */ + case IM_TIFF: + case IM_JPEG: + case IM_GIF: + case IM_PPM: + return image; + break; + + case IM_XPM: + image = RDrawXPM(context, image); + break; + +#ifdef USE_PNG + case IM_PNG: + image = RDrawPNG(context, image); + break; +#endif /* USE_PNG */ + + default: + RErrorCode = RERR_BADFORMAT; + return NULL; + } + + return image; +} + char *RGetImageFileFormat(const char *file) { switch (identFile(file)) { diff --git a/wrlib/png.c b/wrlib/png.c index c4be981..b2f9746 100644 --- a/wrlib/png.c +++ b/wrlib/png.c @@ -33,8 +33,6 @@ #include "wraster.h" #include "imgformat.h" -RImage *RDrawPNG(RContext *context, RImage *image); - /* * png_structp png: Pointer on struct which contains pointer on our data * png_byte buffer: Where you have to copy the source data for libpng computing diff --git a/wrlib/wraster.h b/wrlib/wraster.h index f6a9995..88dc4a4 100644 --- a/wrlib/wraster.h +++ b/wrlib/wraster.h @@ -330,6 +330,7 @@ RImage *RCreateImageFromDrawable(RContext *context, Drawable drawable, Pixmap mask); RImage *RLoadImage(RContext *context, const char *file, int index); +RImage *RDrawImage(RContext *context, RImage *image); RImage* RRetainImage(RImage *image); -- 1.8.4.rc3 -- To unsubscribe, send mail to [email protected].
