Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/imbuf')
-rw-r--r--source/blender/imbuf/intern/IMB_indexer.h2
-rw-r--r--source/blender/imbuf/intern/openexr/openexr_api.cpp171
-rw-r--r--source/blender/imbuf/intern/openexr/openexr_multi.h15
-rw-r--r--source/blender/imbuf/intern/openexr/openexr_stub.cpp25
-rw-r--r--source/blender/imbuf/intern/radiance_hdr.c4
-rw-r--r--source/blender/imbuf/intern/readimage.c2
-rw-r--r--source/blender/imbuf/intern/rotate.c2
-rw-r--r--source/blender/imbuf/intern/targa.c8
8 files changed, 126 insertions, 103 deletions
diff --git a/source/blender/imbuf/intern/IMB_indexer.h b/source/blender/imbuf/intern/IMB_indexer.h
index 37309ccc13a..6c66b11df4f 100644
--- a/source/blender/imbuf/intern/IMB_indexer.h
+++ b/source/blender/imbuf/intern/IMB_indexer.h
@@ -33,7 +33,7 @@
* a) different time-codes within one file (like DTS/PTS, Time-code-Track,
* "implicit" time-codes within DV-files and HDV-files etc.)
* b) seeking difficulties within FFMPEG for files with timestamp holes
- * c) broken files that miss several frames / have varying framerates
+ * c) broken files that miss several frames / have varying frame-rates
* d) use proxies accordingly
*
* ... we need index files, that provide us with
diff --git a/source/blender/imbuf/intern/openexr/openexr_api.cpp b/source/blender/imbuf/intern/openexr/openexr_api.cpp
index cd323e72003..adf09f8dda8 100644
--- a/source/blender/imbuf/intern/openexr/openexr_api.cpp
+++ b/source/blender/imbuf/intern/openexr/openexr_api.cpp
@@ -555,7 +555,7 @@ static bool imb_save_openexr_float(ImBuf *ibuf, const char *name, const int flag
int xstride = sizeof(float) * channels;
int ystride = -xstride * width;
- /* last scanline, stride negative */
+ /* Last scan-line, stride negative. */
float *rect[4] = {nullptr, nullptr, nullptr, nullptr};
rect[0] = ibuf->rect_float + channels * (height - 1) * width;
rect[1] = (channels >= 2) ? rect[0] + 1 : rect[0];
@@ -654,7 +654,7 @@ struct ExrChannel {
char name[EXR_TOT_MAXNAME + 1]; /* full name with everything */
struct MultiViewChannelName *m; /* struct to store all multipart channel info */
- int xstride, ystride; /* step to next pixel, to next scanline */
+ int xstride, ystride; /* step to next pixel, to next scan-line. */
float *rect; /* first pointer to write in */
char chan_id; /* quick lookup of channel char */
int view_id; /* quick lookup of channel view */
@@ -681,6 +681,8 @@ struct ExrLayer {
ListBase passes;
};
+static bool imb_exr_multilayer_parse_channels_from_file(ExrHandle *data);
+
/* ********************** */
void *IMB_exr_get_handle(void)
@@ -839,12 +841,12 @@ void IMB_exr_add_channel(void *handle,
}
/* used for output files (from RenderResult) (single and multilayer, single and multiview) */
-int IMB_exr_begin_write(void *handle,
- const char *filename,
- int width,
- int height,
- int compress,
- const StampData *stamp)
+bool IMB_exr_begin_write(void *handle,
+ const char *filename,
+ int width,
+ int height,
+ int compress,
+ const StampData *stamp)
{
ExrHandle *data = (ExrHandle *)handle;
Header header(width, height);
@@ -962,51 +964,64 @@ void IMB_exrtile_begin_write(
}
/* read from file */
-int IMB_exr_begin_read(void *handle, const char *filename, int *width, int *height)
+bool IMB_exr_begin_read(
+ void *handle, const char *filename, int *width, int *height, const bool parse_channels)
{
ExrHandle *data = (ExrHandle *)handle;
ExrChannel *echan;
/* 32 is arbitrary, but zero length files crashes exr. */
- if (BLI_exists(filename) && BLI_file_size(filename) > 32) {
- /* avoid crash/abort when we don't have permission to write here */
- try {
- data->ifile_stream = new IFileStream(filename);
- data->ifile = new MultiPartInputFile(*(data->ifile_stream));
- }
- catch (const std::exception &) {
- delete data->ifile;
- delete data->ifile_stream;
+ if (!(BLI_exists(filename) && BLI_file_size(filename) > 32)) {
+ return false;
+ }
- data->ifile = nullptr;
- data->ifile_stream = nullptr;
- }
+ /* avoid crash/abort when we don't have permission to write here */
+ try {
+ data->ifile_stream = new IFileStream(filename);
+ data->ifile = new MultiPartInputFile(*(data->ifile_stream));
+ }
+ catch (const std::exception &) {
+ delete data->ifile;
+ delete data->ifile_stream;
- if (data->ifile) {
- Box2i dw = data->ifile->header(0).dataWindow();
- data->width = *width = dw.max.x - dw.min.x + 1;
- data->height = *height = dw.max.y - dw.min.y + 1;
+ data->ifile = nullptr;
+ data->ifile_stream = nullptr;
+ }
- imb_exr_get_views(*data->ifile, *data->multiView);
+ if (!data->ifile) {
+ return false;
+ }
- std::vector<MultiViewChannelName> channels;
- GetChannelsInMultiPartFile(*data->ifile, channels);
+ Box2i dw = data->ifile->header(0).dataWindow();
+ data->width = *width = dw.max.x - dw.min.x + 1;
+ data->height = *height = dw.max.y - dw.min.y + 1;
- for (const MultiViewChannelName &channel : channels) {
- IMB_exr_add_channel(
- data, nullptr, channel.name.c_str(), channel.view.c_str(), 0, 0, nullptr, false);
+ if (parse_channels) {
+ /* Parse channels into view/layer/pass. */
+ if (!imb_exr_multilayer_parse_channels_from_file(data)) {
+ return false;
+ }
+ }
+ else {
+ /* Read view and channels without parsing. */
+ imb_exr_get_views(*data->ifile, *data->multiView);
- echan = (ExrChannel *)data->channels.last;
- echan->m->name = channel.name;
- echan->m->view = channel.view;
- echan->m->part_number = channel.part_number;
- echan->m->internal_name = channel.internal_name;
- }
+ std::vector<MultiViewChannelName> channels;
+ GetChannelsInMultiPartFile(*data->ifile, channels);
+
+ for (const MultiViewChannelName &channel : channels) {
+ IMB_exr_add_channel(
+ data, nullptr, channel.name.c_str(), channel.view.c_str(), 0, 0, nullptr, false);
- return 1;
+ echan = (ExrChannel *)data->channels.last;
+ echan->m->name = channel.name;
+ echan->m->view = channel.view;
+ echan->m->part_number = channel.part_number;
+ echan->m->internal_name = channel.internal_name;
}
}
- return 0;
+
+ return true;
}
/* still clumsy name handling, layers/channels can be ordered as list in list later */
@@ -1112,7 +1127,7 @@ void IMB_exr_write_channels(void *handle)
}
for (echan = (ExrChannel *)data->channels.first; echan; echan = echan->next) {
- /* Writing starts from last scanline, stride negative. */
+ /* Writing starts from last scan-line, stride negative. */
if (echan->use_half_float) {
float *rect = echan->rect;
half *cur = current_rect_half;
@@ -1254,7 +1269,7 @@ void IMB_exr_read_channels(void *handle)
if (!flip) {
/* Inverse correct first pixel for data-window coordinates. */
rect -= echan->xstride * (dw.min.x - dw.min.y * data->width);
- /* move to last scanline to flip to Blender convention */
+ /* Move to last scan-line to flip to Blender convention. */
rect += echan->xstride * (data->height - 1) * data->width;
ystride = -ystride;
}
@@ -1524,25 +1539,8 @@ static ExrPass *imb_exr_get_pass(ListBase *lb, char *passname)
return pass;
}
-/* creates channels, makes a hierarchy and assigns memory to channels */
-static ExrHandle *imb_exr_begin_read_mem(IStream &file_stream,
- MultiPartInputFile &file,
- int width,
- int height)
+static bool imb_exr_multilayer_parse_channels_from_file(ExrHandle *data)
{
- ExrLayer *lay;
- ExrPass *pass;
- ExrChannel *echan;
- ExrHandle *data = (ExrHandle *)IMB_exr_get_handle();
- int a;
- char layname[EXR_TOT_MAXNAME], passname[EXR_TOT_MAXNAME];
-
- data->ifile_stream = &file_stream;
- data->ifile = &file;
-
- data->width = width;
- data->height = height;
-
std::vector<MultiViewChannelName> channels;
GetChannelsInMultiPartFile(*data->ifile, channels);
@@ -1552,7 +1550,7 @@ static ExrHandle *imb_exr_begin_read_mem(IStream &file_stream,
IMB_exr_add_channel(
data, nullptr, channel.name.c_str(), channel.view.c_str(), 0, 0, nullptr, false);
- echan = (ExrChannel *)data->channels.last;
+ ExrChannel *echan = (ExrChannel *)data->channels.last;
echan->m->name = channel.name;
echan->m->view = channel.view;
echan->m->part_number = channel.part_number;
@@ -1561,7 +1559,9 @@ static ExrHandle *imb_exr_begin_read_mem(IStream &file_stream,
/* now try to sort out how to assign memory to the channels */
/* first build hierarchical layer list */
- for (echan = (ExrChannel *)data->channels.first; echan; echan = echan->next) {
+ ExrChannel *echan = (ExrChannel *)data->channels.first;
+ for (; echan; echan = echan->next) {
+ char layname[EXR_TOT_MAXNAME], passname[EXR_TOT_MAXNAME];
if (imb_exr_split_channel_name(echan, layname, passname)) {
const char *view = echan->m->view.c_str();
@@ -1591,21 +1591,20 @@ static ExrHandle *imb_exr_begin_read_mem(IStream &file_stream,
}
if (echan) {
printf("error, too many channels in one pass: %s\n", echan->m->name.c_str());
- IMB_exr_close(data);
- return nullptr;
+ return false;
}
/* with some heuristics, try to merge the channels in buffers */
- for (lay = (ExrLayer *)data->layers.first; lay; lay = lay->next) {
- for (pass = (ExrPass *)lay->passes.first; pass; pass = pass->next) {
+ for (ExrLayer *lay = (ExrLayer *)data->layers.first; lay; lay = lay->next) {
+ for (ExrPass *pass = (ExrPass *)lay->passes.first; pass; pass = pass->next) {
if (pass->totchan) {
- pass->rect = (float *)MEM_callocN(width * height * pass->totchan * sizeof(float),
- "pass rect");
+ pass->rect = (float *)MEM_callocN(
+ data->width * data->height * pass->totchan * sizeof(float), "pass rect");
if (pass->totchan == 1) {
- echan = pass->chan[0];
+ ExrChannel *echan = pass->chan[0];
echan->rect = pass->rect;
echan->xstride = 1;
- echan->ystride = width;
+ echan->ystride = data->width;
pass->chan_id[0] = echan->chan_id;
}
else {
@@ -1634,20 +1633,20 @@ static ExrHandle *imb_exr_begin_read_mem(IStream &file_stream,
lookup[(unsigned int)'V'] = 1;
lookup[(unsigned int)'A'] = 2;
}
- for (a = 0; a < pass->totchan; a++) {
+ for (int a = 0; a < pass->totchan; a++) {
echan = pass->chan[a];
echan->rect = pass->rect + lookup[(unsigned int)echan->chan_id];
echan->xstride = pass->totchan;
- echan->ystride = width * pass->totchan;
+ echan->ystride = data->width * pass->totchan;
pass->chan_id[(unsigned int)lookup[(unsigned int)echan->chan_id]] = echan->chan_id;
}
}
else { /* unknown */
- for (a = 0; a < pass->totchan; a++) {
- echan = pass->chan[a];
+ for (int a = 0; a < pass->totchan; a++) {
+ ExrChannel *echan = pass->chan[a];
echan->rect = pass->rect + a;
echan->xstride = pass->totchan;
- echan->ystride = width * pass->totchan;
+ echan->ystride = data->width * pass->totchan;
pass->chan_id[a] = echan->chan_id;
}
}
@@ -1656,6 +1655,28 @@ static ExrHandle *imb_exr_begin_read_mem(IStream &file_stream,
}
}
+ return true;
+}
+
+/* creates channels, makes a hierarchy and assigns memory to channels */
+static ExrHandle *imb_exr_begin_read_mem(IStream &file_stream,
+ MultiPartInputFile &file,
+ int width,
+ int height)
+{
+ ExrHandle *data = (ExrHandle *)IMB_exr_get_handle();
+
+ data->ifile_stream = &file_stream;
+ data->ifile = &file;
+
+ data->width = width;
+ data->height = height;
+
+ if (!imb_exr_multilayer_parse_channels_from_file(data)) {
+ IMB_exr_close(data);
+ return nullptr;
+ }
+
return data;
}
@@ -1988,7 +2009,7 @@ struct ImBuf *imb_load_openexr(const unsigned char *mem,
/* Inverse correct first pixel for data-window
* coordinates (- dw.min.y because of y flip). */
first = ibuf->rect_float - 4 * (dw.min.x - dw.min.y * width);
- /* but, since we read y-flipped (negative y stride) we move to last scanline */
+ /* But, since we read y-flipped (negative y stride) we move to last scan-line. */
first += 4 * (height - 1) * width;
if (num_rgb_channels > 0) {
diff --git a/source/blender/imbuf/intern/openexr/openexr_multi.h b/source/blender/imbuf/intern/openexr/openexr_multi.h
index 556717ad618..82a5d161ded 100644
--- a/source/blender/imbuf/intern/openexr/openexr_multi.h
+++ b/source/blender/imbuf/intern/openexr/openexr_multi.h
@@ -50,13 +50,14 @@ void IMB_exr_add_channel(void *handle,
float *rect,
bool use_half_float);
-int IMB_exr_begin_read(void *handle, const char *filename, int *width, int *height);
-int IMB_exr_begin_write(void *handle,
- const char *filename,
- int width,
- int height,
- int compress,
- const struct StampData *stamp);
+bool IMB_exr_begin_read(
+ void *handle, const char *filename, int *width, int *height, const bool parse_channels);
+bool IMB_exr_begin_write(void *handle,
+ const char *filename,
+ int width,
+ int height,
+ int compress,
+ const struct StampData *stamp);
void IMB_exrtile_begin_write(
void *handle, const char *filename, int mipmap, int width, int height, int tilex, int tiley);
diff --git a/source/blender/imbuf/intern/openexr/openexr_stub.cpp b/source/blender/imbuf/intern/openexr/openexr_stub.cpp
index 51bc2094053..9b4d6178613 100644
--- a/source/blender/imbuf/intern/openexr/openexr_stub.cpp
+++ b/source/blender/imbuf/intern/openexr/openexr_stub.cpp
@@ -43,21 +43,22 @@ void IMB_exr_add_channel(void * /*handle*/,
{
}
-int IMB_exr_begin_read(void * /*handle*/,
- const char * /*filename*/,
- int * /*width*/,
- int * /*height*/)
+bool IMB_exr_begin_read(void * /*handle*/,
+ const char * /*filename*/,
+ int * /*width*/,
+ int * /*height*/,
+ const bool /*add_channels*/)
{
- return 0;
+ return false;
}
-int IMB_exr_begin_write(void * /*handle*/,
- const char * /*filename*/,
- int /*width*/,
- int /*height*/,
- int /*compress*/,
- const struct StampData * /*stamp*/)
+bool IMB_exr_begin_write(void * /*handle*/,
+ const char * /*filename*/,
+ int /*width*/,
+ int /*height*/,
+ int /*compress*/,
+ const struct StampData * /*stamp*/)
{
- return 0;
+ return false;
}
void IMB_exrtile_begin_write(void * /*handle*/,
const char * /*filename*/,
diff --git a/source/blender/imbuf/intern/radiance_hdr.c b/source/blender/imbuf/intern/radiance_hdr.c
index 94b2a62aa26..7f4e4dd31df 100644
--- a/source/blender/imbuf/intern/radiance_hdr.c
+++ b/source/blender/imbuf/intern/radiance_hdr.c
@@ -294,7 +294,7 @@ struct ImBuf *imb_loadhdr(const unsigned char *mem,
break;
}
for (x = 0; x < width; x++) {
- /* convert to ldr */
+ /* Convert to LDR. */
RGBE2FLOAT(sline[x], fcol);
*rect_float++ = fcol[RED];
*rect_float++ = fcol[GRN];
@@ -328,7 +328,7 @@ static int fwritecolrs(
rgbe_scan = (RGBE *)MEM_mallocN(sizeof(RGBE) * width, "radhdr_write_tmpscan");
- /* convert scanline */
+ /* Convert scan-line. */
for (size_t i = 0, j = 0; i < width; i++) {
if (fpscan) {
fcol[RED] = fpscan[j];
diff --git a/source/blender/imbuf/intern/readimage.c b/source/blender/imbuf/intern/readimage.c
index 50210650f05..c75bdfa375c 100644
--- a/source/blender/imbuf/intern/readimage.c
+++ b/source/blender/imbuf/intern/readimage.c
@@ -126,7 +126,7 @@ ImBuf *IMB_ibImageFromMemory(const unsigned char *mem,
}
if ((flags & IB_test) == 0) {
- fprintf(stderr, "%s: unknown fileformat (%s)\n", __func__, descr);
+ fprintf(stderr, "%s: unknown file-format (%s)\n", __func__, descr);
}
return NULL;
diff --git a/source/blender/imbuf/intern/rotate.c b/source/blender/imbuf/intern/rotate.c
index c2fc2190ce5..83dc29aa107 100644
--- a/source/blender/imbuf/intern/rotate.c
+++ b/source/blender/imbuf/intern/rotate.c
@@ -69,7 +69,7 @@ void IMB_flipy(struct ImBuf *ibuf)
topf = ibuf->rect_float;
bottomf = topf + 4 * ((y - 1) * x);
- linef = MEM_mallocN(4 * x * sizeof(float), "linebuff");
+ linef = MEM_mallocN(4 * x * sizeof(float), "linebuf");
y >>= 1;
diff --git a/source/blender/imbuf/intern/targa.c b/source/blender/imbuf/intern/targa.c
index 8ed0b8b535c..333e29e6d97 100644
--- a/source/blender/imbuf/intern/targa.c
+++ b/source/blender/imbuf/intern/targa.c
@@ -192,7 +192,7 @@ static bool makebody_tga(ImBuf *ibuf, FILE *file, int (*out)(unsigned int, FILE
else {
while (*rect++ == this) { /* seek for first different byte */
if (--bytes == 0) {
- break; /* oor end of line */
+ break; /* Or end of line. */
}
}
rect--;
@@ -470,7 +470,7 @@ static void decodetarga(struct ImBuf *ibuf, const unsigned char *mem, size_t mem
if (psize & 2) {
if (psize & 1) {
- /* order = bgra */
+ /* Order = BGRA. */
cp[0] = mem[3];
cp[1] = mem[0];
cp[2] = mem[1];
@@ -512,7 +512,7 @@ static void decodetarga(struct ImBuf *ibuf, const unsigned char *mem, size_t mem
while (count > 0) {
if (psize & 2) {
if (psize & 1) {
- /* order = bgra */
+ /* Order = BGRA. */
cp[0] = mem[3];
cp[1] = mem[0];
cp[2] = mem[1];
@@ -589,7 +589,7 @@ static void ldtarga(struct ImBuf *ibuf, const unsigned char *mem, size_t mem_siz
if (psize & 2) {
if (psize & 1) {
- /* order = bgra */
+ /* Order = BGRA. */
cp[0] = mem[3];
cp[1] = mem[0];
cp[2] = mem[1];