diff options
Diffstat (limited to 'source/blender/imbuf')
63 files changed, 681 insertions, 520 deletions
diff --git a/source/blender/imbuf/CMakeLists.txt b/source/blender/imbuf/CMakeLists.txt index cad0be659ec..cf637a06405 100644 --- a/source/blender/imbuf/CMakeLists.txt +++ b/source/blender/imbuf/CMakeLists.txt @@ -23,6 +23,7 @@ set(INC ../blenkernel ../blenlib ../blenloader + ../gpu ../makesdna ../makesrna ../../../intern/guardedalloc @@ -63,6 +64,7 @@ set(SRC intern/thumbs_blend.c intern/thumbs_font.c intern/util.c + intern/util_gpu.c intern/writeimage.c IMB_colormanagement.h diff --git a/source/blender/imbuf/IMB_colormanagement.h b/source/blender/imbuf/IMB_colormanagement.h index 4530f6c9fc0..54f126684ae 100644 --- a/source/blender/imbuf/IMB_colormanagement.h +++ b/source/blender/imbuf/IMB_colormanagement.h @@ -17,8 +17,7 @@ * All rights reserved. */ -#ifndef __IMB_COLORMANAGEMENT_H__ -#define __IMB_COLORMANAGEMENT_H__ +#pragma once /** \file * \ingroup imbuf @@ -374,5 +373,3 @@ enum { #endif #include "intern/colormanagement_inline.c" - -#endif /* __IMB_COLORMANAGEMENT_H__ */ diff --git a/source/blender/imbuf/IMB_imbuf.h b/source/blender/imbuf/IMB_imbuf.h index 478297e61b2..37046521dd8 100644 --- a/source/blender/imbuf/IMB_imbuf.h +++ b/source/blender/imbuf/IMB_imbuf.h @@ -53,8 +53,7 @@ * posix-compliant. */ -#ifndef __IMB_IMBUF_H__ -#define __IMB_IMBUF_H__ +#pragma once /* for bool */ #include "../blenlib/BLI_sys_types.h" @@ -90,6 +89,12 @@ struct Stereo3dFormat; /** * + * \attention defined in GPU_texture.h + */ +struct GPUTexture; + +/** + * * \attention Defined in allocimbuf.c */ void IMB_init(void); @@ -729,6 +734,25 @@ const char *IMB_ffmpeg_last_error(void); /** * + * \attention defined in util_gpu.c + */ +struct GPUTexture *IMB_create_gpu_texture(struct ImBuf *ibuf, + bool use_high_bitdepth, + bool use_premult); +struct GPUTexture *IMB_touch_gpu_texture( + struct ImBuf *ibuf, int w, int h, int layers, bool use_high_bitdepth); +void IMB_update_gpu_texture_sub(struct GPUTexture *tex, + struct ImBuf *ibuf, + int x, + int y, + int z, + int w, + int h, + bool use_high_bitdepth, + bool use_premult); + +/** + * * \attention defined in stereoimbuf.c */ void IMB_stereo3d_write_dimensions(const char mode, @@ -766,5 +790,3 @@ void IMB_ImBufFromStereo3d(struct Stereo3dFormat *s3d, #ifdef __cplusplus } #endif - -#endif diff --git a/source/blender/imbuf/IMB_imbuf_types.h b/source/blender/imbuf/IMB_imbuf_types.h index ddc8394264a..98e9c34a4ff 100644 --- a/source/blender/imbuf/IMB_imbuf_types.h +++ b/source/blender/imbuf/IMB_imbuf_types.h @@ -17,8 +17,7 @@ * All rights reserved. */ -#ifndef __IMB_IMBUF_TYPES_H__ -#define __IMB_IMBUF_TYPES_H__ +#pragma once #include "DNA_vec_types.h" /* for rcti */ @@ -353,5 +352,3 @@ enum { #ifdef __cplusplus } #endif - -#endif /* __IMB_IMBUF_TYPES_H__ */ diff --git a/source/blender/imbuf/IMB_metadata.h b/source/blender/imbuf/IMB_metadata.h index edbdd7be482..501bf9dfba1 100644 --- a/source/blender/imbuf/IMB_metadata.h +++ b/source/blender/imbuf/IMB_metadata.h @@ -21,8 +21,7 @@ * \ingroup imbuf */ -#ifndef __IMB_METADATA_H__ -#define __IMB_METADATA_H__ +#pragma once #ifdef __cplusplus extern "C" { @@ -84,5 +83,3 @@ void IMB_metadata_foreach(struct ImBuf *ibuf, IMBMetadataForeachCb callback, voi #ifdef __cplusplus } #endif - -#endif /* __IMB_METADATA_H__ */ diff --git a/source/blender/imbuf/IMB_moviecache.h b/source/blender/imbuf/IMB_moviecache.h index 5fb158f0d8b..8e5f15a64a0 100644 --- a/source/blender/imbuf/IMB_moviecache.h +++ b/source/blender/imbuf/IMB_moviecache.h @@ -17,8 +17,7 @@ * All rights reserved. */ -#ifndef __IMB_MOVIECACHE_H__ -#define __IMB_MOVIECACHE_H__ +#pragma once /** \file * \ingroup imbuf @@ -85,5 +84,3 @@ void *IMB_moviecacheIter_getUserKey(struct MovieCacheIter *iter); #ifdef __cplusplus } #endif - -#endif diff --git a/source/blender/imbuf/IMB_thumbs.h b/source/blender/imbuf/IMB_thumbs.h index 00e9a810ef3..e8c244aaba7 100644 --- a/source/blender/imbuf/IMB_thumbs.h +++ b/source/blender/imbuf/IMB_thumbs.h @@ -21,8 +21,7 @@ * \ingroup imbuf */ -#ifndef __IMB_THUMBS_H__ -#define __IMB_THUMBS_H__ +#pragma once #ifdef __cplusplus extern "C" { @@ -98,5 +97,3 @@ void IMB_thumb_path_unlock(const char *path); #ifdef __cplusplus } #endif /* __cplusplus */ - -#endif /* __IMB_THUMBS_H__ */ diff --git a/source/blender/imbuf/intern/IMB_allocimbuf.h b/source/blender/imbuf/intern/IMB_allocimbuf.h index 9f89969cf1c..08aa1936a6f 100644 --- a/source/blender/imbuf/intern/IMB_allocimbuf.h +++ b/source/blender/imbuf/intern/IMB_allocimbuf.h @@ -21,8 +21,7 @@ * \ingroup imbuf * \brief Header file for allocimbuf.c */ -#ifndef __IMB_ALLOCIMBUF_H__ -#define __IMB_ALLOCIMBUF_H__ +#pragma once #ifdef __cplusplus extern "C" { @@ -51,5 +50,3 @@ bool imb_enlargeencodedbufferImBuf(struct ImBuf *ibuf); #ifdef __cplusplus } #endif - -#endif diff --git a/source/blender/imbuf/intern/IMB_anim.h b/source/blender/imbuf/intern/IMB_anim.h index 3d1d99963c7..babff5c34cd 100644 --- a/source/blender/imbuf/intern/IMB_anim.h +++ b/source/blender/imbuf/intern/IMB_anim.h @@ -21,8 +21,7 @@ * \ingroup imbuf */ -#ifndef __IMB_ANIM_H__ -#define __IMB_ANIM_H__ +#pragma once #ifdef _WIN32 # define INC_OLE2 @@ -152,5 +151,3 @@ struct anim { struct IDProperty *metadata; }; - -#endif diff --git a/source/blender/imbuf/intern/IMB_colormanagement_intern.h b/source/blender/imbuf/intern/IMB_colormanagement_intern.h index 79abe8472b9..6b505a7171a 100644 --- a/source/blender/imbuf/intern/IMB_colormanagement_intern.h +++ b/source/blender/imbuf/intern/IMB_colormanagement_intern.h @@ -17,8 +17,7 @@ * All rights reserved. */ -#ifndef __IMB_COLORMANAGEMENT_INTERN_H__ -#define __IMB_COLORMANAGEMENT_INTERN_H__ +#pragma once /** \file * \ingroup imbuf @@ -130,5 +129,3 @@ void colormanage_imbuf_make_linear(struct ImBuf *ibuf, const char *from_colorspa #ifdef __cplusplus } #endif - -#endif /* __IMB_COLORMANAGEMENT_INTERN_H__ */ diff --git a/source/blender/imbuf/intern/IMB_filetype.h b/source/blender/imbuf/intern/IMB_filetype.h index ce731a3a86d..2b00b87d3d2 100644 --- a/source/blender/imbuf/intern/IMB_filetype.h +++ b/source/blender/imbuf/intern/IMB_filetype.h @@ -18,8 +18,7 @@ * \ingroup imbuf */ -#ifndef __IMB_FILETYPE_H__ -#define __IMB_FILETYPE_H__ +#pragma once #include "IMB_imbuf.h" @@ -151,5 +150,3 @@ struct ImBuf *imb_loadtiff(const unsigned char *mem, 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 *name, int flags); - -#endif /* __IMB_FILETYPE_H__ */ diff --git a/source/blender/imbuf/intern/IMB_filter.h b/source/blender/imbuf/intern/IMB_filter.h index 2cd785e6889..556362d78c1 100644 --- a/source/blender/imbuf/intern/IMB_filter.h +++ b/source/blender/imbuf/intern/IMB_filter.h @@ -22,8 +22,7 @@ * \brief Function declarations for filter.c */ -#ifndef __IMB_FILTER_H__ -#define __IMB_FILTER_H__ +#pragma once struct ImBuf; @@ -36,5 +35,3 @@ void IMB_unpremultiply_rect(unsigned int *rect, char planes, int w, int h); void IMB_unpremultiply_rect_float(float *rect_float, int channels, int w, int h); void imb_onehalf_no_alloc(struct ImBuf *ibuf2, struct ImBuf *ibuf1); - -#endif diff --git a/source/blender/imbuf/intern/IMB_indexer.h b/source/blender/imbuf/intern/IMB_indexer.h index 446aaa0655e..7cd11e137c2 100644 --- a/source/blender/imbuf/intern/IMB_indexer.h +++ b/source/blender/imbuf/intern/IMB_indexer.h @@ -14,8 +14,7 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -#ifndef __IMB_INDEXER_H__ -#define __IMB_INDEXER_H__ +#pragma once /** \file * \ingroup imbuf @@ -113,5 +112,3 @@ struct anim_index *IMB_anim_open_index(struct anim *anim, IMB_Timecode_Type tc); int IMB_proxy_size_to_array_index(IMB_Proxy_Size pr_size); int IMB_timecode_to_array_index(IMB_Timecode_Type tc); - -#endif diff --git a/source/blender/imbuf/intern/allocimbuf.c b/source/blender/imbuf/intern/allocimbuf.c index 4b3858e6d5a..8dfb3ada7d6 100644 --- a/source/blender/imbuf/intern/allocimbuf.c +++ b/source/blender/imbuf/intern/allocimbuf.c @@ -423,9 +423,8 @@ bool imb_addrectImBuf(ImBuf *ibuf) if (ibuf->planes > 32) { return (addzbufImBuf(ibuf)); } - else { - return true; - } + + return true; } return false; @@ -489,7 +488,7 @@ ImBuf *IMB_allocImBuf(unsigned int x, unsigned int y, uchar planes, unsigned int } } - return (ibuf); + return ibuf; } bool IMB_initImBuf( @@ -624,7 +623,7 @@ ImBuf *IMB_dupImBuf(const ImBuf *ibuf1) *ibuf2 = tbuf; - return (ibuf2); + return ibuf2; } size_t IMB_get_size_in_memory(ImBuf *ibuf) diff --git a/source/blender/imbuf/intern/anim_movie.c b/source/blender/imbuf/intern/anim_movie.c index 9fab450cc76..f5ae602946e 100644 --- a/source/blender/imbuf/intern/anim_movie.c +++ b/source/blender/imbuf/intern/anim_movie.c @@ -301,7 +301,7 @@ struct anim *IMB_open_anim(const char *name, anim->ib_flags = ib_flags; anim->streamindex = streamindex; } - return (anim); + return anim; } bool IMB_anim_can_produce_frames(const struct anim *anim) @@ -743,7 +743,7 @@ static int startffmpeg(struct anim *anim) } # endif - return (0); + return 0; } /* postprocess the image in anim->pFrame and do color conversion @@ -803,7 +803,7 @@ static void ffmpeg_postprocess(struct anim *anim) if (ENDIAN_ORDER == B_ENDIAN) { int *dstStride = anim->pFrameRGB->linesize; uint8_t **dst = anim->pFrameRGB->data; - int dstStride2[4] = {dstStride[0], 0, 0, 0}; + const int dstStride2[4] = {dstStride[0], 0, 0, 0}; uint8_t *dst2[4] = {dst[0], 0, 0, 0}; int x, y, h, w; unsigned char *bottom; @@ -849,7 +849,7 @@ static void ffmpeg_postprocess(struct anim *anim) else { int *dstStride = anim->pFrameRGB->linesize; uint8_t **dst = anim->pFrameRGB->data; - int dstStride2[4] = {-dstStride[0], 0, 0, 0}; + const int dstStride2[4] = {-dstStride[0], 0, 0, 0}; uint8_t *dst2[4] = {dst[0] + (anim->y - 1) * dstStride[0], 0, 0, 0}; sws_scale(anim->img_convert_ctx, @@ -1060,7 +1060,7 @@ static ImBuf *ffmpeg_fetchibuf(struct anim *anim, int position, IMB_Timecode_Typ int old_frame_index = 0; /* To quiet gcc barking... */ if (anim == NULL) { - return (0); + return 0; } av_log(anim->pFormatCtx, AV_LOG_DEBUG, "FETCH: pos=%d\n", position); @@ -1291,7 +1291,7 @@ static ImBuf *anim_getnew(struct anim *anim) struct ImBuf *ibuf = NULL; if (anim == NULL) { - return (NULL); + return NULL; } free_anim_movie(anim); @@ -1305,7 +1305,7 @@ static ImBuf *anim_getnew(struct anim *anim) #endif if (anim->curtype != 0) { - return (NULL); + return NULL; } anim->curtype = imb_get_anim_type(anim->name); @@ -1319,7 +1319,7 @@ static ImBuf *anim_getnew(struct anim *anim) break; case ANIM_MOVIE: if (startmovie(anim)) { - return (NULL); + return NULL; } ibuf = IMB_allocImBuf(anim->x, anim->y, 24, 0); /* fake */ break; @@ -1327,7 +1327,7 @@ static ImBuf *anim_getnew(struct anim *anim) case ANIM_AVI: if (startavi(anim)) { printf("couldn't start avi\n"); - return (NULL); + return NULL; } ibuf = IMB_allocImBuf(anim->x, anim->y, 24, 0); break; @@ -1335,13 +1335,13 @@ static ImBuf *anim_getnew(struct anim *anim) #ifdef WITH_FFMPEG case ANIM_FFMPEG: if (startffmpeg(anim)) { - return (0); + return 0; } ibuf = IMB_allocImBuf(anim->x, anim->y, 24, 0); break; #endif } - return (ibuf); + return ibuf; } struct ImBuf *IMB_anim_previewframe(struct anim *anim) @@ -1369,7 +1369,7 @@ struct ImBuf *IMB_anim_absolute(struct anim *anim, int pic; int filter_y; if (anim == NULL) { - return (NULL); + return NULL; } filter_y = (anim->ib_flags & IB_animdeinterlace); @@ -1378,7 +1378,7 @@ struct ImBuf *IMB_anim_absolute(struct anim *anim, if (anim->curtype == 0) { ibuf = anim_getnew(anim); if (ibuf == NULL) { - return (NULL); + return NULL; } IMB_freeImBuf(ibuf); /* ???? */ @@ -1386,10 +1386,10 @@ struct ImBuf *IMB_anim_absolute(struct anim *anim, } if (position < 0) { - return (NULL); + return NULL; } if (position >= anim->duration_in_frames) { - return (NULL); + return NULL; } } else { @@ -1444,7 +1444,7 @@ struct ImBuf *IMB_anim_absolute(struct anim *anim, } BLI_snprintf(ibuf->name, sizeof(ibuf->name), "%s.%04d", anim->name, anim->curposition + 1); } - return (ibuf); + return ibuf; } /***/ diff --git a/source/blender/imbuf/intern/bmp.c b/source/blender/imbuf/intern/bmp.c index 3cac0be7935..31f8b651eff 100644 --- a/source/blender/imbuf/intern/bmp.c +++ b/source/blender/imbuf/intern/bmp.c @@ -101,7 +101,7 @@ static int checkbmp(const uchar *mem) } } - return (ret_val); + return ret_val; } int imb_is_a_bmp(const uchar *buf) @@ -123,7 +123,7 @@ ImBuf *imb_bmp_decode(const uchar *mem, size_t size, int flags, char colorspace[ (void)size; /* unused */ if (checkbmp(mem) == 0) { - return (NULL); + return NULL; } colorspace_set_default_role(colorspace, IM_MAX_SPACE, COLOR_ROLE_DEFAULT_BYTE); @@ -272,7 +272,7 @@ ImBuf *imb_bmp_decode(const uchar *mem, size_t size, int flags, char colorspace[ ibuf->ftype = IMB_FTYPE_BMP; } - return (ibuf); + return ibuf; } #undef CHECK_HEADER_FIELD_BMP diff --git a/source/blender/imbuf/intern/cineon/cineon_dpx.c b/source/blender/imbuf/intern/cineon/cineon_dpx.c index 18942c9abb8..50785d7a857 100644 --- a/source/blender/imbuf/intern/cineon/cineon_dpx.c +++ b/source/blender/imbuf/intern/cineon/cineon_dpx.c @@ -139,7 +139,7 @@ static int imb_save_dpx_cineon(ImBuf *ibuf, const char *filename, int use_cineon /* don't use the float buffer to save 8 bpp picture to prevent color banding * (there's no dithering algorithm behind the logImageSetDataRGBA function) */ - fbuf = (float *)MEM_mallocN(ibuf->x * ibuf->y * 4 * sizeof(float), + fbuf = (float *)MEM_mallocN(sizeof(float[4]) * ibuf->x * ibuf->y, "fbuf in imb_save_dpx_cineon"); for (y = 0; y < ibuf->y; y++) { @@ -158,7 +158,7 @@ static int imb_save_dpx_cineon(ImBuf *ibuf, const char *filename, int use_cineon IMB_rect_from_float(ibuf); } - fbuf = (float *)MEM_mallocN(ibuf->x * ibuf->y * 4 * sizeof(float), + fbuf = (float *)MEM_mallocN(sizeof(float[4]) * ibuf->x * ibuf->y, "fbuf in imb_save_dpx_cineon"); if (fbuf == NULL) { printf("DPX/Cineon: error allocating memory.\n"); diff --git a/source/blender/imbuf/intern/cineon/cineonlib.h b/source/blender/imbuf/intern/cineon/cineonlib.h index 040435e44ee..d1225027b4c 100644 --- a/source/blender/imbuf/intern/cineon/cineonlib.h +++ b/source/blender/imbuf/intern/cineon/cineonlib.h @@ -23,8 +23,7 @@ * Also handles DPX files (almost) */ -#ifndef __CINEONLIB_H__ -#define __CINEONLIB_H__ +#pragma once #include "logImageCore.h" @@ -135,5 +134,3 @@ LogImageFile *cineonCreate( #ifdef __cplusplus } #endif - -#endif /* __CINEONLIB_H__ */ diff --git a/source/blender/imbuf/intern/cineon/dpxlib.c b/source/blender/imbuf/intern/cineon/dpxlib.c index 8acfc23439f..73003265d8d 100644 --- a/source/blender/imbuf/intern/cineon/dpxlib.c +++ b/source/blender/imbuf/intern/cineon/dpxlib.c @@ -207,7 +207,7 @@ LogImageFile *dpxOpen(const unsigned char *byteStuff, int fromMemory, size_t buf dpx->srcFormat = format_DPX; dpx->numElements = swap_ushort(header.imageHeader.elements_per_image, dpx->isMSB); - size_t max_elements = sizeof(header.imageHeader.element) / sizeof(header.imageHeader.element[0]); + size_t max_elements = ARRAY_SIZE(header.imageHeader.element); if (dpx->numElements == 0 || dpx->numElements >= max_elements) { if (verbose) { printf("DPX: Wrong number of elements: %d\n", dpx->numElements); diff --git a/source/blender/imbuf/intern/cineon/dpxlib.h b/source/blender/imbuf/intern/cineon/dpxlib.h index 3a7ebe9dddf..6b729dba59a 100644 --- a/source/blender/imbuf/intern/cineon/dpxlib.h +++ b/source/blender/imbuf/intern/cineon/dpxlib.h @@ -22,8 +22,7 @@ * DPX image file format library definitions. */ -#ifndef __DPXLIB_H__ -#define __DPXLIB_H__ +#pragma once #include "logImageCore.h" @@ -160,5 +159,3 @@ LogImageFile *dpxCreate(const char *filename, #ifdef __cplusplus } #endif - -#endif /* __DPXLIB_H__ */ diff --git a/source/blender/imbuf/intern/cineon/logImageCore.c b/source/blender/imbuf/intern/cineon/logImageCore.c index e9030496498..6a81abd96e3 100644 --- a/source/blender/imbuf/intern/cineon/logImageCore.c +++ b/source/blender/imbuf/intern/cineon/logImageCore.c @@ -119,7 +119,7 @@ LogImageFile *logImageOpenFromFile(const char *filename, int cineon) if (logImageIsDpx(&magicNum)) { return dpxOpen((const unsigned char *)filename, 0, 0); } - else if (logImageIsCineon(&magicNum)) { + if (logImageIsCineon(&magicNum)) { return cineonOpen((const unsigned char *)filename, 0, 0); } @@ -131,7 +131,7 @@ LogImageFile *logImageOpenFromMemory(const unsigned char *buffer, unsigned int s if (logImageIsDpx(buffer)) { return dpxOpen(buffer, 1, size); } - else if (logImageIsCineon(buffer)) { + if (logImageIsCineon(buffer)) { return cineonOpen(buffer, 1, size); } @@ -154,18 +154,17 @@ LogImageFile *logImageCreate(const char *filename, if (cineon) { return cineonCreate(filename, width, height, bitsPerSample, creator); } - else { - return dpxCreate(filename, - width, - height, - bitsPerSample, - isLogarithmic, - hasAlpha, - referenceWhite, - referenceBlack, - gamma, - creator); - } + + return dpxCreate(filename, + width, + height, + bitsPerSample, + isLogarithmic, + hasAlpha, + referenceWhite, + referenceBlack, + gamma, + creator); return NULL; } @@ -484,7 +483,7 @@ int logImageGetDataRGBA(LogImageFile *logImage, float *data, int dataIsLinearRGB memcpy(&mergedElement, &logImage->element[0], sizeof(LogImageElement)); mergedElement.descriptor = -1; mergedElement.depth = logImage->depth; - memset(&sortedElementData, -1, 8 * sizeof(int)); + memset(&sortedElementData, -1, sizeof(int[8])); /* Try to know how to assemble the elements */ for (i = 0; i < logImage->numElements; i++) { @@ -1677,7 +1676,7 @@ static int convertLogElementToRGBA( if (rvalue == 1) { return 1; } - else if (dstIsLinearRGB) { + if (dstIsLinearRGB) { /* convert data from sRGB to Linear RGB via lut */ float *lut = getSrgbToLinLut(logElement); src_ptr = dst; // no error here diff --git a/source/blender/imbuf/intern/cineon/logImageCore.h b/source/blender/imbuf/intern/cineon/logImageCore.h index 3d49da7eb42..a2d50f21a98 100644 --- a/source/blender/imbuf/intern/cineon/logImageCore.h +++ b/source/blender/imbuf/intern/cineon/logImageCore.h @@ -27,8 +27,7 @@ * Hmm. I thought the two formats would have more in common! */ -#ifndef __LOGIMAGECORE_H__ -#define __LOGIMAGECORE_H__ +#pragma once #include <stdio.h> @@ -295,5 +294,3 @@ BLI_INLINE unsigned int float_uint(float value, unsigned int max) #ifdef __cplusplus } #endif - -#endif /* __LOGIMAGECORE_H__ */ diff --git a/source/blender/imbuf/intern/cineon/logmemfile.c b/source/blender/imbuf/intern/cineon/logmemfile.c index 91351d309de..aca84df91ca 100644 --- a/source/blender/imbuf/intern/cineon/logmemfile.c +++ b/source/blender/imbuf/intern/cineon/logmemfile.c @@ -64,10 +64,9 @@ int logimage_fwrite(void *buffer, size_t size, unsigned int count, LogImageFile if (logFile->file) { return fwrite(buffer, size, count, logFile->file); } - else { /* we're writing to memory */ - /* do nothing as this isn't supported yet */ - return count; - } + /* we're writing to memory */ + /* do nothing as this isn't supported yet */ + return count; } int logimage_fread(void *buffer, size_t size, unsigned int count, LogImageFile *logFile) @@ -75,23 +74,22 @@ int logimage_fread(void *buffer, size_t size, unsigned int count, LogImageFile * if (logFile->file) { return fread(buffer, size, count, logFile->file); } - else { /* we're reading from memory */ - unsigned char *buf = (unsigned char *)buffer; - uintptr_t pos = (uintptr_t)logFile->memCursor - (uintptr_t)logFile->memBuffer; - size_t total_size = size * count; - if (pos + total_size > logFile->memBufferSize) { - /* how many elements can we read without overflow ? */ - count = (logFile->memBufferSize - pos) / size; - /* recompute the size */ - total_size = size * count; - } - - if (total_size != 0) { - memcpy(buf, logFile->memCursor, total_size); - } + /* we're reading from memory */ + unsigned char *buf = (unsigned char *)buffer; + uintptr_t pos = (uintptr_t)logFile->memCursor - (uintptr_t)logFile->memBuffer; + size_t total_size = size * count; + if (pos + total_size > logFile->memBufferSize) { + /* how many elements can we read without overflow ? */ + count = (logFile->memBufferSize - pos) / size; + /* recompute the size */ + total_size = size * count; + } - return count; + if (total_size != 0) { + memcpy(buf, logFile->memCursor, total_size); } + + return count; } int logimage_read_uchar(unsigned char *x, LogImageFile *logFile) diff --git a/source/blender/imbuf/intern/cineon/logmemfile.h b/source/blender/imbuf/intern/cineon/logmemfile.h index d0ca03193e5..fd67011ef30 100644 --- a/source/blender/imbuf/intern/cineon/logmemfile.h +++ b/source/blender/imbuf/intern/cineon/logmemfile.h @@ -22,8 +22,7 @@ * Cineon image file format library routines. */ -#ifndef __LOGMEMFILE_H__ -#define __LOGMEMFILE_H__ +#pragma once #include "logImageCore.h" @@ -35,5 +34,3 @@ int logimage_fread(void *buffer, size_t size, unsigned int count, LogImageFile * int logimage_read_uchar(unsigned char *x, LogImageFile *logFile); int logimage_read_ushort(unsigned short *x, LogImageFile *logFile); int logimage_read_uint(unsigned int *x, LogImageFile *logFile); - -#endif /* __LOGMEMFILE_H__ */ diff --git a/source/blender/imbuf/intern/colormanagement.c b/source/blender/imbuf/intern/colormanagement.c index c9b3db39976..2c42d59a2d9 100644 --- a/source/blender/imbuf/intern/colormanagement.c +++ b/source/blender/imbuf/intern/colormanagement.c @@ -1399,9 +1399,8 @@ const char *IMB_colormanagement_get_float_colorspace(ImBuf *ibuf) if (ibuf->float_colorspace) { return ibuf->float_colorspace->name; } - else { - return IMB_colormanagement_role_colorspace_name_get(COLOR_ROLE_SCENE_LINEAR); - } + + return IMB_colormanagement_role_colorspace_name_get(COLOR_ROLE_SCENE_LINEAR); } const char *IMB_colormanagement_get_rect_colorspace(ImBuf *ibuf) @@ -1409,9 +1408,8 @@ const char *IMB_colormanagement_get_rect_colorspace(ImBuf *ibuf) if (ibuf->rect_colorspace) { return ibuf->rect_colorspace->name; } - else { - return IMB_colormanagement_role_colorspace_name_get(COLOR_ROLE_DEFAULT_BYTE); - } + + return IMB_colormanagement_role_colorspace_name_get(COLOR_ROLE_DEFAULT_BYTE); } bool IMB_colormanagement_space_is_data(ColorSpace *colorspace) @@ -2344,7 +2342,7 @@ void IMB_colormanagement_imbuf_to_float_texture(float *out_buffer, } } else { - memcpy(out, in, sizeof(float) * 4 * width); + memcpy(out, in, sizeof(float[4]) * width); } } } @@ -3513,7 +3511,7 @@ static void partial_buffer_update_rect(ImBuf *ibuf, size_t display_offset = ((size_t)display_stride * i + xmin) * 4; memcpy( - display_buffer + display_offset, byte_buffer + byte_offset, 4 * sizeof(char) * width); + display_buffer + display_offset, byte_buffer + byte_offset, sizeof(char[4]) * width); } } } @@ -3958,7 +3956,7 @@ static void curve_mapping_to_ocio_settings(CurveMapping *curve_mapping, { int i; - BKE_curvemapping_initialize(curve_mapping); + BKE_curvemapping_init(curve_mapping); BKE_curvemapping_premultiply(curve_mapping, false); BKE_curvemapping_table_RGBA( curve_mapping, &curve_mapping_settings->lut, &curve_mapping_settings->lut_size); diff --git a/source/blender/imbuf/intern/dds/BlockDXT.cpp b/source/blender/imbuf/intern/dds/BlockDXT.cpp index 9fd6d71e091..1fbe7b46963 100644 --- a/source/blender/imbuf/intern/dds/BlockDXT.cpp +++ b/source/blender/imbuf/intern/dds/BlockDXT.cpp @@ -97,21 +97,20 @@ uint BlockDXT1::evaluatePalette(Color32 color_array[4]) const return 4; } - else { - // Three-color block: derive the other color. - color_array[2].r = (color_array[0].r + color_array[1].r) / 2; - color_array[2].g = (color_array[0].g + color_array[1].g) / 2; - color_array[2].b = (color_array[0].b + color_array[1].b) / 2; - color_array[2].a = 0xFF; - // Set all components to 0 to match DXT specs. - color_array[3].r = 0x00; // color_array[2].r; - color_array[3].g = 0x00; // color_array[2].g; - color_array[3].b = 0x00; // color_array[2].b; - color_array[3].a = 0x00; + // Three-color block: derive the other color. + color_array[2].r = (color_array[0].r + color_array[1].r) / 2; + color_array[2].g = (color_array[0].g + color_array[1].g) / 2; + color_array[2].b = (color_array[0].b + color_array[1].b) / 2; + color_array[2].a = 0xFF; - return 3; - } + // Set all components to 0 to match DXT specs. + color_array[3].r = 0x00; // color_array[2].r; + color_array[3].g = 0x00; // color_array[2].g; + color_array[3].b = 0x00; // color_array[2].b; + color_array[3].a = 0x00; + + return 3; } uint BlockDXT1::evaluatePaletteNV5x(Color32 color_array[4]) const @@ -143,21 +142,20 @@ uint BlockDXT1::evaluatePaletteNV5x(Color32 color_array[4]) const return 4; } - else { - // Three-color block: derive the other color. - color_array[2].r = ((col0.r + col1.r) * 33) / 8; - color_array[2].g = (256 * color_array[0].g + gdiff / 4 + 128 + gdiff * 128) / 256; - color_array[2].b = ((col0.b + col1.b) * 33) / 8; - color_array[2].a = 0xFF; - // Set all components to 0 to match DXT specs. - color_array[3].r = 0x00; // color_array[2].r; - color_array[3].g = 0x00; // color_array[2].g; - color_array[3].b = 0x00; // color_array[2].b; - color_array[3].a = 0x00; + // Three-color block: derive the other color. + color_array[2].r = ((col0.r + col1.r) * 33) / 8; + color_array[2].g = (256 * color_array[0].g + gdiff / 4 + 128 + gdiff * 128) / 256; + color_array[2].b = ((col0.b + col1.b) * 33) / 8; + color_array[2].a = 0xFF; - return 3; - } + // Set all components to 0 to match DXT specs. + color_array[3].r = 0x00; // color_array[2].r; + color_array[3].g = 0x00; // color_array[2].g; + color_array[3].b = 0x00; // color_array[2].b; + color_array[3].a = 0x00; + + return 3; } // Evaluate palette assuming 3 color block. diff --git a/source/blender/imbuf/intern/dds/BlockDXT.h b/source/blender/imbuf/intern/dds/BlockDXT.h index 57430dbaea2..70ec8808c61 100644 --- a/source/blender/imbuf/intern/dds/BlockDXT.h +++ b/source/blender/imbuf/intern/dds/BlockDXT.h @@ -48,8 +48,7 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR // OTHER DEALINGS IN THE SOFTWARE. -#ifndef __BLOCKDXT_H__ -#define __BLOCKDXT_H__ +#pragma once #include <Color.h> #include <ColorBlock.h> @@ -305,5 +304,3 @@ void mem_read(Stream &mem, BlockDXT5 &block); void mem_read(Stream &mem, BlockATI1 &block); void mem_read(Stream &mem, BlockATI2 &block); void mem_read(Stream &mem, BlockCTX1 &block); - -#endif /* __BLOCKDXT_H__ */ diff --git a/source/blender/imbuf/intern/dds/Color.h b/source/blender/imbuf/intern/dds/Color.h index 36e2615759b..d0b67d4638c 100644 --- a/source/blender/imbuf/intern/dds/Color.h +++ b/source/blender/imbuf/intern/dds/Color.h @@ -27,8 +27,7 @@ // This code is in the public domain -- castanyo@yahoo.es -#ifndef __COLOR_H__ -#define __COLOR_H__ +#pragma once /// 32 bit color stored as BGRA. class Color32 { @@ -116,5 +115,3 @@ class Color16 { unsigned short u; }; }; - -#endif /* __COLOR_H__ */ diff --git a/source/blender/imbuf/intern/dds/ColorBlock.h b/source/blender/imbuf/intern/dds/ColorBlock.h index 2e8a6bbda7f..dd63286e230 100644 --- a/source/blender/imbuf/intern/dds/ColorBlock.h +++ b/source/blender/imbuf/intern/dds/ColorBlock.h @@ -27,8 +27,7 @@ // This code is in the public domain -- castanyo@yahoo.es -#ifndef __COLORBLOCK_H__ -#define __COLORBLOCK_H__ +#pragma once #include <Color.h> #include <Image.h> @@ -91,5 +90,3 @@ inline Color32 &ColorBlock::color(uint x, uint y) { return m_color[y * 4 + x]; } - -#endif /* __COLORBLOCK_H__ */ diff --git a/source/blender/imbuf/intern/dds/Common.h b/source/blender/imbuf/intern/dds/Common.h index 56f5d54cf42..90ec347a9ad 100644 --- a/source/blender/imbuf/intern/dds/Common.h +++ b/source/blender/imbuf/intern/dds/Common.h @@ -18,8 +18,7 @@ * \ingroup imbdds */ -#ifndef __COMMON_H__ -#define __COMMON_H__ +#pragma once #ifndef MIN # define MIN(a, b) ((a) <= (b) ? (a) : (b)) @@ -49,5 +48,3 @@ inline uint computePitch(uint w, uint bitsize, uint alignment) { return ((w * bitsize + 8 * alignment - 1) / (8 * alignment)) * alignment; } - -#endif diff --git a/source/blender/imbuf/intern/dds/DirectDrawSurface.cpp b/source/blender/imbuf/intern/dds/DirectDrawSurface.cpp index 9730153819e..7ec059607c5 100644 --- a/source/blender/imbuf/intern/dds/DirectDrawSurface.cpp +++ b/source/blender/imbuf/intern/dds/DirectDrawSurface.cpp @@ -864,9 +864,8 @@ uint DDSHeader::d3d9Format() const if (pf.flags & DDPF_FOURCC) { return pf.fourcc; } - else { - return findD3D9Format(pf.bitcount, pf.rmask, pf.gmask, pf.bmask, pf.amask); - } + + return findD3D9Format(pf.bitcount, pf.rmask, pf.gmask, pf.bmask, pf.amask); } DirectDrawSurface::DirectDrawSurface(unsigned char *mem, uint size) : stream(mem, size), header() @@ -923,33 +922,32 @@ bool DirectDrawSurface::isSupported() const return false; } - else { - if (header.pf.flags & DDPF_FOURCC) { - if (header.pf.fourcc != FOURCC_DXT1 && header.pf.fourcc != FOURCC_DXT2 && - header.pf.fourcc != FOURCC_DXT3 && header.pf.fourcc != FOURCC_DXT4 && - header.pf.fourcc != FOURCC_DXT5 && header.pf.fourcc != FOURCC_RXGB && - header.pf.fourcc != FOURCC_ATI1 && header.pf.fourcc != FOURCC_ATI2) { - // Unknown fourcc code. - return false; - } - } - else if ((header.pf.flags & DDPF_RGB) || (header.pf.flags & DDPF_LUMINANCE)) { - // All RGB and luminance formats are supported now. - } - else { - return false; - } - if (isTextureCube() && - (header.caps.caps2 & DDSCAPS2_CUBEMAP_ALL_FACES) != DDSCAPS2_CUBEMAP_ALL_FACES) { - // Cubemaps must contain all faces. + if (header.pf.flags & DDPF_FOURCC) { + if (header.pf.fourcc != FOURCC_DXT1 && header.pf.fourcc != FOURCC_DXT2 && + header.pf.fourcc != FOURCC_DXT3 && header.pf.fourcc != FOURCC_DXT4 && + header.pf.fourcc != FOURCC_DXT5 && header.pf.fourcc != FOURCC_RXGB && + header.pf.fourcc != FOURCC_ATI1 && header.pf.fourcc != FOURCC_ATI2) { + // Unknown fourcc code. return false; } + } + else if ((header.pf.flags & DDPF_RGB) || (header.pf.flags & DDPF_LUMINANCE)) { + // All RGB and luminance formats are supported now. + } + else { + return false; + } - if (isTexture3D()) { - // @@ 3D textures not supported yet. - return false; - } + if (isTextureCube() && + (header.caps.caps2 & DDSCAPS2_CUBEMAP_ALL_FACES) != DDSCAPS2_CUBEMAP_ALL_FACES) { + // Cubemaps must contain all faces. + return false; + } + + if (isTexture3D()) { + // @@ 3D textures not supported yet. + return false; } return true; @@ -963,23 +961,21 @@ bool DirectDrawSurface::hasAlpha() const header.header10.dxgiFormat == DXGI_FORMAT_BC2_UNORM || header.header10.dxgiFormat == DXGI_FORMAT_BC3_UNORM; } - else { - if (header.pf.flags & DDPF_RGB) { - return header.pf.amask != 0; - } - else if (header.pf.flags & DDPF_FOURCC) { - if (header.pf.fourcc == FOURCC_RXGB || header.pf.fourcc == FOURCC_ATI1 || - header.pf.fourcc == FOURCC_ATI2 || header.pf.flags & DDPF_NORMAL) { - return false; - } - else { - // @@ Here we could check the ALPHA_PIXELS flag, but nobody sets it. (except us?) - return true; - } + + if (header.pf.flags & DDPF_RGB) { + return header.pf.amask != 0; + } + if (header.pf.flags & DDPF_FOURCC) { + if (header.pf.fourcc == FOURCC_RXGB || header.pf.fourcc == FOURCC_ATI1 || + header.pf.fourcc == FOURCC_ATI2 || header.pf.flags & DDPF_NORMAL) { + return false; } - return false; + // @@ Here we could check the ALPHA_PIXELS flag, but nobody sets it. (except us?) + return true; } + + return false; } uint DirectDrawSurface::mipmapCount() const @@ -987,9 +983,8 @@ uint DirectDrawSurface::mipmapCount() const if (header.flags & DDSD_MIPMAPCOUNT) { return header.mipmapcount; } - else { - return 1; - } + + return 1; } uint DirectDrawSurface::fourCC() const @@ -1002,9 +997,8 @@ uint DirectDrawSurface::width() const if (header.flags & DDSD_WIDTH) { return header.width; } - else { - return 1; - } + + return 1; } uint DirectDrawSurface::height() const @@ -1012,9 +1006,8 @@ uint DirectDrawSurface::height() const if (header.flags & DDSD_HEIGHT) { return header.height; } - else { - return 1; - } + + return 1; } uint DirectDrawSurface::depth() const @@ -1022,9 +1015,8 @@ uint DirectDrawSurface::depth() const if (header.flags & DDSD_DEPTH) { return header.depth; } - else { - return 1; - } + + return 1; } bool DirectDrawSurface::isTexture1D() const @@ -1040,9 +1032,8 @@ bool DirectDrawSurface::isTexture2D() const if (header.hasDX10Header()) { return header.header10.resourceDimension == D3D10_RESOURCE_DIMENSION_TEXTURE2D; } - else { - return !isTexture3D() && !isTextureCube(); - } + + return !isTexture3D() && !isTextureCube(); } bool DirectDrawSurface::isTexture3D() const @@ -1050,9 +1041,8 @@ bool DirectDrawSurface::isTexture3D() const if (header.hasDX10Header()) { return header.header10.resourceDimension == D3D10_RESOURCE_DIMENSION_TEXTURE3D; } - else { - return (header.caps.caps2 & DDSCAPS2_VOLUME) != 0; - } + + return (header.caps.caps2 & DDSCAPS2_VOLUME) != 0; } bool DirectDrawSurface::isTextureCube() const @@ -1355,16 +1345,15 @@ uint DirectDrawSurface::mipmapSize(uint mipmap) const h = (h + 3) / 4; return blockSize() * w * h; } - else if (header.pf.flags & DDPF_RGB || (header.pf.flags & DDPF_LUMINANCE)) { + if (header.pf.flags & DDPF_RGB || (header.pf.flags & DDPF_LUMINANCE)) { uint pitch = computePitch( w, header.pf.bitcount, 8); // Assuming 8 bit alignment, which is the same D3DX expects. return pitch * h * d; } - else { - printf("DDS: mipmap format not supported\n"); - return (0); - } + + printf("DDS: mipmap format not supported\n"); + return 0; } uint DirectDrawSurface::faceSize() const diff --git a/source/blender/imbuf/intern/dds/DirectDrawSurface.h b/source/blender/imbuf/intern/dds/DirectDrawSurface.h index f12c45d11df..ac7f893fddd 100644 --- a/source/blender/imbuf/intern/dds/DirectDrawSurface.h +++ b/source/blender/imbuf/intern/dds/DirectDrawSurface.h @@ -48,8 +48,7 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR // OTHER DEALINGS IN THE SOFTWARE. -#ifndef __DIRECTDRAWSURFACE_H__ -#define __DIRECTDRAWSURFACE_H__ +#pragma once #include <ColorBlock.h> #include <Common.h> @@ -184,5 +183,3 @@ void mem_read(Stream &mem, DDSPixelFormat &pf); void mem_read(Stream &mem, DDSCaps &caps); void mem_read(Stream &mem, DDSHeader &header); void mem_read(Stream &mem, DDSHeader10 &header); - -#endif /* __DIRECTDRAWSURFACE_H__ */ diff --git a/source/blender/imbuf/intern/dds/FlipDXT.cpp b/source/blender/imbuf/intern/dds/FlipDXT.cpp index f5c937654b3..f46f50eb2b9 100644 --- a/source/blender/imbuf/intern/dds/FlipDXT.cpp +++ b/source/blender/imbuf/intern/dds/FlipDXT.cpp @@ -217,7 +217,7 @@ int FlipDXTCImage( // no flip to do, and we're done. break; } - else if (mip_height == 2) { + if (mip_height == 2) { // flip the first 2 lines in each block. for (unsigned int i = 0; i < blocks_per_row; i++) { half_block_function(data + i * block_bytes); diff --git a/source/blender/imbuf/intern/dds/FlipDXT.h b/source/blender/imbuf/intern/dds/FlipDXT.h index b7056742430..d35157251bd 100644 --- a/source/blender/imbuf/intern/dds/FlipDXT.h +++ b/source/blender/imbuf/intern/dds/FlipDXT.h @@ -14,13 +14,10 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -#ifndef __FLIPDXT_H__ -#define __FLIPDXT_H__ +#pragma once #include "BLI_sys_types.h" /* flip compressed DXT image vertically to fit OpenGL convention */ int FlipDXTCImage( unsigned int width, unsigned int height, unsigned int levels, int fourcc, uint8_t *data); - -#endif diff --git a/source/blender/imbuf/intern/dds/Image.h b/source/blender/imbuf/intern/dds/Image.h index 2922d5cfda3..4ccfec99445 100644 --- a/source/blender/imbuf/intern/dds/Image.h +++ b/source/blender/imbuf/intern/dds/Image.h @@ -27,8 +27,7 @@ // This code is in the public domain -- castanyo@yahoo.es -#ifndef __IMAGE_H__ -#define __IMAGE_H__ +#pragma once #include "Color.h" #include "Common.h" @@ -89,5 +88,3 @@ inline Color32 &Image::pixel(uint x, uint y) { return pixel(y * width() + x); } - -#endif /* __IMAGE_H__ */ diff --git a/source/blender/imbuf/intern/dds/PixelFormat.h b/source/blender/imbuf/intern/dds/PixelFormat.h index 47585147dfb..a9125c64121 100644 --- a/source/blender/imbuf/intern/dds/PixelFormat.h +++ b/source/blender/imbuf/intern/dds/PixelFormat.h @@ -48,8 +48,7 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR // OTHER DEALINGS IN THE SOFTWARE. -#ifndef __PIXELFORMAT_H__ -#define __PIXELFORMAT_H__ +#pragma once #include "Common.h" @@ -126,5 +125,3 @@ inline float quantizeFloor(float f, int bits) #endif } // namespace PixelFormat - -#endif /* __PIXELFORMAT_H__ */ diff --git a/source/blender/imbuf/intern/dds/Stream.cpp b/source/blender/imbuf/intern/dds/Stream.cpp index 271717f165c..e1c5eb1d505 100644 --- a/source/blender/imbuf/intern/dds/Stream.cpp +++ b/source/blender/imbuf/intern/dds/Stream.cpp @@ -42,55 +42,55 @@ unsigned int mem_read(Stream &mem, unsigned long long &i) { if (mem.pos + 8 > mem.size) { mem.set_failed(msg_error_seek); - return (0); + return 0; } memcpy(&i, mem.mem + mem.pos, 8); // @@ todo: make sure little endian mem.pos += 8; - return (8); + return 8; } unsigned int mem_read(Stream &mem, unsigned int &i) { if (mem.pos + 4 > mem.size) { mem.set_failed(msg_error_read); - return (0); + return 0; } memcpy(&i, mem.mem + mem.pos, 4); // @@ todo: make sure little endian mem.pos += 4; - return (4); + return 4; } unsigned int mem_read(Stream &mem, unsigned short &i) { if (mem.pos + 2 > mem.size) { mem.set_failed(msg_error_read); - return (0); + return 0; } memcpy(&i, mem.mem + mem.pos, 2); // @@ todo: make sure little endian mem.pos += 2; - return (2); + return 2; } unsigned int mem_read(Stream &mem, unsigned char &i) { if (mem.pos + 1 > mem.size) { mem.set_failed(msg_error_read); - return (0); + return 0; } i = (mem.mem + mem.pos)[0]; mem.pos += 1; - return (1); + return 1; } unsigned int mem_read(Stream &mem, unsigned char *i, unsigned int cnt) { if (mem.pos + cnt > mem.size) { mem.set_failed(msg_error_read); - return (0); + return 0; } memcpy(i, mem.mem + mem.pos, cnt); mem.pos += cnt; - return (cnt); + return cnt; } void Stream::set_failed(const char *msg) diff --git a/source/blender/imbuf/intern/dds/Stream.h b/source/blender/imbuf/intern/dds/Stream.h index 43cd6b56fb9..ad6b9165801 100644 --- a/source/blender/imbuf/intern/dds/Stream.h +++ b/source/blender/imbuf/intern/dds/Stream.h @@ -20,8 +20,7 @@ /* simple memory stream functions with buffer overflow check */ -#ifndef __STREAM_H__ -#define __STREAM_H__ +#pragma once struct Stream { unsigned char *mem; // location in memory @@ -40,5 +39,3 @@ unsigned int mem_read(Stream &mem, unsigned int &i); unsigned int mem_read(Stream &mem, unsigned short &i); unsigned int mem_read(Stream &mem, unsigned char &i); unsigned int mem_read(Stream &mem, unsigned char *i, unsigned int cnt); - -#endif /* __STREAM_H__ */ diff --git a/source/blender/imbuf/intern/dds/dds_api.cpp b/source/blender/imbuf/intern/dds/dds_api.cpp index 83d304203a0..309b5d6410f 100644 --- a/source/blender/imbuf/intern/dds/dds_api.cpp +++ b/source/blender/imbuf/intern/dds/dds_api.cpp @@ -44,14 +44,14 @@ extern "C" { int imb_save_dds(struct ImBuf *ibuf, const char *name, int /*flags*/) { - return (0); /* todo: finish this function */ + return 0; /* todo: finish this function */ /* check image buffer */ if (ibuf == 0) { - return (0); + return 0; } if (ibuf->rect == 0) { - return (0); + return 0; } /* 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 1; } int imb_is_a_dds(const unsigned char *mem) // note: use at most first 32 bytes @@ -77,13 +77,13 @@ int imb_is_a_dds(const unsigned char *mem) // note: use at most first 32 bytes /* heuristic check to see if mem contains a DDS file */ /* header.fourcc == FOURCC_DDS */ if ((mem[0] != 'D') || (mem[1] != 'D') || (mem[2] != 'S') || (mem[3] != ' ')) { - return (0); + return 0; } /* header.size == 124 */ if ((mem[4] != 124) || mem[5] || mem[6] || mem[7]) { - return (0); + return 0; } - return (1); + return 1; } struct ImBuf *imb_load_dds(const unsigned char *mem, @@ -109,27 +109,27 @@ struct ImBuf *imb_load_dds(const unsigned char *mem, colorspace_set_default_role(colorspace, IM_MAX_SPACE, COLOR_ROLE_DEFAULT_BYTE); if (!imb_is_a_dds(mem)) { - return (0); + return 0; } /* check if DDS is valid and supported */ if (!dds.isValid()) { /* no need to print error here, just testing if it is a DDS */ if (flags & IB_test) { - return (0); + return 0; } printf("DDS: not valid; header follows\n"); dds.printInfo(); - return (0); + return 0; } if (!dds.isSupported()) { printf("DDS: format not supported\n"); - return (0); + return 0; } if ((dds.width() > 65535) || (dds.height() > 65535)) { printf("DDS: dimensions too large\n"); - return (0); + return 0; } /* convert DDS into ImBuf */ @@ -149,7 +149,7 @@ struct ImBuf *imb_load_dds(const unsigned char *mem, } ibuf = IMB_allocImBuf(dds.width(), dds.height(), bits_per_pixel, 0); if (ibuf == 0) { - return (0); /* memory allocation failed */ + return 0; /* memory allocation failed */ } ibuf->ftype = IMB_FTYPE_DDS; @@ -158,10 +158,10 @@ struct ImBuf *imb_load_dds(const unsigned char *mem, if ((flags & IB_test) == 0) { if (!imb_addrectImBuf(ibuf)) { - return (ibuf); + return ibuf; } if (ibuf->rect == 0) { - return (ibuf); + return ibuf; } rect = ibuf->rect; @@ -196,7 +196,7 @@ struct ImBuf *imb_load_dds(const unsigned char *mem, IMB_flipy(ibuf); } - return (ibuf); + return ibuf; } } // extern "C" diff --git a/source/blender/imbuf/intern/dds/dds_api.h b/source/blender/imbuf/intern/dds/dds_api.h index e6782e217fc..930205c9efb 100644 --- a/source/blender/imbuf/intern/dds/dds_api.h +++ b/source/blender/imbuf/intern/dds/dds_api.h @@ -18,8 +18,7 @@ * \ingroup imbdds */ -#ifndef __DDS_API_H__ -#define __DDS_API_H__ +#pragma once #include "../../IMB_imbuf.h" @@ -37,5 +36,3 @@ struct ImBuf *imb_load_dds(const unsigned char *mem, #ifdef __cplusplus } #endif - -#endif /* __DDS_API_H */ diff --git a/source/blender/imbuf/intern/divers.c b/source/blender/imbuf/intern/divers.c index bcc8488089d..798849f2dd4 100644 --- a/source/blender/imbuf/intern/divers.c +++ b/source/blender/imbuf/intern/divers.c @@ -666,7 +666,7 @@ void IMB_buffer_byte_from_byte(uchar *rect_to, if (profile_to == profile_from) { /* same profile, copy */ - memcpy(to, from, sizeof(uchar) * 4 * width); + memcpy(to, from, sizeof(uchar[4]) * width); } else if (profile_to == IB_PROFILE_LINEAR_RGB) { /* convert to sRGB to linear */ @@ -785,7 +785,7 @@ void IMB_float_from_rect(ImBuf *ibuf) size_t size; size = ((size_t)ibuf->x) * ibuf->y; - size = size * 4 * sizeof(float); + size = sizeof(float[4]) * size; ibuf->channels = 4; rect_float = MEM_callocN(size, "IMB_float_from_rect"); diff --git a/source/blender/imbuf/intern/filetype.c b/source/blender/imbuf/intern/filetype.c index 29430036182..5aa588da36d 100644 --- a/source/blender/imbuf/intern/filetype.c +++ b/source/blender/imbuf/intern/filetype.c @@ -224,8 +224,7 @@ const ImFileType IMB_FILE_TYPES[] = { {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, 0}, }; -const ImFileType *IMB_FILE_TYPES_LAST = - &IMB_FILE_TYPES[sizeof(IMB_FILE_TYPES) / sizeof(ImFileType) - 1]; +const ImFileType *IMB_FILE_TYPES_LAST = &IMB_FILE_TYPES[ARRAY_SIZE(IMB_FILE_TYPES) - 1]; void imb_filetypes_init(void) { diff --git a/source/blender/imbuf/intern/filter.c b/source/blender/imbuf/intern/filter.c index d8a5096af71..12f90f27309 100644 --- a/source/blender/imbuf/intern/filter.c +++ b/source/blender/imbuf/intern/filter.c @@ -394,9 +394,8 @@ static int filter_make_index(const int x, const int y, const int w, const int h) if (x < 0 || x >= w || y < 0 || y >= h) { return -1; /* return bad index */ } - else { - return y * w + x; - } + + return y * w + x; } static int check_pixel_assigned( diff --git a/source/blender/imbuf/intern/imbuf.h b/source/blender/imbuf/intern/imbuf.h index 912c25f2616..309a911e9ca 100644 --- a/source/blender/imbuf/intern/imbuf.h +++ b/source/blender/imbuf/intern/imbuf.h @@ -21,8 +21,7 @@ * \ingroup imbuf */ -#ifndef __IMBUF_H__ -#define __IMBUF_H__ +#pragma once #include <stdio.h> #include <stdlib.h> @@ -61,5 +60,3 @@ #endif #define IMB_DPI_DEFAULT 72.0f - -#endif /* __IMBUF_H__ */ diff --git a/source/blender/imbuf/intern/indexer.c b/source/blender/imbuf/intern/indexer.c index 7cc31b99077..76717bef537 100644 --- a/source/blender/imbuf/intern/indexer.c +++ b/source/blender/imbuf/intern/indexer.c @@ -268,9 +268,8 @@ int IMB_indexer_get_frame_index(struct anim_index *idx, int frameno) if (first == idx->num_entries) { return idx->num_entries - 1; } - else { - return first; - } + + return first; } unsigned long long IMB_indexer_get_pts(struct anim_index *idx, int frame_index) @@ -473,10 +472,6 @@ static struct proxy_output_ctx *alloc_proxy_output_ffmpeg( char fname[FILE_MAX]; int ffmpeg_quality; - /* JPEG requires this */ - width = round_up(width, 8); - height = round_up(height, 8); - rv->proxy_size = proxy_size; rv->anim = anim; @@ -633,9 +628,8 @@ static int add_to_proxy_output_ffmpeg(struct proxy_output_ctx *ctx, AVFrame *fra return 1; } - else { - return 0; - } + + return 0; } static void free_proxy_output_ffmpeg(struct proxy_output_ctx *ctx, int rollback) diff --git a/source/blender/imbuf/intern/iris.c b/source/blender/imbuf/intern/iris.c index 2516df22151..2d8f1510d7b 100644 --- a/source/blender/imbuf/intern/iris.c +++ b/source/blender/imbuf/intern/iris.c @@ -281,18 +281,18 @@ struct ImBuf *imb_loadiris(const uchar *mem, size_t size, int flags, char colors readheader(inf, &image); if (image.imagic != IMAGIC) { fprintf(stderr, "longimagedata: bad magic number in image file\n"); - return (NULL); + return NULL; } rle = ISRLE(image.type); bpp = BPP(image.type); if (bpp != 1 && bpp != 2) { fprintf(stderr, "longimagedata: image must have 1 or 2 byte per pix chan\n"); - return (NULL); + return NULL; } if ((uint)image.zsize > 8) { fprintf(stderr, "longimagedata: channels over 8 not supported\n"); - return (NULL); + return NULL; } const int xsize = image.xsize; @@ -304,7 +304,7 @@ struct ImBuf *imb_loadiris(const uchar *mem, size_t size, int flags, char colors if (ibuf) { ibuf->ftype = IMB_FTYPE_IMAGIC; } - return (ibuf); + return ibuf; } if (rle) { @@ -598,7 +598,7 @@ struct ImBuf *imb_loadiris(const uchar *mem, size_t size, int flags, char colors IMB_convert_rgba_to_abgr(ibuf); } - return (ibuf); + return ibuf; } /* static utility functions for longimagedata */ @@ -892,10 +892,9 @@ static int output_iris(uint *lptr, int xsize, int ysize, int zsize, const char * if (goodwrite) { return 1; } - else { - fprintf(stderr, "output_iris: not enough space for image!!\n"); - return 0; - } + + fprintf(stderr, "output_iris: not enough space for image!!\n"); + return 0; } /* static utility functions for output_iris */ @@ -989,5 +988,5 @@ int imb_saveiris(struct ImBuf *ibuf, const char *name, int flags) IMB_convert_rgba_to_abgr(ibuf); test_endian_zbuf(ibuf); - return (ret); + return ret; } diff --git a/source/blender/imbuf/intern/jp2.c b/source/blender/imbuf/intern/jp2.c index 5154f50c7e8..2244a9c3051 100644 --- a/source/blender/imbuf/intern/jp2.c +++ b/source/blender/imbuf/intern/jp2.c @@ -73,12 +73,11 @@ static OPJ_CODEC_FORMAT format_from_header(const unsigned char mem[JP2_FILEHEADE if (check_jp2(mem)) { return OPJ_CODEC_JP2; } - else if (check_j2k(mem)) { + if (check_j2k(mem)) { return OPJ_CODEC_J2K; } - else { - return OPJ_CODEC_UNKNOWN; - } + + return OPJ_CODEC_UNKNOWN; } int imb_is_a_jp2(const unsigned char *buf) @@ -339,16 +338,14 @@ ImBuf *imb_load_jp2_filepath(const char *filepath, int flags, char colorspace[IM if (stream) { return NULL; } - else { - if (fread(mem, sizeof(mem), 1, p_file) != sizeof(mem)) { - opj_stream_destroy(stream); - return NULL; - } - else { - fseek(p_file, 0, SEEK_SET); - } + + if (fread(mem, sizeof(mem), 1, p_file) != sizeof(mem)) { + opj_stream_destroy(stream); + return NULL; } + fseek(p_file, 0, SEEK_SET); + const OPJ_CODEC_FORMAT format = format_from_header(mem); ImBuf *ibuf = imb_load_jp2_stream(stream, format, flags, colorspace); opj_stream_destroy(stream); @@ -651,7 +648,7 @@ BLI_INLINE int DOWNSAMPLE_FLOAT_TO_16BIT(const float _val) #define COMP_24_CS 1041666 /*Maximum size per color component for 2K & 4K @ 24fps*/ #define COMP_48_CS 520833 /*Maximum size per color component for 2K @ 48fps*/ -static int initialise_4K_poc(opj_poc_t *POC, int numres) +static int init_4K_poc(opj_poc_t *POC, int numres) { POC[0].tile = 1; POC[0].resno0 = 0; @@ -750,7 +747,7 @@ static void cinema_setup_encoder(opj_cparameters_t *parameters, else { parameters->cp_rsiz = DCP_CINEMA2K; } - parameters->numpocs = initialise_4K_poc(parameters->POC, parameters->numresolution); + parameters->numpocs = init_4K_poc(parameters->POC, parameters->numresolution); break; case OPJ_OFF: /* do nothing */ @@ -899,7 +896,7 @@ static opj_image_t *ibuftoimage(ImBuf *ibuf, opj_cparameters_t *parameters) h = ibuf->y; /* initialize image components */ - memset(&cmptparm, 0, 4 * sizeof(opj_image_cmptparm_t)); + memset(&cmptparm, 0, sizeof(opj_image_cmptparm_t[4])); for (i = 0; i < numcomps; i++) { cmptparm[i].prec = prec; cmptparm[i].bpp = prec; diff --git a/source/blender/imbuf/intern/jpeg.c b/source/blender/imbuf/intern/jpeg.c index fe74d9bc23f..3346f1c0964 100644 --- a/source/blender/imbuf/intern/jpeg.c +++ b/source/blender/imbuf/intern/jpeg.c @@ -417,7 +417,7 @@ static ImBuf *ibJpegImageFromCinfo(struct jpeg_decompress_struct *cinfo, int fla } } - return (ibuf); + return ibuf; } ImBuf *imb_load_jpeg(const unsigned char *buffer, @@ -452,7 +452,7 @@ ImBuf *imb_load_jpeg(const unsigned char *buffer, ibuf = ibJpegImageFromCinfo(cinfo, flags); - return (ibuf); + return ibuf; } static void write_jpeg(struct jpeg_compress_struct *cinfo, struct ImBuf *ibuf) @@ -479,7 +479,7 @@ static void write_jpeg(struct jpeg_compress_struct *cinfo, struct ImBuf *ibuf) for (prop = ibuf->metadata->data.group.first; prop; prop = prop->next) { if (prop->type == IDP_STRING) { int text_len; - if (!strcmp(prop->name, "None")) { + if (STREQ(prop->name, "None")) { jpeg_write_marker(cinfo, JPEG_COM, (JOCTET *)IDP_String(prop), prop->len + 1); } @@ -605,7 +605,7 @@ static int init_jpeg(FILE *outfile, struct jpeg_compress_struct *cinfo, struct I cinfo->dct_method = JDCT_FLOAT; jpeg_set_quality(cinfo, quality, true); - return (0); + return 0; } static int save_stdjpeg(const char *name, struct ImBuf *ibuf) diff --git a/source/blender/imbuf/intern/moviecache.c b/source/blender/imbuf/intern/moviecache.c index 96ecbdce9cc..e395222a214 100644 --- a/source/blender/imbuf/intern/moviecache.c +++ b/source/blender/imbuf/intern/moviecache.c @@ -192,9 +192,8 @@ static size_t get_size_in_memory(ImBuf *ibuf) if (ibuf->userflags & IB_PERSISTENT) { return 0; } - else { - return IMB_get_size_in_memory(ibuf); - } + + return IMB_get_size_in_memory(ibuf); } static size_t get_item_size(void *p) { @@ -537,7 +536,7 @@ void IMB_moviecache_get_cache_segments( if (totseg) { int b, *points; - points = MEM_callocN(2 * sizeof(int) * totseg, "movieclip cache segments"); + points = MEM_callocN(sizeof(int[2]) * totseg, "movieclip cache segments"); /* fill */ for (a = 0, b = 0; a < totframe; a++) { diff --git a/source/blender/imbuf/intern/oiio/openimageio_api.cpp b/source/blender/imbuf/intern/oiio/openimageio_api.cpp index df51aada5f0..86bb5934db6 100644 --- a/source/blender/imbuf/intern/oiio/openimageio_api.cpp +++ b/source/blender/imbuf/intern/oiio/openimageio_api.cpp @@ -182,10 +182,10 @@ int imb_save_photoshop(struct ImBuf *ibuf, const char * /*name*/, int flags) << " currently not supported" << std::endl; imb_addencodedbufferImBuf(ibuf); ibuf->encodedsize = 0; - return (0); + return 0; } - return (0); + return 0; } struct ImBuf *imb_load_photoshop(const char *filename, int flags, char colorspace[IM_MAX_SPACE]) @@ -199,7 +199,7 @@ struct ImBuf *imb_load_photoshop(const char *filename, int flags, char colorspac /* load image from file through OIIO */ if (imb_is_a_photoshop(filename) == 0) { - return (NULL); + return NULL; } colorspace_set_default_role(colorspace, IM_MAX_SPACE, COLOR_ROLE_DEFAULT_BYTE); diff --git a/source/blender/imbuf/intern/oiio/openimageio_api.h b/source/blender/imbuf/intern/oiio/openimageio_api.h index 3dd089d65cb..3f5f234099c 100644 --- a/source/blender/imbuf/intern/oiio/openimageio_api.h +++ b/source/blender/imbuf/intern/oiio/openimageio_api.h @@ -21,8 +21,7 @@ * \ingroup openimageio */ -#ifndef __OPENIMAGEIO_API_H__ -#define __OPENIMAGEIO_API_H__ +#pragma once #include <stdio.h> @@ -44,5 +43,3 @@ int OIIO_getVersionHex(void); } #endif - -#endif /* __OPENIMAGEIO_API_H__ */ diff --git a/source/blender/imbuf/intern/openexr/openexr_api.cpp b/source/blender/imbuf/intern/openexr/openexr_api.cpp index 9b614eab0dc..67bb3677834 100644 --- a/source/blender/imbuf/intern/openexr/openexr_api.cpp +++ b/source/blender/imbuf/intern/openexr/openexr_api.cpp @@ -131,9 +131,8 @@ class IMemStream : public Imf::IStream { _exrpos += n; return true; } - else { - return false; - } + + return false; } virtual Int64 tellg() @@ -597,15 +596,13 @@ 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); } - else { - /* when no float rect, we save as half (16 bits is sufficient) */ - if (ibuf->rect_float == NULL) { - return (int)imb_save_openexr_half(ibuf, name, flags); - } - else { - return (int)imb_save_openexr_float(ibuf, name, flags); - } + + /* when no float rect, we save as half (16 bits is sufficient) */ + if (ibuf->rect_float == NULL) { + return (int)imb_save_openexr_half(ibuf, name, flags); } + + return (int)imb_save_openexr_float(ibuf, name, flags); } /* ******* Nicer API, MultiLayer and with Tile file support ************************************ */ @@ -719,9 +716,8 @@ static int imb_exr_get_multiView_id(StringVector &views, const std::string &name if (name == *i) { return count; } - else { - count++; - } + + count++; } /* no views or wrong name */ @@ -741,7 +737,7 @@ static void imb_exr_get_views(MultiPartInputFile &file, StringVector &views) else { for (int p = 0; p < file.parts(); p++) { - std::string view = ""; + std::string view; if (file.header(p).hasView()) { view = file.header(p).view(); } @@ -1173,7 +1169,7 @@ void IMB_exrtile_write_channels( /* eventually we can make the parts' channels to include * only the current view TODO */ - if (strcmp(viewname, echan->m->view.c_str()) != 0) { + if (!STREQ(viewname, echan->m->view.c_str())) { continue; } @@ -1421,7 +1417,7 @@ static int imb_exr_split_channel_name(ExrChannel *echan, char *layname, char *pa printf("multilayer read: bad channel name: %s\n", name); return 0; } - else if (len == 1) { + if (len == 1) { echan->chan_id = token[0]; } else if (len > 1) { @@ -1904,7 +1900,7 @@ struct ImBuf *imb_load_openexr(const unsigned char *mem, MultiPartInputFile *file = NULL; if (imb_is_a_openexr(mem) == 0) { - return (NULL); + return NULL; } colorspace_set_default_role(colorspace, IM_MAX_SPACE, COLOR_ROLE_DEFAULT_FLOAT); @@ -1980,7 +1976,7 @@ struct ImBuf *imb_load_openexr(const unsigned char *mem, const bool has_luma = exr_has_luma(*file); FrameBuffer frameBuffer; float *first; - int xstride = sizeof(float) * 4; + int xstride = sizeof(float[4]); int ystride = -xstride * width; imb_addrectfloatImBuf(ibuf); @@ -2077,7 +2073,7 @@ struct ImBuf *imb_load_openexr(const unsigned char *mem, ibuf->flags |= IB_alphamode_premul; } } - return (ibuf); + return ibuf; } catch (const std::exception &exc) { std::cerr << exc.what() << std::endl; @@ -2087,7 +2083,7 @@ struct ImBuf *imb_load_openexr(const unsigned char *mem, delete file; delete membuf; - return (0); + return 0; } } diff --git a/source/blender/imbuf/intern/openexr/openexr_api.h b/source/blender/imbuf/intern/openexr/openexr_api.h index b0835e5082e..73db146849b 100644 --- a/source/blender/imbuf/intern/openexr/openexr_api.h +++ b/source/blender/imbuf/intern/openexr/openexr_api.h @@ -21,8 +21,7 @@ * \ingroup openexr */ -#ifndef __OPENEXR_API_H__ -#define __OPENEXR_API_H__ +#pragma once #include <stdio.h> @@ -42,5 +41,3 @@ struct ImBuf *imb_load_openexr(const unsigned char *mem, size_t size, int flags, #ifdef __cplusplus } #endif - -#endif /* __OPENEXR_API_H */ diff --git a/source/blender/imbuf/intern/openexr/openexr_multi.h b/source/blender/imbuf/intern/openexr/openexr_multi.h index 58f103aeba0..7008447313d 100644 --- a/source/blender/imbuf/intern/openexr/openexr_multi.h +++ b/source/blender/imbuf/intern/openexr/openexr_multi.h @@ -21,8 +21,7 @@ * \ingroup openexr */ -#ifndef __OPENEXR_MULTI_H__ -#define __OPENEXR_MULTI_H__ +#pragma once /* experiment with more advanced exr api */ @@ -99,5 +98,3 @@ bool IMB_exr_has_multilayer(void *handle); #ifdef __cplusplus } // extern "C" #endif - -#endif /* __OPENEXR_MULTI_H */ diff --git a/source/blender/imbuf/intern/png.c b/source/blender/imbuf/intern/png.c index 9e600f363c5..2eb1b216572 100644 --- a/source/blender/imbuf/intern/png.c +++ b/source/blender/imbuf/intern/png.c @@ -71,7 +71,7 @@ int imb_is_a_png(const unsigned char *mem) ret_val = !png_sig_cmp(mem, 0, 8); #endif } - return (ret_val); + return ret_val; } static void Flush(png_structp png_ptr) @@ -161,7 +161,7 @@ int imb_savepng(struct ImBuf *ibuf, const char *name, int flags) bytesperpixel = (ibuf->planes + 7) >> 3; if ((bytesperpixel > 4) || (bytesperpixel == 2)) { printf("imb_savepng: Unsupported bytes per pixel: %d for file: '%s'\n", bytesperpixel, name); - return (0); + return 0; } png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); @@ -511,7 +511,7 @@ int imb_savepng(struct ImBuf *ibuf, const char *name, int flags) fclose(fp); } - return (1); + return 1; } static void imb_png_warning(png_structp UNUSED(png_ptr), png_const_charp message) @@ -549,7 +549,7 @@ ImBuf *imb_loadpng(const unsigned char *mem, size_t size, int flags, char colors unsigned int channels; if (imb_is_a_png(mem) == 0) { - return (NULL); + return NULL; } /* both 8 and 16 bit PNGs are default to standard byte colorspace */ @@ -819,5 +819,5 @@ ImBuf *imb_loadpng(const unsigned char *mem, size_t size, int flags, char colors } png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp)NULL); - return (ibuf); + return ibuf; } diff --git a/source/blender/imbuf/intern/rectop.c b/source/blender/imbuf/intern/rectop.c index 91787d64525..8b4f33bb306 100644 --- a/source/blender/imbuf/intern/rectop.c +++ b/source/blender/imbuf/intern/rectop.c @@ -610,7 +610,7 @@ void IMB_rectblend(ImBuf *dbuf, } if (do_float) { - memcpy(drectf, srectf, width * sizeof(float) * 4); + memcpy(drectf, srectf, sizeof(float[4]) * width); drectf += destskip * 4; srectf += srcskip * 4; } diff --git a/source/blender/imbuf/intern/rotate.c b/source/blender/imbuf/intern/rotate.c index 17b485b5171..c2fc2190ce5 100644 --- a/source/blender/imbuf/intern/rotate.c +++ b/source/blender/imbuf/intern/rotate.c @@ -108,11 +108,11 @@ void IMB_flipx(struct ImBuf *ibuf) if (ibuf->rect_float) { for (yi = y - 1; yi >= 0; yi--) { for (xr = x - 1, xl = 0; xr >= xl; xr--, xl++) { - memcpy(&px_f, &ibuf->rect_float[((x * yi) + xr) * 4], 4 * sizeof(float)); + memcpy(&px_f, &ibuf->rect_float[((x * yi) + xr) * 4], sizeof(float[4])); memcpy(&ibuf->rect_float[((x * yi) + xr) * 4], &ibuf->rect_float[((x * yi) + xl) * 4], - 4 * sizeof(float)); - memcpy(&ibuf->rect_float[((x * yi) + xl) * 4], &px_f, 4 * sizeof(float)); + sizeof(float[4])); + memcpy(&ibuf->rect_float[((x * yi) + xl) * 4], &px_f, sizeof(float[4])); } } } diff --git a/source/blender/imbuf/intern/scaling.c b/source/blender/imbuf/intern/scaling.c index 95f720a9d16..1fd9bba68f3 100644 --- a/source/blender/imbuf/intern/scaling.c +++ b/source/blender/imbuf/intern/scaling.c @@ -99,10 +99,10 @@ struct ImBuf *IMB_half_x(struct ImBuf *ibuf1) struct ImBuf *ibuf2; if (ibuf1 == NULL) { - return (NULL); + return NULL; } if (ibuf1->rect == NULL && ibuf1->rect_float == NULL) { - return (NULL); + return NULL; } if (ibuf1->x <= 1) { @@ -111,12 +111,12 @@ struct ImBuf *IMB_half_x(struct ImBuf *ibuf1) ibuf2 = IMB_allocImBuf((ibuf1->x) / 2, ibuf1->y, ibuf1->planes, ibuf1->flags); if (ibuf2 == NULL) { - return (NULL); + return NULL; } imb_half_x_no_alloc(ibuf2, ibuf1); - return (ibuf2); + return ibuf2; } struct ImBuf *IMB_double_fast_x(struct ImBuf *ibuf1) @@ -126,10 +126,10 @@ struct ImBuf *IMB_double_fast_x(struct ImBuf *ibuf1) float *p1f, *destf; if (ibuf1 == NULL) { - return (NULL); + return NULL; } if (ibuf1->rect == NULL && ibuf1->rect_float == NULL) { - return (NULL); + return NULL; } do_rect = (ibuf1->rect != NULL); @@ -137,7 +137,7 @@ struct ImBuf *IMB_double_fast_x(struct ImBuf *ibuf1) ibuf2 = IMB_allocImBuf(2 * ibuf1->x, ibuf1->y, ibuf1->planes, ibuf1->flags); if (ibuf2 == NULL) { - return (NULL); + return NULL; } p1 = (int *)ibuf1->rect; @@ -161,7 +161,7 @@ struct ImBuf *IMB_double_fast_x(struct ImBuf *ibuf1) } } - return (ibuf2); + return ibuf2; } struct ImBuf *IMB_double_x(struct ImBuf *ibuf1) @@ -169,16 +169,16 @@ struct ImBuf *IMB_double_x(struct ImBuf *ibuf1) struct ImBuf *ibuf2; if (ibuf1 == NULL) { - return (NULL); + return NULL; } if (ibuf1->rect == NULL && ibuf1->rect_float == NULL) { - return (NULL); + return NULL; } ibuf2 = IMB_double_fast_x(ibuf1); imb_filterx(ibuf2); - return (ibuf2); + return ibuf2; } static void imb_half_y_no_alloc(struct ImBuf *ibuf2, struct ImBuf *ibuf1) @@ -253,10 +253,10 @@ struct ImBuf *IMB_half_y(struct ImBuf *ibuf1) struct ImBuf *ibuf2; if (ibuf1 == NULL) { - return (NULL); + return NULL; } if (ibuf1->rect == NULL && ibuf1->rect_float == NULL) { - return (NULL); + return NULL; } if (ibuf1->y <= 1) { @@ -265,12 +265,12 @@ struct ImBuf *IMB_half_y(struct ImBuf *ibuf1) ibuf2 = IMB_allocImBuf(ibuf1->x, (ibuf1->y) / 2, ibuf1->planes, ibuf1->flags); if (ibuf2 == NULL) { - return (NULL); + return NULL; } imb_half_y_no_alloc(ibuf2, ibuf1); - return (ibuf2); + return ibuf2; } struct ImBuf *IMB_double_fast_y(struct ImBuf *ibuf1) @@ -282,10 +282,10 @@ struct ImBuf *IMB_double_fast_y(struct ImBuf *ibuf1) int do_rect, do_float; if (ibuf1 == NULL) { - return (NULL); + return NULL; } if (ibuf1->rect == NULL && ibuf1->rect_float == NULL) { - return (NULL); + return NULL; } do_rect = (ibuf1->rect != NULL); @@ -293,7 +293,7 @@ struct ImBuf *IMB_double_fast_y(struct ImBuf *ibuf1) ibuf2 = IMB_allocImBuf(ibuf1->x, 2 * ibuf1->y, ibuf1->planes, ibuf1->flags); if (ibuf2 == NULL) { - return (NULL); + return NULL; } p1 = (int *)ibuf1->rect; @@ -318,7 +318,7 @@ struct ImBuf *IMB_double_fast_y(struct ImBuf *ibuf1) } } - return (ibuf2); + return ibuf2; } struct ImBuf *IMB_double_y(struct ImBuf *ibuf1) @@ -326,16 +326,16 @@ struct ImBuf *IMB_double_y(struct ImBuf *ibuf1) struct ImBuf *ibuf2; if (ibuf1 == NULL) { - return (NULL); + return NULL; } if (ibuf1->rect == NULL) { - return (NULL); + return NULL; } ibuf2 = IMB_double_fast_y(ibuf1); IMB_filtery(ibuf2); - return (ibuf2); + return ibuf2; } /* pretty much specific functions which converts uchar <-> ushort but assumes @@ -453,10 +453,10 @@ ImBuf *IMB_onehalf(struct ImBuf *ibuf1) struct ImBuf *ibuf2; if (ibuf1 == NULL) { - return (NULL); + return NULL; } if (ibuf1->rect == NULL && ibuf1->rect_float == NULL) { - return (NULL); + return NULL; } if (ibuf1->x <= 1) { @@ -468,12 +468,12 @@ ImBuf *IMB_onehalf(struct ImBuf *ibuf1) ibuf2 = IMB_allocImBuf((ibuf1->x) / 2, (ibuf1->y) / 2, ibuf1->planes, ibuf1->flags); if (ibuf2 == NULL) { - return (NULL); + return NULL; } imb_onehalf_no_alloc(ibuf2, ibuf1); - return (ibuf2); + return ibuf2; } /* q_scale_linear_interpolation helper functions */ @@ -886,7 +886,7 @@ static bool q_scale_linear_interpolation(struct ImBuf *ibuf, int newx, int newy) } if (ibuf->rect) { - unsigned char *newrect = MEM_mallocN(newx * newy * sizeof(int), "q_scale rect"); + unsigned char *newrect = MEM_mallocN(sizeof(int) * newx * newy, "q_scale rect"); q_scale_byte((unsigned char *)ibuf->rect, newrect, ibuf->x, ibuf->y, newx, newy); imb_freerectImBuf(ibuf); @@ -894,7 +894,7 @@ static bool q_scale_linear_interpolation(struct ImBuf *ibuf, int newx, int newy) ibuf->rect = (unsigned int *)newrect; } if (ibuf->rect_float) { - float *newrect = MEM_mallocN(newx * newy * 4 * sizeof(float), "q_scale rectfloat"); + float *newrect = MEM_mallocN(sizeof(float[4]) * newx * newy, "q_scale rectfloat"); q_scale_float(ibuf->rect_float, newrect, ibuf->x, ibuf->y, newx, newy); imb_freerectfloatImBuf(ibuf); ibuf->mall |= IB_rectfloat; @@ -923,22 +923,22 @@ static ImBuf *scaledownx(struct ImBuf *ibuf, int newx) nvalf[0] = nvalf[1] = nvalf[2] = nvalf[3] = 0.0f; if (!do_rect && !do_float) { - return (ibuf); + return ibuf; } if (do_rect) { - _newrect = MEM_mallocN(newx * ibuf->y * sizeof(uchar) * 4, "scaledownx"); + _newrect = MEM_mallocN(sizeof(uchar[4]) * newx * ibuf->y, "scaledownx"); if (_newrect == NULL) { - return (ibuf); + return ibuf; } } if (do_float) { - _newrectf = MEM_mallocN(newx * ibuf->y * sizeof(float) * 4, "scaledownxf"); + _newrectf = MEM_mallocN(sizeof(float[4]) * newx * ibuf->y, "scaledownxf"); if (_newrectf == NULL) { if (_newrect) { MEM_freeN(_newrect); } - return (ibuf); + return ibuf; } } @@ -1044,7 +1044,7 @@ static ImBuf *scaledownx(struct ImBuf *ibuf, int newx) (void)rect_size; /* UNUSED in release builds */ ibuf->x = newx; - return (ibuf); + return ibuf; } static ImBuf *scaledowny(struct ImBuf *ibuf, int newy) @@ -1064,22 +1064,22 @@ static ImBuf *scaledowny(struct ImBuf *ibuf, int newy) nvalf[0] = nvalf[1] = nvalf[2] = nvalf[3] = 0.0f; if (!do_rect && !do_float) { - return (ibuf); + return ibuf; } if (do_rect) { - _newrect = MEM_mallocN(newy * ibuf->x * sizeof(uchar) * 4, "scaledowny"); + _newrect = MEM_mallocN(sizeof(uchar[4]) * newy * ibuf->x, "scaledowny"); if (_newrect == NULL) { - return (ibuf); + return ibuf; } } if (do_float) { - _newrectf = MEM_mallocN(newy * ibuf->x * sizeof(float) * 4, "scaledownyf"); + _newrectf = MEM_mallocN(sizeof(float[4]) * newy * ibuf->x, "scaledownyf"); if (_newrectf == NULL) { if (_newrect) { MEM_freeN(_newrect); } - return (ibuf); + return ibuf; } } @@ -1186,7 +1186,7 @@ static ImBuf *scaledowny(struct ImBuf *ibuf, int newy) (void)rect_size; /* UNUSED in release builds */ ibuf->y = newy; - return (ibuf); + return ibuf; } static ImBuf *scaleupx(struct ImBuf *ibuf, int newx) @@ -1210,27 +1210,27 @@ static ImBuf *scaleupx(struct ImBuf *ibuf, int newx) val_af = nval_af = diff_af = val_bf = nval_bf = diff_bf = 0; val_gf = nval_gf = diff_gf = val_rf = nval_rf = diff_rf = 0; if (ibuf == NULL) { - return (NULL); + return NULL; } if (ibuf->rect == NULL && ibuf->rect_float == NULL) { - return (ibuf); + return ibuf; } if (ibuf->rect) { do_rect = true; _newrect = MEM_mallocN(newx * ibuf->y * sizeof(int), "scaleupx"); if (_newrect == NULL) { - return (ibuf); + return ibuf; } } if (ibuf->rect_float) { do_float = true; - _newrectf = MEM_mallocN(newx * ibuf->y * sizeof(float) * 4, "scaleupxf"); + _newrectf = MEM_mallocN(sizeof(float[4]) * newx * ibuf->y, "scaleupxf"); if (_newrectf == NULL) { if (_newrect) { MEM_freeN(_newrect); } - return (ibuf); + return ibuf; } } @@ -1362,7 +1362,7 @@ static ImBuf *scaleupx(struct ImBuf *ibuf, int newx) } ibuf->x = newx; - return (ibuf); + return ibuf; } static ImBuf *scaleupy(struct ImBuf *ibuf, int newy) @@ -1386,27 +1386,27 @@ static ImBuf *scaleupy(struct ImBuf *ibuf, int newy) val_af = nval_af = diff_af = val_bf = nval_bf = diff_bf = 0; val_gf = nval_gf = diff_gf = val_rf = nval_rf = diff_rf = 0; if (ibuf == NULL) { - return (NULL); + return NULL; } if (ibuf->rect == NULL && ibuf->rect_float == NULL) { - return (ibuf); + return ibuf; } if (ibuf->rect) { do_rect = true; _newrect = MEM_mallocN(ibuf->x * newy * sizeof(int), "scaleupy"); if (_newrect == NULL) { - return (ibuf); + return ibuf; } } if (ibuf->rect_float) { do_float = true; - _newrectf = MEM_mallocN(ibuf->x * newy * sizeof(float) * 4, "scaleupyf"); + _newrectf = MEM_mallocN(sizeof(float[4]) * ibuf->x * newy, "scaleupyf"); if (_newrectf == NULL) { if (_newrect) { MEM_freeN(_newrect); } - return (ibuf); + return ibuf; } } @@ -1545,7 +1545,7 @@ static ImBuf *scaleupy(struct ImBuf *ibuf, int newy) } ibuf->y = newy; - return (ibuf); + return ibuf; } static void scalefast_Z_ImBuf(ImBuf *ibuf, int newx, int newy) @@ -1703,7 +1703,7 @@ bool IMB_scalefastImBuf(struct ImBuf *ibuf, unsigned int newx, unsigned int newy } if (do_float) { - _newrectf = MEM_mallocN(newx * newy * sizeof(float) * 4, "scalefastimbuf f"); + _newrectf = MEM_mallocN(sizeof(float[4]) * newx * newy, "scalefastimbuf f"); if (_newrectf == NULL) { if (_newrect) { MEM_freeN(_newrect); diff --git a/source/blender/imbuf/intern/stereoimbuf.c b/source/blender/imbuf/intern/stereoimbuf.c index 5569e119b95..247122065de 100644 --- a/source/blender/imbuf/intern/stereoimbuf.c +++ b/source/blender/imbuf/intern/stereoimbuf.c @@ -669,17 +669,17 @@ static void imb_stereo3d_squeeze_rect( /*************************** preparing to call the write functions **************************/ -static void imb_stereo3d_data_initialize(Stereo3DData *s3d_data, - const bool is_float, - const size_t x, - const size_t y, - const size_t channels, - int *rect_left, - int *rect_right, - int *rect_stereo, - float *rectf_left, - float *rectf_right, - float *rectf_stereo) +static void imb_stereo3d_data_init(Stereo3DData *s3d_data, + const bool is_float, + const size_t x, + const size_t y, + const size_t channels, + int *rect_left, + int *rect_right, + int *rect_stereo, + float *rectf_left, + float *rectf_right, + float *rectf_stereo) { s3d_data->is_float = is_float; s3d_data->x = x; @@ -709,7 +709,7 @@ int *IMB_stereo3d_from_rect(ImageFormatData *im_format, im_format->stereo3d_format.display_mode, false, x, y, &width, &height); r_rect = MEM_mallocN(channels * sizeof(int) * width * height, __func__); - imb_stereo3d_data_initialize( + imb_stereo3d_data_init( &s3d_data, is_float, x, y, channels, rect_left, rect_right, r_rect, NULL, NULL, NULL); imb_stereo3d_write_doit(&s3d_data, &im_format->stereo3d_format); imb_stereo3d_squeeze_rect(r_rect, &im_format->stereo3d_format, x, y, channels); @@ -733,7 +733,7 @@ float *IMB_stereo3d_from_rectf(ImageFormatData *im_format, im_format->stereo3d_format.display_mode, false, x, y, &width, &height); r_rectf = MEM_mallocN(channels * sizeof(float) * width * height, __func__); - imb_stereo3d_data_initialize( + imb_stereo3d_data_init( &s3d_data, is_float, x, y, channels, NULL, NULL, NULL, rectf_left, rectf_right, r_rectf); imb_stereo3d_write_doit(&s3d_data, &im_format->stereo3d_format); imb_stereo3d_squeeze_rectf(r_rectf, &im_format->stereo3d_format, x, y, channels); @@ -759,17 +759,17 @@ ImBuf *IMB_stereo3d_ImBuf(ImageFormatData *im_format, ImBuf *ibuf_left, ImBuf *i ibuf_stereo->flags = ibuf_left->flags; - imb_stereo3d_data_initialize(&s3d_data, - is_float, - ibuf_left->x, - ibuf_left->y, - 4, - (int *)ibuf_left->rect, - (int *)ibuf_right->rect, - (int *)ibuf_stereo->rect, - ibuf_left->rect_float, - ibuf_right->rect_float, - ibuf_stereo->rect_float); + imb_stereo3d_data_init(&s3d_data, + is_float, + ibuf_left->x, + ibuf_left->y, + 4, + (int *)ibuf_left->rect, + (int *)ibuf_right->rect, + (int *)ibuf_stereo->rect, + ibuf_left->rect_float, + ibuf_right->rect_float, + ibuf_stereo->rect_float); imb_stereo3d_write_doit(&s3d_data, &im_format->stereo3d_format); imb_stereo3d_squeeze_ImBuf(ibuf_stereo, &im_format->stereo3d_format, ibuf_left->x, ibuf_left->y); @@ -1286,17 +1286,17 @@ void IMB_ImBufFromStereo3d(Stereo3dFormat *s3d, &height); imb_stereo3d_unsqueeze_ImBuf(ibuf_stereo3d, s3d, width, height); - imb_stereo3d_data_initialize(&s3d_data, - is_float, - ibuf_left->x, - ibuf_left->y, - 4, - (int *)ibuf_left->rect, - (int *)ibuf_right->rect, - (int *)ibuf_stereo3d->rect, - ibuf_left->rect_float, - ibuf_right->rect_float, - ibuf_stereo3d->rect_float); + imb_stereo3d_data_init(&s3d_data, + is_float, + ibuf_left->x, + ibuf_left->y, + 4, + (int *)ibuf_left->rect, + (int *)ibuf_right->rect, + (int *)ibuf_stereo3d->rect, + ibuf_left->rect_float, + ibuf_right->rect_float, + ibuf_stereo3d->rect_float); imb_stereo3d_read_doit(&s3d_data, s3d); @@ -1310,17 +1310,17 @@ void IMB_ImBufFromStereo3d(Stereo3dFormat *s3d, addzbufImBuf(ibuf_right); } - imb_stereo3d_data_initialize(&s3d_data, - is_float, - ibuf_left->x, - ibuf_left->y, - 1, - (int *)ibuf_left->zbuf, - (int *)ibuf_right->zbuf, - (int *)ibuf_stereo3d->zbuf, - ibuf_left->zbuf_float, - ibuf_right->zbuf_float, - ibuf_stereo3d->zbuf_float); + imb_stereo3d_data_init(&s3d_data, + is_float, + ibuf_left->x, + ibuf_left->y, + 1, + (int *)ibuf_left->zbuf, + (int *)ibuf_right->zbuf, + (int *)ibuf_stereo3d->zbuf, + ibuf_left->zbuf_float, + ibuf_right->zbuf_float, + ibuf_stereo3d->zbuf_float); imb_stereo3d_read_doit(&s3d_data, s3d); } diff --git a/source/blender/imbuf/intern/tiff.c b/source/blender/imbuf/intern/tiff.c index 715f2aaf621..c95476fa628 100644 --- a/source/blender/imbuf/intern/tiff.c +++ b/source/blender/imbuf/intern/tiff.c @@ -104,7 +104,7 @@ static int imb_tiff_DummyMapProc( (void)pbase; (void)psize; - return (0); + return 0; } /** @@ -145,7 +145,7 @@ static tsize_t imb_tiff_ReadProc(thandle_t handle, tdata_t data, tsize_t n) /* on EOF, return immediately and read (copy) nothing */ if (nCopy <= 0) { - return (0); + return 0; } /* all set -> do the read (copy) */ @@ -238,7 +238,7 @@ static int imb_tiff_CloseProc(thandle_t handle) mfile = IMB_TIFF_GET_MEMFILE(handle); if (!mfile || !mfile->mem) { fprintf(stderr, "imb_tiff_CloseProc: !mfile || !mfile->mem!\n"); - return (0); + return 0; } /* virtually close the file */ @@ -246,7 +246,7 @@ static int imb_tiff_CloseProc(thandle_t handle) mfile->offset = 0; mfile->size = 0; - return (0); + return 0; } /** @@ -262,7 +262,7 @@ static toff_t imb_tiff_SizeProc(thandle_t handle) mfile = IMB_TIFF_GET_MEMFILE(handle); if (!mfile || !mfile->mem) { fprintf(stderr, "imb_tiff_SizeProc: !mfile || !mfile->mem!\n"); - return (0); + return 0; } /* return the size */ @@ -306,8 +306,8 @@ static TIFF *imb_tiff_client_open(ImbTIFFMemFile *memFile, const unsigned char * #define IMB_TIFF_NCB 4 /* number of comparison bytes used */ int imb_is_a_tiff(const unsigned char *mem) { - char big_endian[IMB_TIFF_NCB] = {0x4d, 0x4d, 0x00, 0x2a}; - char lil_endian[IMB_TIFF_NCB] = {0x49, 0x49, 0x2a, 0x00}; + const char big_endian[IMB_TIFF_NCB] = {0x4d, 0x4d, 0x00, 0x2a}; + const char lil_endian[IMB_TIFF_NCB] = {0x49, 0x49, 0x2a, 0x00}; return ((memcmp(big_endian, mem, IMB_TIFF_NCB) == 0) || (memcmp(lil_endian, mem, IMB_TIFF_NCB) == 0)); @@ -764,7 +764,7 @@ int imb_savetiff(ImBuf *ibuf, const char *name, int flags) "imb_savetiff: unsupported number of bytes per " "pixel: %d\n", samplesperpixel); - return (0); + return 0; } if ((ibuf->foptions.flag & TIF_16BIT) && ibuf->rect_float) { @@ -790,21 +790,21 @@ int imb_savetiff(ImBuf *ibuf, const char *name, int flags) fprintf(stderr, "imb_savetiff: creation of in-memory TIFF files is " "not yet supported.\n"); - return (0); + return 0; } - else { - /* create image as a file */ + + /* create image as a file */ #ifdef WIN32 - wchar_t *wname = alloc_utf16_from_8(name, 0); - image = TIFFOpenW(wname, "w"); - free(wname); + wchar_t *wname = alloc_utf16_from_8(name, 0); + image = TIFFOpenW(wname, "w"); + free(wname); #else - image = TIFFOpen(name, "w"); + image = TIFFOpen(name, "w"); #endif - } + if (image == NULL) { fprintf(stderr, "imb_savetiff: could not open TIFF for writing.\n"); - return (0); + return 0; } /* allocate array for pixel data */ @@ -819,7 +819,7 @@ int imb_savetiff(ImBuf *ibuf, const char *name, int flags) if (pixels == NULL && pixels16 == NULL) { fprintf(stderr, "imb_savetiff: could not allocate pixels array.\n"); TIFFClose(image); - return (0); + return 0; } /* setup pointers */ @@ -945,7 +945,7 @@ int imb_savetiff(ImBuf *ibuf, const char *name, int flags) if (pixels16) { _TIFFfree(pixels16); } - return (1); + return 1; } /* close the TIFF file */ @@ -956,5 +956,5 @@ int imb_savetiff(ImBuf *ibuf, const char *name, int flags) if (pixels16) { _TIFFfree(pixels16); } - return (1); + return 1; } diff --git a/source/blender/imbuf/intern/util.c b/source/blender/imbuf/intern/util.c index 3c420f3f297..64b03f332a8 100644 --- a/source/blender/imbuf/intern/util.c +++ b/source/blender/imbuf/intern/util.c @@ -339,42 +339,42 @@ int imb_get_anim_type(const char *name) # ifdef WITH_FFMPEG /* stat test below fails on large files > 4GB */ if (isffmpeg(name)) { - return (ANIM_FFMPEG); + return ANIM_FFMPEG; } # endif if (BLI_stat(name, &st) == -1) { - return (0); + return 0; } if (((st.st_mode) & S_IFMT) != S_IFREG) { - return (0); + return 0; } if (isavi(name)) { - return (ANIM_AVI); + return ANIM_AVI; } if (ismovie(name)) { - return (ANIM_MOVIE); + return ANIM_MOVIE; } #else if (BLI_stat(name, &st) == -1) { - return (0); + return 0; } if (((st.st_mode) & S_IFMT) != S_IFREG) { - return (0); + return 0; } if (ismovie(name)) { - return (ANIM_MOVIE); + return ANIM_MOVIE; } # ifdef WITH_FFMPEG if (isffmpeg(name)) { - return (ANIM_FFMPEG); + return ANIM_FFMPEG; } # endif if (isavi(name)) { - return (ANIM_AVI); + return ANIM_AVI; } #endif type = IMB_ispic(name); diff --git a/source/blender/imbuf/intern/util_gpu.c b/source/blender/imbuf/intern/util_gpu.c new file mode 100644 index 00000000000..58ff8473a85 --- /dev/null +++ b/source/blender/imbuf/intern/util_gpu.c @@ -0,0 +1,260 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. + * All rights reserved. + * util.c + */ + +/** \file + * \ingroup imbuf + */ + +#include "imbuf.h" + +#include "BLI_math.h" +#include "BLI_utildefines.h" +#include "MEM_guardedalloc.h" + +#include "BKE_global.h" + +#include "GPU_extensions.h" +#include "GPU_texture.h" + +#include "IMB_colormanagement.h" +#include "IMB_imbuf.h" +#include "IMB_imbuf_types.h" + +/* gpu ibuf utils */ + +static void imb_gpu_get_format(const ImBuf *ibuf, + bool high_bitdepth, + eGPUDataFormat *r_data_format, + eGPUTextureFormat *r_texture_format) +{ + const bool float_rect = (ibuf->rect_float != NULL); + const bool use_srgb = (!IMB_colormanagement_space_is_data(ibuf->rect_colorspace) && + !IMB_colormanagement_space_is_scene_linear(ibuf->rect_colorspace)); + high_bitdepth = (!(ibuf->flags & IB_halffloat) && high_bitdepth); + + *r_data_format = (float_rect) ? GPU_DATA_FLOAT : GPU_DATA_UNSIGNED_BYTE; + + if (float_rect) { + *r_texture_format = high_bitdepth ? GPU_RGBA32F : GPU_RGBA16F; + } + else { + *r_texture_format = use_srgb ? GPU_SRGB8_A8 : GPU_RGBA8; + } +} + +/* Return false if no suitable format was found. */ +#ifdef WITH_DDS +static bool IMB_gpu_get_compressed_format(const ImBuf *ibuf, eGPUTextureFormat *r_texture_format) +{ + /* For DDS we only support data, scene linear and sRGB. Converting to + * different colorspace would break the compression. */ + const bool use_srgb = (!IMB_colormanagement_space_is_data(ibuf->rect_colorspace) && + !IMB_colormanagement_space_is_scene_linear(ibuf->rect_colorspace)); + + if (ibuf->dds_data.fourcc == FOURCC_DXT1) { + *r_texture_format = (use_srgb) ? GPU_SRGB8_A8_DXT1 : GPU_RGBA8_DXT1; + } + else if (ibuf->dds_data.fourcc == FOURCC_DXT3) { + *r_texture_format = (use_srgb) ? GPU_SRGB8_A8_DXT3 : GPU_RGBA8_DXT3; + } + else if (ibuf->dds_data.fourcc == FOURCC_DXT5) { + *r_texture_format = (use_srgb) ? GPU_SRGB8_A8_DXT5 : GPU_RGBA8_DXT5; + } + else { + return false; + } + return true; +} +#endif + +/** + * Apply colormanagement and scale buffer if needed. + * *r_freedata is set to true if the returned buffer need to be manually freed. + **/ +static void *imb_gpu_get_data(const ImBuf *ibuf, + const bool do_rescale, + const int rescale_size[2], + const bool compress_as_srgb, + const bool store_premultiplied, + bool *r_freedata) +{ + const bool is_float_rect = (ibuf->rect_float != NULL); + void *data_rect = (is_float_rect) ? (void *)ibuf->rect_float : (void *)ibuf->rect; + + if (is_float_rect) { + /* Float image is already in scene linear colorspace or non-color data by + * convention, no colorspace conversion needed. But we do require 4 channels + * currently. */ + if (ibuf->channels != 4 || !store_premultiplied) { + data_rect = MEM_mallocN(sizeof(float[4]) * ibuf->x * ibuf->y, __func__); + *r_freedata = true; + + if (data_rect == NULL) { + return NULL; + } + + IMB_colormanagement_imbuf_to_float_texture( + (float *)data_rect, 0, 0, ibuf->x, ibuf->y, ibuf, store_premultiplied); + } + } + else { + /* Byte image is in original colorspace from the file. If the file is sRGB + * scene linear, or non-color data no conversion is needed. Otherwise we + * compress as scene linear + sRGB transfer function to avoid precision loss + * in common cases. + * + * We must also convert to premultiplied for correct texture interpolation + * and consistency with float images. */ + if (!IMB_colormanagement_space_is_data(ibuf->rect_colorspace)) { + data_rect = MEM_mallocN(sizeof(uchar[4]) * ibuf->x * ibuf->y, __func__); + *r_freedata = true; + + if (data_rect == NULL) { + return NULL; + } + + /* Texture storage of images is defined by the alpha mode of the image. The + * downside of this is that there can be artifacts near alpha edges. However, + * this allows us to use sRGB texture formats and preserves color values in + * zero alpha areas, and appears generally closer to what game engines that we + * want to be compatible with do. */ + IMB_colormanagement_imbuf_to_byte_texture( + (uchar *)data_rect, 0, 0, ibuf->x, ibuf->y, ibuf, compress_as_srgb, store_premultiplied); + } + } + + if (do_rescale) { + uint *rect = (is_float_rect) ? NULL : (uint *)data_rect; + float *rect_float = (is_float_rect) ? (float *)data_rect : NULL; + + ImBuf *scale_ibuf = IMB_allocFromBuffer(rect, rect_float, ibuf->x, ibuf->y, 4); + IMB_scaleImBuf(scale_ibuf, UNPACK2(rescale_size)); + + data_rect = (is_float_rect) ? (void *)scale_ibuf->rect_float : (void *)scale_ibuf->rect; + *r_freedata = true; + /* Steal the rescaled buffer to avoid double free. */ + scale_ibuf->rect_float = NULL; + scale_ibuf->rect = NULL; + IMB_freeImBuf(scale_ibuf); + } + return data_rect; +} + +/* The ibuf is only here to detect the storage type. The produced texture will have undefined + * content. It will need to be populated by using IMB_update_gpu_texture_sub(). */ +GPUTexture *IMB_touch_gpu_texture(ImBuf *ibuf, int w, int h, int layers, bool use_high_bitdepth) +{ + eGPUDataFormat data_format; + eGPUTextureFormat tex_format; + imb_gpu_get_format(ibuf, use_high_bitdepth, &data_format, &tex_format); + + GPUTexture *tex = GPU_texture_create_nD( + w, h, layers, 2, NULL, tex_format, data_format, 0, false, NULL); + + GPU_texture_anisotropic_filter(tex, true); + return tex; +} + +/* Will update a GPUTexture using the content of the ImBuf. Only one layer will be updated. + * Will resize the ibuf if needed. + * z is the layer to update. Unused if the texture is 2D. */ +void IMB_update_gpu_texture_sub(GPUTexture *tex, + ImBuf *ibuf, + int x, + int y, + int z, + int w, + int h, + bool use_high_bitdepth, + bool use_premult) +{ + const bool do_rescale = (ibuf->x != w || ibuf->y != h); + const int size[2] = {w, h}; + + eGPUDataFormat data_format; + eGPUTextureFormat tex_format; + imb_gpu_get_format(ibuf, use_high_bitdepth, &data_format, &tex_format); + + const bool compress_as_srgb = (tex_format == GPU_SRGB8_A8); + bool freebuf = false; + + void *data = imb_gpu_get_data(ibuf, do_rescale, size, compress_as_srgb, use_premult, &freebuf); + + /* Update Texture. */ + GPU_texture_update_sub(tex, data_format, data, x, y, z, w, h, 1); + + if (freebuf) { + MEM_freeN(data); + } +} + +GPUTexture *IMB_create_gpu_texture(ImBuf *ibuf, bool use_high_bitdepth, bool use_premult) +{ + GPUTexture *tex = NULL; + const int size[2] = {GPU_texture_size_with_limit(ibuf->x), GPU_texture_size_with_limit(ibuf->y)}; + bool do_rescale = (ibuf->x != size[0]) || (ibuf->y != size[1]); + +#ifdef WITH_DDS + if (ibuf->ftype == IMB_FTYPE_DDS) { + eGPUTextureFormat compressed_format; + if (!IMB_gpu_get_compressed_format(ibuf, &compressed_format)) { + fprintf(stderr, "Unable to find a suitable DXT compression,"); + } + else if (do_rescale) { + fprintf(stderr, "Unable to load DXT image resolution,"); + } + else if (!is_power_of_2_i(ibuf->x) || !is_power_of_2_i(ibuf->y)) { + fprintf(stderr, "Unable to load non-power-of-two DXT image resolution,"); + } + else { + tex = GPU_texture_create_compressed( + ibuf->x, ibuf->y, ibuf->dds_data.nummipmaps, compressed_format, ibuf->dds_data.data); + + if (tex != NULL) { + return tex; + } + + fprintf(stderr, "ST3C support not found,"); + } + /* Fallback to uncompressed texture. */ + fprintf(stderr, " falling back to uncompressed.\n"); + } +#endif + + eGPUDataFormat data_format; + eGPUTextureFormat tex_format; + imb_gpu_get_format(ibuf, use_high_bitdepth, &data_format, &tex_format); + + const bool compress_as_srgb = (tex_format == GPU_SRGB8_A8); + bool freebuf = false; + + void *data = imb_gpu_get_data(ibuf, do_rescale, size, compress_as_srgb, use_premult, &freebuf); + + /* Create Texture. */ + tex = GPU_texture_create_nD(UNPACK2(size), 0, 2, data, tex_format, data_format, 0, false, NULL); + + GPU_texture_anisotropic_filter(tex, true); + + if (freebuf) { + MEM_freeN(data); + } + + return tex; +} diff --git a/source/blender/imbuf/intern/writeimage.c b/source/blender/imbuf/intern/writeimage.c index 9cb0436cb98..1d77233a7e2 100644 --- a/source/blender/imbuf/intern/writeimage.c +++ b/source/blender/imbuf/intern/writeimage.c @@ -50,7 +50,7 @@ short IMB_saveiff(struct ImBuf *ibuf, const char *name, int flags) BLI_assert(!BLI_path_is_rel(name)); if (ibuf == NULL) { - return (false); + return false; } ibuf->flags = flags; |