From a5f8071bdf7893ef487c677b460793e8bef55402 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 11 Nov 2020 16:14:05 +1100 Subject: Cleanup: use bool for imbuf save callbacks --- source/blender/imbuf/IMB_imbuf.h | 2 +- source/blender/imbuf/intern/IMB_filetype.h | 22 +++++++++++----------- source/blender/imbuf/intern/bmp.c | 2 +- source/blender/imbuf/intern/cineon/cineon_dpx.c | 4 ++-- source/blender/imbuf/intern/dds/dds_api.cpp | 10 +++++----- source/blender/imbuf/intern/dds/dds_api.h | 2 +- source/blender/imbuf/intern/iris.c | 9 ++++----- source/blender/imbuf/intern/jp2.c | 12 ++++++------ source/blender/imbuf/intern/jpeg.c | 4 ++-- .../blender/imbuf/intern/openexr/openexr_api.cpp | 8 ++++---- source/blender/imbuf/intern/openexr/openexr_api.h | 2 +- source/blender/imbuf/intern/png.c | 2 +- source/blender/imbuf/intern/radiance_hdr.c | 2 +- source/blender/imbuf/intern/targa.c | 2 +- source/blender/imbuf/intern/tiff.c | 3 +-- source/blender/imbuf/intern/writeimage.c | 9 ++------- 16 files changed, 44 insertions(+), 51 deletions(-) (limited to 'source/blender/imbuf') diff --git a/source/blender/imbuf/IMB_imbuf.h b/source/blender/imbuf/IMB_imbuf.h index 0f9aa7055e7..bb28c4b1234 100644 --- a/source/blender/imbuf/IMB_imbuf.h +++ b/source/blender/imbuf/IMB_imbuf.h @@ -466,7 +466,7 @@ void IMB_scaleImBuf_threaded(struct ImBuf *ibuf, unsigned int newx, unsigned int * * \attention Defined in writeimage.c */ -short IMB_saveiff(struct ImBuf *ibuf, const char *filepath, int flags); +bool IMB_saveiff(struct ImBuf *ibuf, const char *filepath, int flags); bool IMB_prepare_write_ImBuf(const bool isfloat, struct ImBuf *ibuf); /** diff --git a/source/blender/imbuf/intern/IMB_filetype.h b/source/blender/imbuf/intern/IMB_filetype.h index b7763976853..520e810fe32 100644 --- a/source/blender/imbuf/intern/IMB_filetype.h +++ b/source/blender/imbuf/intern/IMB_filetype.h @@ -39,7 +39,7 @@ typedef struct ImFileType { int flags, char colorspace[IM_MAX_SPACE]); struct ImBuf *(*load_filepath)(const char *filepath, int flags, char colorspace[IM_MAX_SPACE]); - int (*save)(struct ImBuf *ibuf, const char *filepath, int flags); + bool (*save)(struct ImBuf *ibuf, const char *filepath, int flags); void (*load_tile)(struct ImBuf *ibuf, const unsigned char *mem, size_t size, @@ -72,7 +72,7 @@ struct ImBuf *imb_loadpng(const unsigned char *mem, size_t size, int flags, char colorspace[IM_MAX_SPACE]); -int imb_savepng(struct ImBuf *ibuf, const char *filepath, int flags); +bool imb_savepng(struct ImBuf *ibuf, const char *filepath, int flags); /* targa */ int imb_is_a_targa(const unsigned char *buf); @@ -80,7 +80,7 @@ struct ImBuf *imb_loadtarga(const unsigned char *mem, size_t size, int flags, char colorspace[IM_MAX_SPACE]); -int imb_savetarga(struct ImBuf *ibuf, const char *filepath, int flags); +bool imb_savetarga(struct ImBuf *ibuf, const char *filepath, int flags); /* iris */ int imb_is_a_iris(const unsigned char *mem); @@ -88,7 +88,7 @@ struct ImBuf *imb_loadiris(const unsigned char *mem, size_t size, int flags, char colorspace[IM_MAX_SPACE]); -int imb_saveiris(struct ImBuf *ibuf, const char *filepath, int flags); +bool imb_saveiris(struct ImBuf *ibuf, const char *filepath, int flags); /* jp2 */ int imb_is_a_jp2(const unsigned char *buf); @@ -99,11 +99,11 @@ struct ImBuf *imb_load_jp2(const unsigned char *mem, struct ImBuf *imb_load_jp2_filepath(const char *filepath, int flags, char colorspace[IM_MAX_SPACE]); -int imb_save_jp2(struct ImBuf *ibuf, const char *filepath, int flags); +bool imb_save_jp2(struct ImBuf *ibuf, const char *filepath, int flags); /* jpeg */ int imb_is_a_jpeg(const unsigned char *mem); -int imb_savejpeg(struct ImBuf *ibuf, const char *filepath, int flags); +bool imb_savejpeg(struct ImBuf *ibuf, const char *filepath, int flags); struct ImBuf *imb_load_jpeg(const unsigned char *buffer, size_t size, int flags, @@ -115,11 +115,11 @@ struct ImBuf *imb_bmp_decode(const unsigned char *mem, size_t size, int flags, char colorspace[IM_MAX_SPACE]); -int imb_savebmp(struct ImBuf *ibuf, const char *filepath, int flags); +bool imb_savebmp(struct ImBuf *ibuf, const char *filepath, int flags); /* cineon */ int imb_is_a_cineon(const unsigned char *buf); -int imb_save_cineon(struct ImBuf *buf, const char *filepath, int flags); +bool imb_save_cineon(struct ImBuf *buf, const char *filepath, int flags); struct ImBuf *imb_load_cineon(const unsigned char *mem, size_t size, int flags, @@ -127,7 +127,7 @@ struct ImBuf *imb_load_cineon(const unsigned char *mem, /* dpx */ int imb_is_a_dpx(const unsigned char *buf); -int imb_save_dpx(struct ImBuf *buf, const char *filepath, int flags); +bool imb_save_dpx(struct ImBuf *buf, const char *filepath, int flags); struct ImBuf *imb_load_dpx(const unsigned char *mem, size_t size, int flags, @@ -139,7 +139,7 @@ struct ImBuf *imb_loadhdr(const unsigned char *mem, size_t size, int flags, char colorspace[IM_MAX_SPACE]); -int imb_savehdr(struct ImBuf *ibuf, const char *filepath, int flags); +bool imb_savehdr(struct ImBuf *ibuf, const char *filepath, int flags); /* tiff */ void imb_inittiff(void); @@ -150,4 +150,4 @@ struct ImBuf *imb_loadtiff(const unsigned char *mem, char colorspace[IM_MAX_SPACE]); void imb_loadtiletiff( struct ImBuf *ibuf, const unsigned char *mem, size_t size, int tx, int ty, unsigned int *rect); -int imb_savetiff(struct ImBuf *ibuf, const char *filepath, int flags); +bool imb_savetiff(struct ImBuf *ibuf, const char *filepath, int flags); diff --git a/source/blender/imbuf/intern/bmp.c b/source/blender/imbuf/intern/bmp.c index f7fdc7a8e80..6d1726af608 100644 --- a/source/blender/imbuf/intern/bmp.c +++ b/source/blender/imbuf/intern/bmp.c @@ -292,7 +292,7 @@ static int putShortLSB(ushort us, FILE *ofile) } /* Found write info at http://users.ece.gatech.edu/~slabaugh/personal/c/bitmapUnix.c */ -int imb_savebmp(ImBuf *ibuf, const char *filepath, int UNUSED(flags)) +bool imb_savebmp(ImBuf *ibuf, const char *filepath, int UNUSED(flags)) { BMPINFOHEADER infoheader; diff --git a/source/blender/imbuf/intern/cineon/cineon_dpx.c b/source/blender/imbuf/intern/cineon/cineon_dpx.c index 98082a97e0f..7907d648abe 100644 --- a/source/blender/imbuf/intern/cineon/cineon_dpx.c +++ b/source/blender/imbuf/intern/cineon/cineon_dpx.c @@ -183,7 +183,7 @@ static int imb_save_dpx_cineon(ImBuf *ibuf, const char *filename, int use_cineon return rvalue; } -int imb_save_cineon(struct ImBuf *buf, const char *filepath, int flags) +bool imb_save_cineon(struct ImBuf *buf, const char *filepath, int flags) { return imb_save_dpx_cineon(buf, filepath, 1, flags); } @@ -204,7 +204,7 @@ ImBuf *imb_load_cineon(const unsigned char *mem, return NULL; } -int imb_save_dpx(struct ImBuf *buf, const char *filepath, int flags) +bool imb_save_dpx(struct ImBuf *buf, const char *filepath, int flags) { return imb_save_dpx_cineon(buf, filepath, 0, flags); } diff --git a/source/blender/imbuf/intern/dds/dds_api.cpp b/source/blender/imbuf/intern/dds/dds_api.cpp index e620c968f1c..d8bcca7e1f5 100644 --- a/source/blender/imbuf/intern/dds/dds_api.cpp +++ b/source/blender/imbuf/intern/dds/dds_api.cpp @@ -42,16 +42,16 @@ extern "C" { -int imb_save_dds(struct ImBuf *ibuf, const char *name, int /*flags*/) +bool imb_save_dds(struct ImBuf *ibuf, const char *name, int /*flags*/) { - return 0; /* todo: finish this function */ + return false; /* todo: finish this function */ /* check image buffer */ if (ibuf == nullptr) { - return 0; + return false; } if (ibuf->rect == nullptr) { - return 0; + return false; } /* open file for writing */ @@ -69,7 +69,7 @@ int imb_save_dds(struct ImBuf *ibuf, const char *name, int /*flags*/) fildes << "DDS "; fildes.close(); - return 1; + return true; } int imb_is_a_dds(const unsigned char *mem) /* note: use at most first 32 bytes */ diff --git a/source/blender/imbuf/intern/dds/dds_api.h b/source/blender/imbuf/intern/dds/dds_api.h index 930205c9efb..ca74cbeaa74 100644 --- a/source/blender/imbuf/intern/dds/dds_api.h +++ b/source/blender/imbuf/intern/dds/dds_api.h @@ -27,7 +27,7 @@ extern "C" { #endif int imb_is_a_dds(const unsigned char *mem); /* use only first 32 bytes of mem */ -int imb_save_dds(struct ImBuf *ibuf, const char *name, int flags); +bool imb_save_dds(struct ImBuf *ibuf, const char *name, int flags); struct ImBuf *imb_load_dds(const unsigned char *mem, size_t size, int flags, diff --git a/source/blender/imbuf/intern/iris.c b/source/blender/imbuf/intern/iris.c index 214cdf1b63b..6bf2e3ec8d3 100644 --- a/source/blender/imbuf/intern/iris.c +++ b/source/blender/imbuf/intern/iris.c @@ -807,7 +807,7 @@ fail: * Added: zbuf write */ -static int output_iris(uint *lptr, int xsize, int ysize, int zsize, const char *name, int *zptr) +static bool output_iris(uint *lptr, int xsize, int ysize, int zsize, const char *name, int *zptr) { FILE *outf; IMAGE *image; @@ -969,10 +969,9 @@ static int compressrow(uchar *lbuf, uchar *rlebuf, int z, int cnt) return optr - (uchar *)rlebuf; } -int imb_saveiris(struct ImBuf *ibuf, const char *filepath, int flags) +bool imb_saveiris(struct ImBuf *ibuf, const char *filepath, int flags) { short zsize; - int ret; zsize = (ibuf->planes + 7) >> 3; if (flags & IB_zbuf && ibuf->zbuf != NULL) { @@ -982,11 +981,11 @@ int imb_saveiris(struct ImBuf *ibuf, const char *filepath, int flags) IMB_convert_rgba_to_abgr(ibuf); test_endian_zbuf(ibuf); - ret = output_iris(ibuf->rect, ibuf->x, ibuf->y, zsize, filepath, ibuf->zbuf); + const bool ok = output_iris(ibuf->rect, ibuf->x, ibuf->y, zsize, filepath, ibuf->zbuf); /* restore! Quite clumsy, 2 times a switch... maybe better a malloc ? */ IMB_convert_rgba_to_abgr(ibuf); test_endian_zbuf(ibuf); - return ret; + return ok; } diff --git a/source/blender/imbuf/intern/jp2.c b/source/blender/imbuf/intern/jp2.c index 97af0eb8feb..f0486852d6f 100644 --- a/source/blender/imbuf/intern/jp2.c +++ b/source/blender/imbuf/intern/jp2.c @@ -1194,22 +1194,22 @@ static opj_image_t *ibuftoimage(ImBuf *ibuf, opj_cparameters_t *parameters) return image; } -int imb_save_jp2_stream(struct ImBuf *ibuf, opj_stream_t *stream, int flags); +bool imb_save_jp2_stream(struct ImBuf *ibuf, opj_stream_t *stream, int flags); -int imb_save_jp2(struct ImBuf *ibuf, const char *filepath, int flags) +bool imb_save_jp2(struct ImBuf *ibuf, const char *filepath, int flags) { opj_stream_t *stream = opj_stream_create_from_file( filepath, OPJ_J2K_STREAM_CHUNK_SIZE, false, NULL); if (stream == NULL) { return 0; } - int ret = imb_save_jp2_stream(ibuf, stream, flags); + const bool ok = imb_save_jp2_stream(ibuf, stream, flags); opj_stream_destroy(stream); - return ret; + return ok; } /* Found write info at http://users.ece.gatech.edu/~slabaugh/personal/c/bitmapUnix.c */ -int imb_save_jp2_stream(struct ImBuf *ibuf, opj_stream_t *stream, int UNUSED(flags)) +bool imb_save_jp2_stream(struct ImBuf *ibuf, opj_stream_t *stream, int UNUSED(flags)) { int quality = ibuf->foptions.quality; @@ -1230,7 +1230,7 @@ int imb_save_jp2_stream(struct ImBuf *ibuf, opj_stream_t *stream, int UNUSED(fla image = ibuftoimage(ibuf, ¶meters); opj_codec_t *codec = NULL; - int ok = false; + bool ok = false; /* JP2 format output */ { /* get a JP2 compressor handle */ diff --git a/source/blender/imbuf/intern/jpeg.c b/source/blender/imbuf/intern/jpeg.c index 38f8806d910..fca24a1baa9 100644 --- a/source/blender/imbuf/intern/jpeg.c +++ b/source/blender/imbuf/intern/jpeg.c @@ -608,7 +608,7 @@ static int init_jpeg(FILE *outfile, struct jpeg_compress_struct *cinfo, struct I return 0; } -static int save_stdjpeg(const char *name, struct ImBuf *ibuf) +static bool save_stdjpeg(const char *name, struct ImBuf *ibuf) { FILE *outfile; struct jpeg_compress_struct _cinfo, *cinfo = &_cinfo; @@ -642,7 +642,7 @@ static int save_stdjpeg(const char *name, struct ImBuf *ibuf) return 1; } -int imb_savejpeg(struct ImBuf *ibuf, const char *filepath, int flags) +bool imb_savejpeg(struct ImBuf *ibuf, const char *filepath, int flags) { ibuf->flags = flags; diff --git a/source/blender/imbuf/intern/openexr/openexr_api.cpp b/source/blender/imbuf/intern/openexr/openexr_api.cpp index 40a502a14db..6d4cff4d18d 100644 --- a/source/blender/imbuf/intern/openexr/openexr_api.cpp +++ b/source/blender/imbuf/intern/openexr/openexr_api.cpp @@ -586,7 +586,7 @@ static bool imb_save_openexr_float(ImBuf *ibuf, const char *name, const int flag return true; } -int imb_save_openexr(struct ImBuf *ibuf, const char *name, int flags) +bool imb_save_openexr(struct ImBuf *ibuf, const char *name, int flags) { if (flags & IB_mem) { imb_addencodedbufferImBuf(ibuf); @@ -594,15 +594,15 @@ int imb_save_openexr(struct ImBuf *ibuf, const char *name, int flags) } if (ibuf->foptions.flag & OPENEXR_HALF) { - return (int)imb_save_openexr_half(ibuf, name, flags); + return imb_save_openexr_half(ibuf, name, flags); } /* when no float rect, we save as half (16 bits is sufficient) */ if (ibuf->rect_float == nullptr) { - return (int)imb_save_openexr_half(ibuf, name, flags); + return imb_save_openexr_half(ibuf, name, flags); } - return (int)imb_save_openexr_float(ibuf, name, flags); + return imb_save_openexr_float(ibuf, name, flags); } /* ******* Nicer API, MultiLayer and with Tile file support ************************************ */ diff --git a/source/blender/imbuf/intern/openexr/openexr_api.h b/source/blender/imbuf/intern/openexr/openexr_api.h index 73db146849b..fcbd9b803b8 100644 --- a/source/blender/imbuf/intern/openexr/openexr_api.h +++ b/source/blender/imbuf/intern/openexr/openexr_api.h @@ -34,7 +34,7 @@ void imb_exitopenexr(void); int imb_is_a_openexr(const unsigned char *mem); -int imb_save_openexr(struct ImBuf *ibuf, const char *name, int flags); +bool imb_save_openexr(struct ImBuf *ibuf, const char *name, int flags); struct ImBuf *imb_load_openexr(const unsigned char *mem, size_t size, int flags, char *colorspace); diff --git a/source/blender/imbuf/intern/png.c b/source/blender/imbuf/intern/png.c index 5b3311e5dd0..1f90f91be3e 100644 --- a/source/blender/imbuf/intern/png.c +++ b/source/blender/imbuf/intern/png.c @@ -118,7 +118,7 @@ BLI_INLINE unsigned short ftoshort(float val) return unit_float_to_ushort_clamp(val); } -int imb_savepng(struct ImBuf *ibuf, const char *filepath, int flags) +bool imb_savepng(struct ImBuf *ibuf, const char *filepath, int flags) { png_structp png_ptr; png_infop info_ptr; diff --git a/source/blender/imbuf/intern/radiance_hdr.c b/source/blender/imbuf/intern/radiance_hdr.c index 8de243e52bc..adeed444c80 100644 --- a/source/blender/imbuf/intern/radiance_hdr.c +++ b/source/blender/imbuf/intern/radiance_hdr.c @@ -411,7 +411,7 @@ static void writeHeader(FILE *file, int width, int height) fputc(10, file); } -int imb_savehdr(struct ImBuf *ibuf, const char *filepath, int flags) +bool imb_savehdr(struct ImBuf *ibuf, const char *filepath, int flags) { FILE *file = BLI_fopen(filepath, "wb"); float *fp = NULL; diff --git a/source/blender/imbuf/intern/targa.c b/source/blender/imbuf/intern/targa.c index 0efc8dee2db..6d156a637d3 100644 --- a/source/blender/imbuf/intern/targa.c +++ b/source/blender/imbuf/intern/targa.c @@ -294,7 +294,7 @@ static bool dumptarga(struct ImBuf *ibuf, FILE *file) return 1; } -int imb_savetarga(struct ImBuf *ibuf, const char *filepath, int UNUSED(flags)) +bool imb_savetarga(struct ImBuf *ibuf, const char *filepath, int UNUSED(flags)) { char buf[TARGA_HEADER_SIZE] = {0}; FILE *fildes; diff --git a/source/blender/imbuf/intern/tiff.c b/source/blender/imbuf/intern/tiff.c index bc69a14fa47..aa58eaa125d 100644 --- a/source/blender/imbuf/intern/tiff.c +++ b/source/blender/imbuf/intern/tiff.c @@ -759,8 +759,7 @@ void imb_loadtiletiff( * * \return 1 if the function is successful, 0 on failure. */ - -int imb_savetiff(ImBuf *ibuf, const char *filepath, int flags) +bool imb_savetiff(ImBuf *ibuf, const char *filepath, int flags) { TIFF *image = NULL; uint16 samplesperpixel, bitspersample; diff --git a/source/blender/imbuf/intern/writeimage.c b/source/blender/imbuf/intern/writeimage.c index e321470559a..71ecc8b14ae 100644 --- a/source/blender/imbuf/intern/writeimage.c +++ b/source/blender/imbuf/intern/writeimage.c @@ -41,7 +41,7 @@ static bool prepare_write_imbuf(const ImFileType *type, ImBuf *ibuf) return IMB_prepare_write_ImBuf((type->flag & IM_FTYPE_FLOAT), ibuf); } -short IMB_saveiff(struct ImBuf *ibuf, const char *filepath, int flags) +bool IMB_saveiff(struct ImBuf *ibuf, const char *filepath, int flags) { const ImFileType *type; @@ -56,13 +56,8 @@ short IMB_saveiff(struct ImBuf *ibuf, const char *filepath, int flags) for (type = IMB_FILE_TYPES; type < IMB_FILE_TYPES_LAST; type++) { if (type->save && type->ftype(type, ibuf)) { - short result = false; - prepare_write_imbuf(type, ibuf); - - result = type->save(ibuf, filepath, flags); - - return result; + return type->save(ibuf, filepath, flags); } } -- cgit v1.2.3