Cleanup: imbuf: Replace 'void' MEM_[cm]allocN with templated, type-safe MEM_[cm]allocN<T>.
The main issue of 'type-less' standard C allocations is that there is no check on allocated type possible. This is a serious source of annoyance (and crashes) when making some low-level structs non-trivial, as tracking down all usages of these structs in higher-level other structs and their allocation is... really painful. MEM_[cm]allocN<T> templates on the other hand do check that the given type is trivial, at build time (static assert), which makes such issue... trivial to catch. NOTE: New code should strive to use MEM_new (i.e. allocation and construction) as much as possible, even for trivial PoD types. Pull Request: https://projects.blender.org/blender/blender/pulls/135994
This commit is contained in:
committed by
Bastien Montagne
parent
d79274ae53
commit
e85ebb24fe
@@ -119,8 +119,8 @@ static int imb_save_dpx_cineon(ImBuf *ibuf, const char *filepath, 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(sizeof(float[4]) * ibuf->x * ibuf->y,
|
||||
"fbuf in imb_save_dpx_cineon");
|
||||
fbuf = MEM_malloc_arrayN<float>(4 * size_t(ibuf->x) * size_t(ibuf->y),
|
||||
"fbuf in imb_save_dpx_cineon");
|
||||
|
||||
for (y = 0; y < ibuf->y; y++) {
|
||||
float *dst_ptr = fbuf + 4 * ((ibuf->y - y - 1) * ibuf->x);
|
||||
@@ -138,8 +138,8 @@ static int imb_save_dpx_cineon(ImBuf *ibuf, const char *filepath, int use_cineon
|
||||
IMB_byte_from_float(ibuf);
|
||||
}
|
||||
|
||||
fbuf = (float *)MEM_mallocN(sizeof(float[4]) * ibuf->x * ibuf->y,
|
||||
"fbuf in imb_save_dpx_cineon");
|
||||
fbuf = MEM_malloc_arrayN<float>(4 * size_t(ibuf->x) * size_t(ibuf->y),
|
||||
"fbuf in imb_save_dpx_cineon");
|
||||
if (fbuf == nullptr) {
|
||||
printf("DPX/Cineon: error allocating memory.\n");
|
||||
logImageClose(logImage);
|
||||
|
||||
@@ -124,7 +124,7 @@ static void fillCineonMainHeader(LogImageFile *cineon,
|
||||
LogImageFile *cineonOpen(const uchar *byteStuff, int fromMemory, size_t bufferSize)
|
||||
{
|
||||
CineonMainHeader header;
|
||||
LogImageFile *cineon = (LogImageFile *)MEM_mallocN(sizeof(LogImageFile), __func__);
|
||||
LogImageFile *cineon = MEM_mallocN<LogImageFile>(__func__);
|
||||
const char *filepath = (const char *)byteStuff;
|
||||
int i;
|
||||
uint dataOffset;
|
||||
@@ -357,7 +357,7 @@ LogImageFile *cineonCreate(
|
||||
const char *shortFilename = nullptr;
|
||||
// uchar pad[6044];
|
||||
|
||||
LogImageFile *cineon = (LogImageFile *)MEM_mallocN(sizeof(LogImageFile), __func__);
|
||||
LogImageFile *cineon = MEM_mallocN<LogImageFile>(__func__);
|
||||
if (cineon == nullptr) {
|
||||
if (verbose) {
|
||||
printf("cineon: Failed to malloc cineon file structure.\n");
|
||||
|
||||
@@ -123,7 +123,7 @@ static void fillDpxMainHeader(LogImageFile *dpx,
|
||||
LogImageFile *dpxOpen(const uchar *byteStuff, int fromMemory, size_t bufferSize)
|
||||
{
|
||||
DpxMainHeader header;
|
||||
LogImageFile *dpx = (LogImageFile *)MEM_mallocN(sizeof(LogImageFile), __func__);
|
||||
LogImageFile *dpx = MEM_mallocN<LogImageFile>(__func__);
|
||||
const char *filepath = (const char *)byteStuff;
|
||||
int i;
|
||||
|
||||
@@ -422,7 +422,7 @@ LogImageFile *dpxCreate(const char *filepath,
|
||||
const char *shortFilename = nullptr;
|
||||
uchar pad[6044];
|
||||
|
||||
LogImageFile *dpx = (LogImageFile *)MEM_mallocN(sizeof(LogImageFile), __func__);
|
||||
LogImageFile *dpx = MEM_mallocN<LogImageFile>(__func__);
|
||||
if (dpx == nullptr) {
|
||||
if (verbose) {
|
||||
printf("DPX: Failed to malloc dpx file structure.\n");
|
||||
|
||||
@@ -1111,7 +1111,7 @@ static float *getLinToLogLut(const LogImageFile *logImage, const LogImageElement
|
||||
uint lutsize = uint(logElement.maxValue + 1);
|
||||
uint i;
|
||||
|
||||
lut = static_cast<float *>(MEM_mallocN(sizeof(float) * lutsize, "getLinToLogLut"));
|
||||
lut = MEM_malloc_arrayN<float>(lutsize, "getLinToLogLut");
|
||||
|
||||
negativeFilmGamma = 0.6;
|
||||
step = logElement.refHighQuantity / logElement.maxValue;
|
||||
@@ -1139,7 +1139,7 @@ static float *getLogToLinLut(const LogImageFile *logImage, const LogImageElement
|
||||
uint lutsize = uint(logElement.maxValue + 1);
|
||||
uint i;
|
||||
|
||||
lut = static_cast<float *>(MEM_mallocN(sizeof(float) * lutsize, "getLogToLinLut"));
|
||||
lut = MEM_malloc_arrayN<float>(lutsize, "getLogToLinLut");
|
||||
|
||||
/* Building the Log -> Lin LUT */
|
||||
step = logElement.refHighQuantity / logElement.maxValue;
|
||||
@@ -1189,7 +1189,7 @@ static float *getLinToSrgbLut(const LogImageElement &logElement)
|
||||
uint lutsize = uint(logElement.maxValue + 1);
|
||||
uint i;
|
||||
|
||||
lut = static_cast<float *>(MEM_mallocN(sizeof(float) * lutsize, "getLogToLinLut"));
|
||||
lut = MEM_malloc_arrayN<float>(lutsize, "getLogToLinLut");
|
||||
|
||||
for (i = 0; i < lutsize; i++) {
|
||||
col = float(i) / logElement.maxValue;
|
||||
@@ -1210,7 +1210,7 @@ static float *getSrgbToLinLut(const LogImageElement &logElement)
|
||||
uint lutsize = uint(logElement.maxValue + 1);
|
||||
uint i;
|
||||
|
||||
lut = static_cast<float *>(MEM_mallocN(sizeof(float) * lutsize, "getLogToLinLut"));
|
||||
lut = MEM_malloc_arrayN<float>(lutsize, "getLogToLinLut");
|
||||
|
||||
for (i = 0; i < lutsize; i++) {
|
||||
col = float(i) / logElement.maxValue;
|
||||
|
||||
@@ -527,8 +527,8 @@ static bool colormanage_load_config(OCIO_ConstConfigRcPtr *config)
|
||||
|
||||
colorspace->num_aliases = OCIO_colorSpaceGetNumAliases(ocio_colorspace);
|
||||
if (colorspace->num_aliases > 0) {
|
||||
colorspace->aliases = static_cast<char(*)[MAX_COLORSPACE_NAME]>(MEM_callocN(
|
||||
sizeof(*colorspace->aliases) * colorspace->num_aliases, "ColorSpace aliases"));
|
||||
colorspace->aliases = MEM_calloc_arrayN<char[MAX_COLORSPACE_NAME]>(
|
||||
size_t(colorspace->num_aliases), "ColorSpace aliases");
|
||||
for (int i = 0; i < colorspace->num_aliases; i++) {
|
||||
BLI_strncpy(colorspace->aliases[i],
|
||||
OCIO_colorSpaceGetAlias(ocio_colorspace, i),
|
||||
@@ -1781,8 +1781,8 @@ static void do_display_buffer_apply_thread(DisplayBufferThread *handle)
|
||||
int channels = handle->channels;
|
||||
int width = handle->width;
|
||||
int height = handle->tot_line;
|
||||
float *linear_buffer = static_cast<float *>(MEM_mallocN(
|
||||
size_t(channels) * width * height * sizeof(float), "color conversion linear buffer"));
|
||||
float *linear_buffer = MEM_malloc_arrayN<float>(
|
||||
size_t(channels) * size_t(width) * size_t(height), "color conversion linear buffer");
|
||||
|
||||
bool is_straight_alpha;
|
||||
display_buffer_apply_get_linear_buffer(handle, height, linear_buffer, &is_straight_alpha);
|
||||
@@ -2743,7 +2743,6 @@ uchar *IMB_display_buffer_acquire(ImBuf *ibuf,
|
||||
void **cache_handle)
|
||||
{
|
||||
uchar *display_buffer;
|
||||
size_t buffer_size;
|
||||
ColormanageCacheViewSettings cache_view_settings;
|
||||
ColormanageCacheDisplaySettings cache_display_settings;
|
||||
ColorManagedViewSettings default_view_settings;
|
||||
@@ -2800,8 +2799,8 @@ uchar *IMB_display_buffer_acquire(ImBuf *ibuf,
|
||||
|
||||
/* ensure color management bit fields exists */
|
||||
if (!ibuf->display_buffer_flags) {
|
||||
ibuf->display_buffer_flags = static_cast<uint *>(
|
||||
MEM_callocN(sizeof(uint) * global_tot_display, "imbuf display_buffer_flags"));
|
||||
ibuf->display_buffer_flags = MEM_calloc_arrayN<uint>(size_t(global_tot_display),
|
||||
"imbuf display_buffer_flags");
|
||||
}
|
||||
else if (ibuf->userflags & IB_DISPLAY_BUFFER_INVALID) {
|
||||
/* all display buffers were marked as invalid from other areas,
|
||||
@@ -2820,8 +2819,8 @@ uchar *IMB_display_buffer_acquire(ImBuf *ibuf,
|
||||
return display_buffer;
|
||||
}
|
||||
|
||||
buffer_size = DISPLAY_BUFFER_CHANNELS * size_t(ibuf->x) * ibuf->y * sizeof(char);
|
||||
display_buffer = static_cast<uchar *>(MEM_mallocN(buffer_size, "imbuf display buffer"));
|
||||
display_buffer = MEM_malloc_arrayN<uchar>(
|
||||
DISPLAY_BUFFER_CHANNELS * size_t(ibuf->x) * size_t(ibuf->y), "imbuf display buffer");
|
||||
|
||||
colormanage_display_buffer_process(
|
||||
ibuf, display_buffer, applied_view_settings, display_settings);
|
||||
@@ -2857,8 +2856,8 @@ void IMB_display_buffer_transform_apply(uchar *display_buffer,
|
||||
ColormanageProcessor *cm_processor = IMB_colormanagement_display_processor_new(view_settings,
|
||||
display_settings);
|
||||
|
||||
buffer = static_cast<float *>(MEM_mallocN(size_t(channels) * width * height * sizeof(float),
|
||||
"display transform temp buffer"));
|
||||
buffer = MEM_malloc_arrayN<float>(size_t(channels) * size_t(width) * size_t(height),
|
||||
"display transform temp buffer");
|
||||
memcpy(buffer, linear_buffer, size_t(channels) * width * height * sizeof(float));
|
||||
|
||||
IMB_colormanagement_processor_apply(cm_processor, buffer, width, height, channels, predivide);
|
||||
@@ -2893,8 +2892,8 @@ void IMB_display_buffer_transform_apply_float(float *float_display_buffer,
|
||||
ColormanageProcessor *cm_processor = IMB_colormanagement_display_processor_new(view_settings,
|
||||
display_settings);
|
||||
|
||||
buffer = static_cast<float *>(MEM_mallocN(size_t(channels) * width * height * sizeof(float),
|
||||
"display transform temp buffer"));
|
||||
buffer = MEM_malloc_arrayN<float>(size_t(channels) * size_t(width) * size_t(height),
|
||||
"display transform temp buffer");
|
||||
memcpy(buffer, linear_buffer, size_t(channels) * width * height * sizeof(float));
|
||||
|
||||
IMB_colormanagement_processor_apply(cm_processor, buffer, width, height, channels, predivide);
|
||||
@@ -3581,8 +3580,8 @@ static void partial_buffer_update_rect(ImBuf *ibuf,
|
||||
channels = 4;
|
||||
}
|
||||
|
||||
display_buffer_float = static_cast<float *>(MEM_mallocN(
|
||||
size_t(channels) * width * height * sizeof(float), "display buffer for dither"));
|
||||
display_buffer_float = MEM_malloc_arrayN<float>(
|
||||
size_t(channels) * size_t(width) * size_t(height), "display buffer for dither");
|
||||
}
|
||||
|
||||
if (cm_processor) {
|
||||
|
||||
@@ -720,8 +720,7 @@ void IMB_float_from_byte(ImBuf *ibuf)
|
||||
*/
|
||||
float *rect_float = ibuf->float_buffer.data;
|
||||
if (rect_float == nullptr) {
|
||||
const size_t size = IMB_get_pixel_count(ibuf) * sizeof(float[4]);
|
||||
rect_float = static_cast<float *>(MEM_callocN(size, "IMB_float_from_byte"));
|
||||
rect_float = MEM_calloc_arrayN<float>(4 * IMB_get_pixel_count(ibuf), "IMB_float_from_byte");
|
||||
|
||||
if (rect_float == nullptr) {
|
||||
return;
|
||||
|
||||
@@ -273,8 +273,8 @@ ImBuf *imb_loadiris(const uchar *mem, size_t size, int flags, char colorspace[IM
|
||||
size_t tablen = size_t(ysize) * size_t(zsize_file) * sizeof(int);
|
||||
MFILE_SEEK(inf, HEADER_SIZE);
|
||||
|
||||
uint *starttab = static_cast<uint *>(MEM_mallocN(tablen, "iris starttab"));
|
||||
uint *lengthtab = static_cast<uint *>(MEM_mallocN(tablen, "iris endtab"));
|
||||
uint *starttab = MEM_malloc_arrayN<uint>(tablen, "iris starttab");
|
||||
uint *lengthtab = MEM_malloc_arrayN<uint>(tablen, "iris endtab");
|
||||
|
||||
#define MFILE_CAPACITY_AT_PTR_OK_OR_FAIL(p) \
|
||||
if (UNLIKELY((p) > mem_end)) { \
|
||||
@@ -781,12 +781,12 @@ static bool output_iris(const char *filepath,
|
||||
|
||||
tablen = ysize * zsize * sizeof(int);
|
||||
|
||||
image = (IMAGE *)MEM_mallocN(sizeof(IMAGE), "iris image");
|
||||
starttab = (uint *)MEM_mallocN(tablen, "iris starttab");
|
||||
lengthtab = (uint *)MEM_mallocN(tablen, "iris lengthtab");
|
||||
image = MEM_mallocN<IMAGE>("iris image");
|
||||
starttab = MEM_malloc_arrayN<uint>(size_t(tablen), "iris starttab");
|
||||
lengthtab = MEM_malloc_arrayN<uint>(size_t(tablen), "iris lengthtab");
|
||||
rlebuflen = 1.05 * xsize + 10;
|
||||
rlebuf = (uchar *)MEM_mallocN(rlebuflen, "iris rlebuf");
|
||||
lumbuf = (uint *)MEM_mallocN(xsize * sizeof(int), "iris lumbuf");
|
||||
rlebuf = MEM_malloc_arrayN<uchar>(size_t(rlebuflen), "iris rlebuf");
|
||||
lumbuf = MEM_malloc_arrayN<uint>(size_t(xsize), "iris lumbuf");
|
||||
|
||||
memset(image, 0, sizeof(IMAGE));
|
||||
image->imagic = IMAGIC;
|
||||
|
||||
@@ -842,7 +842,7 @@ static opj_image_t *ibuftoimage(ImBuf *ibuf, opj_cparameters_t *parameters)
|
||||
}
|
||||
}
|
||||
if (parameters->cp_cinema) {
|
||||
img_fol.rates = (float *)MEM_mallocN(parameters->tcp_numlayers * sizeof(float), "jp2_rates");
|
||||
img_fol.rates = MEM_malloc_arrayN<float>(size_t(parameters->tcp_numlayers), "jp2_rates");
|
||||
for (i = 0; i < parameters->tcp_numlayers; i++) {
|
||||
img_fol.rates[i] = parameters->tcp_rates[i];
|
||||
}
|
||||
|
||||
@@ -521,7 +521,7 @@ ImBuf *imb_thumbnail_jpeg(const char *filepath,
|
||||
if (i > 0 && !feof(infile)) {
|
||||
/* We found a JPEG thumbnail inside this image. */
|
||||
ImBuf *ibuf = nullptr;
|
||||
uchar *buffer = static_cast<uchar *>(MEM_callocN(JPEG_APP1_MAX, "thumbbuffer"));
|
||||
uchar *buffer = MEM_calloc_arrayN<uchar>(JPEG_APP1_MAX, "thumbbuffer");
|
||||
/* Just put SOI directly in buffer rather than seeking back 2 bytes. */
|
||||
buffer[0] = JPEG_MARKER_MSB;
|
||||
buffer[1] = JPEG_MARKER_SOI;
|
||||
@@ -573,22 +573,23 @@ static void write_jpeg(jpeg_compress_struct *cinfo, ImBuf *ibuf)
|
||||
|
||||
/* Static storage array for the short metadata. */
|
||||
char static_text[1024];
|
||||
const int static_text_size = ARRAY_SIZE(static_text);
|
||||
const size_t static_text_size = ARRAY_SIZE(static_text);
|
||||
LISTBASE_FOREACH (IDProperty *, prop, &ibuf->metadata->data.group) {
|
||||
if (prop->type == IDP_STRING) {
|
||||
int text_len;
|
||||
size_t text_len;
|
||||
if (STREQ(prop->name, "None")) {
|
||||
jpeg_write_marker(cinfo, JPEG_COM, (JOCTET *)IDP_String(prop), prop->len);
|
||||
}
|
||||
|
||||
char *text = static_text;
|
||||
int text_size = static_text_size;
|
||||
size_t text_size = static_text_size;
|
||||
/* 7 is for Blender, 2 colon separators, length of property
|
||||
* name and property value, followed by the nullptr-terminator
|
||||
* which isn't needed by JPEG but #BLI_snprintf_rlen requires it. */
|
||||
const int text_length_required = 7 + 2 + strlen(prop->name) + strlen(IDP_String(prop)) + 1;
|
||||
const size_t text_length_required = 7 + 2 + strlen(prop->name) + strlen(IDP_String(prop)) +
|
||||
1;
|
||||
if (text_length_required <= static_text_size) {
|
||||
text = static_cast<char *>(MEM_mallocN(text_length_required, "jpeg metadata field"));
|
||||
text = MEM_malloc_arrayN<char>(text_length_required, "jpeg metadata field");
|
||||
text_size = text_length_required;
|
||||
}
|
||||
|
||||
@@ -604,7 +605,7 @@ static void write_jpeg(jpeg_compress_struct *cinfo, ImBuf *ibuf)
|
||||
text_len = BLI_snprintf_rlen(
|
||||
text, text_size, "Blender:%s:%s", prop->name, IDP_String(prop));
|
||||
/* Don't write the null byte (not expected by the JPEG format). */
|
||||
jpeg_write_marker(cinfo, JPEG_COM, (JOCTET *)text, text_len);
|
||||
jpeg_write_marker(cinfo, JPEG_COM, (JOCTET *)text, uint(text_len));
|
||||
|
||||
/* TODO(sergey): Ideally we will try to re-use allocation as
|
||||
* much as possible. In practice, such long fields don't happen
|
||||
@@ -616,8 +617,8 @@ static void write_jpeg(jpeg_compress_struct *cinfo, ImBuf *ibuf)
|
||||
}
|
||||
}
|
||||
|
||||
row_pointer[0] = static_cast<JSAMPROW>(MEM_mallocN(
|
||||
sizeof(JSAMPLE) * cinfo->input_components * cinfo->image_width, "jpeg row_pointer"));
|
||||
row_pointer[0] = MEM_malloc_arrayN<std::remove_pointer_t<JSAMPROW>>(
|
||||
size_t(cinfo->input_components) * size_t(cinfo->image_width), "jpeg row_pointer");
|
||||
|
||||
for (y = ibuf->y - 1; y >= 0; y--) {
|
||||
rect = ibuf->byte_buffer.data + 4 * y * size_t(ibuf->x);
|
||||
|
||||
@@ -270,7 +270,7 @@ MovieCache *IMB_moviecache_create(const char *name,
|
||||
|
||||
PRINT("%s: cache '%s' create\n", __func__, name);
|
||||
|
||||
cache = (MovieCache *)MEM_callocN(sizeof(MovieCache), "MovieCache");
|
||||
cache = MEM_callocN<MovieCache>("MovieCache");
|
||||
|
||||
STRNCPY(cache->name, name);
|
||||
|
||||
@@ -505,7 +505,7 @@ void IMB_moviecache_get_cache_segments(
|
||||
}
|
||||
else {
|
||||
int totframe = BLI_ghash_len(cache->hash);
|
||||
int *frames = (int *)MEM_callocN(totframe * sizeof(int), "movieclip cache frames");
|
||||
int *frames = MEM_calloc_arrayN<int>(size_t(totframe), "movieclip cache frames");
|
||||
int a, totseg = 0;
|
||||
GHashIterator gh_iter;
|
||||
|
||||
@@ -540,7 +540,7 @@ void IMB_moviecache_get_cache_segments(
|
||||
if (totseg) {
|
||||
int b, *points;
|
||||
|
||||
points = (int *)MEM_callocN(sizeof(int[2]) * totseg, "movieclip cache segments");
|
||||
points = MEM_calloc_arrayN<int>(2 * size_t(totseg), "movieclip cache segments");
|
||||
|
||||
/* fill */
|
||||
for (a = 0, b = 0; a < totframe; a++) {
|
||||
|
||||
@@ -1183,8 +1183,7 @@ void IMB_exr_write_channels(void *handle)
|
||||
|
||||
/* We allocate temporary storage for half pixels for all the channels at once. */
|
||||
if (data->num_half_channels != 0) {
|
||||
rect_half = (half *)MEM_mallocN(sizeof(half) * data->num_half_channels * num_pixels,
|
||||
__func__);
|
||||
rect_half = MEM_malloc_arrayN<half>(size_t(data->num_half_channels) * num_pixels, __func__);
|
||||
current_rect_half = rect_half;
|
||||
}
|
||||
|
||||
@@ -1769,8 +1768,8 @@ static bool imb_exr_multilayer_parse_channels_from_file(ExrHandle *data)
|
||||
LISTBASE_FOREACH (ExrLayer *, lay, &data->layers) {
|
||||
LISTBASE_FOREACH (ExrPass *, pass, &lay->passes) {
|
||||
if (pass->totchan) {
|
||||
pass->rect = (float *)MEM_callocN(
|
||||
data->width * data->height * pass->totchan * sizeof(float), "pass rect");
|
||||
pass->rect = MEM_calloc_arrayN<float>(
|
||||
size_t(data->width) * size_t(data->height) * size_t(pass->totchan), "pass rect");
|
||||
if (pass->totchan == 1) {
|
||||
ExrChannel *echan = pass->chan[0];
|
||||
echan->rect = pass->rect;
|
||||
|
||||
@@ -274,7 +274,7 @@ static void rect_realloc_4bytes(void **buf_p, const uint size[2])
|
||||
return;
|
||||
}
|
||||
MEM_freeN(*buf_p);
|
||||
*buf_p = MEM_mallocN(sizeof(uint) * size[0] * size[1], __func__);
|
||||
*buf_p = MEM_malloc_arrayN<uint>(size[0] * size[1], __func__);
|
||||
}
|
||||
|
||||
static void rect_realloc_16bytes(void **buf_p, const uint size[2])
|
||||
@@ -283,7 +283,7 @@ static void rect_realloc_16bytes(void **buf_p, const uint size[2])
|
||||
return;
|
||||
}
|
||||
MEM_freeN(*buf_p);
|
||||
*buf_p = MEM_mallocN(sizeof(uint[4]) * size[0] * size[1], __func__);
|
||||
*buf_p = MEM_malloc_arrayN<uint>(4 * size[0] * size[1], __func__);
|
||||
}
|
||||
|
||||
void IMB_rect_size_set(ImBuf *ibuf, const uint size[2])
|
||||
|
||||
@@ -71,8 +71,8 @@ bool IMB_rotate_orthogonal(ImBuf *ibuf, int degrees)
|
||||
if (ibuf->float_buffer.data) {
|
||||
const int channels = ibuf->channels;
|
||||
const float *src_pixels = ibuf->float_buffer.data;
|
||||
float *dst_pixels = static_cast<float *>(
|
||||
MEM_malloc_arrayN(size_t(size_x) * size_y, channels * sizeof(float), __func__));
|
||||
float *dst_pixels = MEM_malloc_arrayN<float>(
|
||||
size_t(channels) * size_t(size_x) * size_t(size_y), __func__);
|
||||
rotate_pixels<float>(degrees, size_x, size_y, src_pixels, dst_pixels, ibuf->channels);
|
||||
IMB_assign_float_buffer(ibuf, dst_pixels, IB_TAKE_OWNERSHIP);
|
||||
if (ibuf->byte_buffer.data) {
|
||||
@@ -81,8 +81,7 @@ bool IMB_rotate_orthogonal(ImBuf *ibuf, int degrees)
|
||||
}
|
||||
else if (ibuf->byte_buffer.data) {
|
||||
const uchar *src_pixels = ibuf->byte_buffer.data;
|
||||
uchar *dst_pixels = static_cast<uchar *>(
|
||||
MEM_malloc_arrayN(size_t(size_x) * size_y, sizeof(uchar[4]), __func__));
|
||||
uchar *dst_pixels = MEM_malloc_arrayN<uchar>(4 * size_t(size_x) * size_t(size_y), __func__);
|
||||
rotate_pixels<uchar>(degrees, size_x, size_y, src_pixels, dst_pixels, 4);
|
||||
IMB_assign_byte_buffer(ibuf, dst_pixels, IB_TAKE_OWNERSHIP);
|
||||
}
|
||||
@@ -108,7 +107,7 @@ void IMB_flipy(ImBuf *ibuf)
|
||||
|
||||
top = (uint *)ibuf->byte_buffer.data;
|
||||
bottom = top + ((y_size - 1) * x_size);
|
||||
line = static_cast<uint *>(MEM_mallocN(stride, "linebuf"));
|
||||
line = MEM_malloc_arrayN<uint>(x_size, "linebuf");
|
||||
|
||||
y_size >>= 1;
|
||||
|
||||
@@ -133,7 +132,7 @@ void IMB_flipy(ImBuf *ibuf)
|
||||
|
||||
topf = ibuf->float_buffer.data;
|
||||
bottomf = topf + 4 * ((y_size - 1) * x_size);
|
||||
linef = static_cast<float *>(MEM_mallocN(stride, "linebuf"));
|
||||
linef = MEM_malloc_arrayN<float>(4 * x_size, "linebuf");
|
||||
|
||||
y_size >>= 1;
|
||||
|
||||
|
||||
@@ -343,16 +343,15 @@ static void alloc_scale_dst_buffers(
|
||||
{
|
||||
*r_dst_byte = nullptr;
|
||||
if (ibuf->byte_buffer.data != nullptr) {
|
||||
*r_dst_byte = static_cast<uchar4 *>(
|
||||
MEM_mallocN(sizeof(uchar4) * newx * newy, "scale_buf_byte"));
|
||||
*r_dst_byte = MEM_malloc_arrayN<uchar4>(newx * newy, "scale_buf_byte");
|
||||
if (*r_dst_byte == nullptr) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
*r_dst_float = nullptr;
|
||||
if (ibuf->float_buffer.data != nullptr) {
|
||||
*r_dst_float = static_cast<float *>(
|
||||
MEM_mallocN(sizeof(float) * ibuf->channels * newx * newy, "scale_buf_float"));
|
||||
*r_dst_float = MEM_malloc_arrayN<float>(size_t(ibuf->channels) * newx * newy,
|
||||
"scale_buf_float");
|
||||
if (*r_dst_float == nullptr) {
|
||||
if (*r_dst_byte) {
|
||||
MEM_freeN(*r_dst_byte);
|
||||
|
||||
@@ -132,7 +132,7 @@ static void *imb_gpu_get_data(const ImBuf *ibuf,
|
||||
* 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__);
|
||||
data_rect = MEM_malloc_arrayN<float>(4 * size_t(ibuf->x) * size_t(ibuf->y), __func__);
|
||||
*r_freedata = freedata = true;
|
||||
|
||||
if (data_rect == nullptr) {
|
||||
@@ -181,7 +181,7 @@ static void *imb_gpu_get_data(const ImBuf *ibuf,
|
||||
}
|
||||
else {
|
||||
/* Other colorspace, store as float texture to avoid precision loss. */
|
||||
data_rect = MEM_mallocN(sizeof(float[4]) * ibuf->x * ibuf->y, __func__);
|
||||
data_rect = MEM_malloc_arrayN<float>(4 * size_t(ibuf->x) * size_t(ibuf->y), __func__);
|
||||
*r_freedata = freedata = true;
|
||||
is_float_rect = true;
|
||||
|
||||
|
||||
@@ -167,8 +167,7 @@ bool imb_savewebp(ImBuf *ibuf, const char *filepath, int /*flags*/)
|
||||
/* We must convert the ImBuf RGBA buffer to RGB as WebP expects a RGB buffer. */
|
||||
const size_t num_pixels = ibuf->x * ibuf->y;
|
||||
const uint8_t *rgba_rect = ibuf->byte_buffer.data;
|
||||
uint8_t *rgb_rect = static_cast<uint8_t *>(
|
||||
MEM_mallocN(sizeof(uint8_t) * num_pixels * 3, "webp rgb_rect"));
|
||||
uint8_t *rgb_rect = MEM_malloc_arrayN<uint8_t>(num_pixels * 3, "webp rgb_rect");
|
||||
for (int i = 0; i < num_pixels; i++) {
|
||||
rgb_rect[i * 3 + 0] = rgba_rect[i * 4 + 0];
|
||||
rgb_rect[i * 3 + 1] = rgba_rect[i * 4 + 1];
|
||||
|
||||
Reference in New Issue
Block a user