Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Speed up loading uncompressed bmp files #397

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
53116cb
Cache Images for faster parsing subsequent images (or frames in an an…
mlsomers Feb 22, 2020
783ff84
Remove #include <xlocbuf>
mlsomers Feb 22, 2020
0e4550b
Replaced <cuchar> with <uchar.h>
mlsomers Feb 22, 2020
b5ef870
Added #include <cstring>
mlsomers Feb 22, 2020
3989f81
Use pov_base::UCS2toSysString instead of own function.
mlsomers Feb 22, 2020
63eb73a
Destroy the Image from ImageUtil (resolve C4150: deletion of pointer …
mlsomers Feb 23, 2020
4196674
Replace __time64_t with long
mlsomers Feb 23, 2020
f312aa8
Instead of using a teaspoon (file->readByte()), read in a whole row a…
mlsomers Feb 23, 2020
133d88f
Set the image pointer to null and delete the wrapper, thus preventing…
mlsomers Feb 23, 2020
415f2c0
Point the image to null to prevent it from being deleted when the wra…
mlsomers Feb 23, 2020
7fb27ec
Revert "Point the image to null to prevent it from being deleted when…
mlsomers Feb 23, 2020
3e6586e
Revert "Replace __time64_t with long"
mlsomers Feb 23, 2020
0cb2cd9
Revert "Destroy the Image from ImageUtil (resolve C4150: deletion of …
mlsomers Feb 23, 2020
c5bf024
Revert "Use pov_base::UCS2toSysString instead of own function."
mlsomers Feb 23, 2020
b907697
Revert "Added #include <cstring>"
mlsomers Feb 23, 2020
957a032
Revert "Replaced <cuchar> with <uchar.h>"
mlsomers Feb 23, 2020
d00b1b5
Revert "Remove #include <xlocbuf>"
mlsomers Feb 23, 2020
bee9f79
Revert "Cache Images for faster parsing subsequent images (or frames …
mlsomers Feb 23, 2020
d691288
Only the Bitmap changes...
mlsomers Feb 23, 2020
367c973
commit because Git insists...
mlsomers Feb 23, 2020
243e2fb
No changes to imageutil.cpp
mlsomers Feb 23, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 44 additions & 12 deletions source/base/image/bmp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -667,24 +667,56 @@ Image *Read (IStream *file, const ImageReadOptions& options)
int pad = has_alpha ? 0 : (4 - ((file_width * 3) % 4)) & 0x03 ;
unsigned int a = 255 ; // value to use for files that don't have an alpha channel (full opacity)

for (int y = file_height - 1 ; y >= 0 ; y--)
const unsigned int pixelWidth = (has_alpha ? 4 : 3);
const unsigned int rowLength = file_width * pixelWidth;

unsigned char* rowBuffer = new unsigned char[rowLength];

if (has_alpha)
{
for (int x = 0 ; x < file_width ; x++)
for (int y = file_height - 1; y >= 0; y--)
{
unsigned int b = Read_Safe_Char (*file);
unsigned int g = Read_Safe_Char (*file);
unsigned int r = Read_Safe_Char (*file);
if (has_alpha)
a = Read_Safe_Char (*file);
SetEncodedRGBAValue (image, x, y, gamma, 255, r, g, b, a, premul);
file->read(rowBuffer, rowLength);
if (!file)
throw POV_EXCEPTION(kFileDataErr, "Error reading data from BMP image.");

int offset = rowLength - pixelWidth;

for (int x = file_width - 1; x >= 0; x--)
{
SetEncodedRGBAValue(image, x, y, gamma, 255, rowBuffer[offset + 2], rowBuffer[offset + 1], rowBuffer[offset], rowBuffer[offset + 3], premul);
offset -= pixelWidth;
}

if (pad && !Skip(file, pad))
throw POV_EXCEPTION(kFileDataErr, "Error reading data from BMP image.");
}
if (pad && !Skip (file, pad))
throw POV_EXCEPTION(kFileDataErr, "Error reading data from BMP image.") ;
}
}
else
{
for (int y = file_height - 1; y >= 0; y--)
{
file->read(rowBuffer, rowLength);
if (!file)
throw POV_EXCEPTION(kFileDataErr, "Error reading data from BMP image.");

int offset = rowLength - pixelWidth;

for (int x = file_width - 1; x >= 0; x--)
{
SetEncodedRGBValue(image, x, y, gamma, 255, rowBuffer[offset + 2], rowBuffer[offset + 1], rowBuffer[offset]);
offset -= pixelWidth;
}

return (image) ;
if (pad && !Skip(file, pad))
throw POV_EXCEPTION(kFileDataErr, "Error reading data from BMP image.");
}
}

delete[] rowBuffer;
}

return (image);
}

}
Expand Down