Cleanup: use bool for imbuf save callbacks

This commit is contained in:
Campbell Barton 2020-11-11 16:14:05 +11:00
parent e9c19b2820
commit a5f8071bdf
18 changed files with 47 additions and 57 deletions

View File

@ -2953,13 +2953,11 @@ void BKE_imbuf_write_prepare(ImBuf *ibuf, const ImageFormatData *imf)
int BKE_imbuf_write(ImBuf *ibuf, const char *name, const ImageFormatData *imf)
{
int ok;
BKE_imbuf_write_prepare(ibuf, imf);
BLI_make_existing_file(name);
ok = IMB_saveiff(ibuf, name, IB_rect | IB_zbuf | IB_zbuffloat);
const bool ok = IMB_saveiff(ibuf, name, IB_rect | IB_zbuf | IB_zbuffloat);
if (ok == 0) {
perror(name);
}

View File

@ -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);
/**

View File

@ -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);

View File

@ -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;

View File

@ -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);
}

View File

@ -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 */

View File

@ -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,

View File

@ -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;
}

View File

@ -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, &parameters);
opj_codec_t *codec = NULL;
int ok = false;
bool ok = false;
/* JP2 format output */
{
/* get a JP2 compressor handle */

View File

@ -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;

View File

@ -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 ************************************ */

View File

@ -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);

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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);
}
}

View File

@ -265,7 +265,6 @@ static void seq_proxy_build_frame(const SeqRenderData *context,
char name[PROXY_MAXFILE];
int quality;
int rectx, recty;
int ok;
ImBuf *ibuf_tmp, *ibuf;
Editing *ed = context->scene->ed;
@ -305,8 +304,8 @@ static void seq_proxy_build_frame(const SeqRenderData *context,
BLI_make_existing_file(name);
ok = IMB_saveiff(ibuf, name, IB_rect | IB_zbuf | IB_zbuffloat);
if (ok == 0) {
const bool ok = IMB_saveiff(ibuf, name, IB_rect | IB_zbuf | IB_zbuffloat);
if (ok == false) {
perror(name);
}