forked from bartvdbraak/blender
Patch #34632: DPX/Cineon speed up
Done by Julien Enche (aka trap), thanks! From the patch comment: This patch speeds up Cineon/DPX file loading. Some more checks are done in dpxOpen and cineonOpen functions so IB_test flag can now be taken into account safely, and an unnecessary call to IMB_rect_from_float has been removed. DPX/Cineon file now loads around 3 times faster on my computer. Own comment: Ideally, IB_rect shall indeed indicate which buffers to load, however currently all places which reads image uses this flag. This fact already mentioned in OpenEXR reader and it shall be fine to skip doing rect_from_float in readers themselves.
This commit is contained in:
parent
42660a204a
commit
1ea16dcf9b
@ -70,30 +70,23 @@ static struct ImBuf *imb_load_dpx_cineon(unsigned char *mem, size_t size, int us
|
||||
|
||||
logImageGetSize(image, &width, &height, &depth);
|
||||
|
||||
if (width == 0 || height == 0) {
|
||||
logImageClose(image);
|
||||
return 0;
|
||||
}
|
||||
|
||||
ibuf = IMB_allocImBuf(width, height, 32, IB_rectfloat | flags);
|
||||
if (ibuf == 0) {
|
||||
logImageClose(image);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!(flags & IB_test)) {
|
||||
if (logImageGetDataRGBA(image, ibuf->rect_float, 1) != 0) {
|
||||
/* Conversion not possible (probably because the format is unsupported) */
|
||||
logImageClose(image);
|
||||
MEM_freeN(ibuf);
|
||||
IMB_freeImBuf(ibuf);
|
||||
return 0;
|
||||
}
|
||||
IMB_flipy(ibuf);
|
||||
}
|
||||
|
||||
logImageClose(image);
|
||||
ibuf->ftype = use_cineon ? CINEON : DPX;
|
||||
IMB_flipy(ibuf);
|
||||
|
||||
if (flags & IB_rect)
|
||||
IMB_rect_from_float(ibuf);
|
||||
|
||||
if (flags & IB_alphamode_detect)
|
||||
ibuf->flags |= IB_alphamode_premul;
|
||||
|
@ -196,6 +196,13 @@ LogImageFile *cineonOpen(const unsigned char *byteStuff, int fromMemory, size_t
|
||||
|
||||
cineon->width = swap_uint(header.imageHeader.element[0].pixels_per_line, cineon->isMSB);
|
||||
cineon->height = swap_uint(header.imageHeader.element[0].lines_per_image, cineon->isMSB);
|
||||
|
||||
if (cineon->width == 0 || cineon->height == 0) {
|
||||
if (verbose) printf("Cineon: Wrong image dimension: %dx%d\n", cineon->width, cineon->height);
|
||||
logImageClose(cineon);
|
||||
return 0;
|
||||
}
|
||||
|
||||
cineon->depth = header.imageHeader.elements_per_image;
|
||||
cineon->srcFormat = format_Cineon;
|
||||
|
||||
@ -205,6 +212,7 @@ LogImageFile *cineonOpen(const unsigned char *byteStuff, int fromMemory, size_t
|
||||
cineon->numElements = header.imageHeader.elements_per_image;
|
||||
else {
|
||||
if (verbose) printf("Cineon: Data interleave not supported: %d\n", header.imageHeader.interleave);
|
||||
logImageClose(cineon);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -235,6 +243,7 @@ LogImageFile *cineonOpen(const unsigned char *byteStuff, int fromMemory, size_t
|
||||
}
|
||||
else {
|
||||
if (verbose) printf("Cineon: Cineon image depth unsupported: %d\n", cineon->depth);
|
||||
logImageClose(cineon);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -264,6 +273,7 @@ LogImageFile *cineonOpen(const unsigned char *byteStuff, int fromMemory, size_t
|
||||
default:
|
||||
/* Not supported */
|
||||
if (verbose) printf("Cineon: packing unsupported: %d\n", header.imageHeader.packing);
|
||||
logImageClose(cineon);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -192,8 +192,21 @@ 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);
|
||||
if (dpx->numElements == 0) {
|
||||
if (verbose) printf("DPX: Wrong number of elements: %d\n", dpx->numElements);
|
||||
logImageClose(dpx);
|
||||
return 0;
|
||||
}
|
||||
|
||||
dpx->width = swap_uint(header.imageHeader.pixels_per_line, dpx->isMSB);
|
||||
dpx->height = swap_uint(header.imageHeader.lines_per_element, dpx->isMSB);
|
||||
|
||||
if (dpx->width == 0 || dpx->height == 0) {
|
||||
if (verbose) printf("DPX: Wrong image dimension: %dx%d\n", dpx->width, dpx->height);
|
||||
logImageClose(dpx);
|
||||
return 0;
|
||||
}
|
||||
|
||||
dpx->depth = 0;
|
||||
|
||||
for (i = 0; i < dpx->numElements; i++) {
|
||||
@ -242,8 +255,23 @@ LogImageFile *dpxOpen(const unsigned char *byteStuff, int fromMemory, size_t buf
|
||||
}
|
||||
|
||||
dpx->element[i].bitsPerSample = header.imageHeader.element[i].bits_per_sample;
|
||||
if (dpx->element[i].bitsPerSample != 1 && dpx->element[i].bitsPerSample != 8 &&
|
||||
dpx->element[i].bitsPerSample != 10 && dpx->element[i].bitsPerSample != 12 &&
|
||||
dpx->element[i].bitsPerSample != 16)
|
||||
{
|
||||
if (verbose) printf("DPX: Unsupported bitsPerSample for elements %d: %d\n", i, dpx->element[i].bitsPerSample);
|
||||
logImageClose(dpx);
|
||||
return 0;
|
||||
}
|
||||
|
||||
dpx->element[i].maxValue = powf(2, dpx->element[i].bitsPerSample) - 1.0f;
|
||||
|
||||
dpx->element[i].packing = swap_ushort(header.imageHeader.element[i].packing, dpx->isMSB);
|
||||
if (dpx->element[i].packing > 2) {
|
||||
if (verbose) printf("DPX: Unsupported packing for element %d: %d\n", i, dpx->element[i].packing);
|
||||
logImageClose(dpx);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Sometimes, the offset is not set correctly in the header */
|
||||
dpx->element[i].dataOffset = swap_uint(header.imageHeader.element[i].data_offset, dpx->isMSB);
|
||||
@ -323,7 +351,6 @@ LogImageFile *dpxOpen(const unsigned char *byteStuff, int fromMemory, size_t buf
|
||||
(dpx->referenceWhite == DPX_UNDEFINED_R32 || dpx->referenceWhite <= dpx->referenceBlack || isnan(dpx->referenceWhite)) ||
|
||||
(dpx->gamma == DPX_UNDEFINED_R32 || dpx->gamma <= 0 || isnan(dpx->gamma)))
|
||||
{
|
||||
|
||||
dpx->referenceBlack = 95.0f / 1023.0f * dpx->element[0].maxValue;
|
||||
dpx->referenceWhite = 685.0f / 1023.0f * dpx->element[0].maxValue;
|
||||
dpx->gamma = 1.7f;
|
||||
|
Loading…
Reference in New Issue
Block a user