Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1508)

Unified Diff: Source/platform/image-decoders/bmp/BMPImageReader.cpp

Issue 1259083003: Do not consolidate data in BMPImageDecoder (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@SegmentedBuffer
Patch Set: Read exactly the amount needed in getConsecutiveData Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: Source/platform/image-decoders/bmp/BMPImageReader.cpp
diff --git a/Source/platform/image-decoders/bmp/BMPImageReader.cpp b/Source/platform/image-decoders/bmp/BMPImageReader.cpp
index 8cbd07bf04386c7ebe77a3d325aec33f459e93c1..da10c63b3b06a301866350d052aa888ce0b0b6b0 100644
--- a/Source/platform/image-decoders/bmp/BMPImageReader.cpp
+++ b/Source/platform/image-decoders/bmp/BMPImageReader.cpp
@@ -166,7 +166,9 @@ bool BMPImageReader::readInfoHeaderSize()
ASSERT(m_decodedOffset == m_headerOffset);
if ((m_decodedOffset > m_data->size()) || ((m_data->size() - m_decodedOffset) < 4))
return false;
- m_infoHeader.biSize = readUint32(0);
+
+ FastSharedBufferReader fastReader(m_data);
+ m_infoHeader.biSize = readUint32(&fastReader, 0);
// Don't increment m_decodedOffset here, it just makes the code in
// processInfoHeader() more confusing.
@@ -241,23 +243,25 @@ bool BMPImageReader::readInfoHeader()
m_infoHeader.biCompression = RGB;
m_infoHeader.biClrUsed = 0;
+ FastSharedBufferReader fastReader(m_data);
+
if (m_isOS21x) {
- m_infoHeader.biWidth = readUint16(4);
- m_infoHeader.biHeight = readUint16(6);
+ m_infoHeader.biWidth = readUint16(&fastReader, 4);
+ m_infoHeader.biHeight = readUint16(&fastReader, 6);
ASSERT(!m_isInICO); // ICO is a Windows format, not OS/2!
- m_infoHeader.biBitCount = readUint16(10);
+ m_infoHeader.biBitCount = readUint16(&fastReader, 10);
return true;
}
- m_infoHeader.biWidth = readUint32(4);
- m_infoHeader.biHeight = readUint32(8);
+ m_infoHeader.biWidth = readUint32(&fastReader, 4);
+ m_infoHeader.biHeight = readUint32(&fastReader, 8);
if (m_isInICO)
m_infoHeader.biHeight /= 2;
- m_infoHeader.biBitCount = readUint16(14);
+ m_infoHeader.biBitCount = readUint16(&fastReader, 14);
// Read compression type, if present.
if (m_infoHeader.biSize >= 20) {
- uint32_t biCompression = readUint32(16);
+ uint32_t biCompression = readUint32(&fastReader, 16);
// Detect OS/2 2.x-specific compression types.
if ((biCompression == 3) && (m_infoHeader.biBitCount == 1)) {
@@ -273,8 +277,9 @@ bool BMPImageReader::readInfoHeader()
}
// Read colors used, if present.
- if (m_infoHeader.biSize >= 36)
- m_infoHeader.biClrUsed = readUint32(32);
+ if (m_infoHeader.biSize >= 36) {
Peter Kasting 2015/08/31 19:53:42 Nit: No {}
scroggo_chromium 2015/09/01 22:50:30 Done.
+ m_infoHeader.biClrUsed = readUint32(&fastReader, 32);
+ }
// Windows V4+ can safely read the four bitmasks from 40-56 bytes in, so do
// that here. If the bit depth is less than 16, these values will be ignored
@@ -287,10 +292,10 @@ bool BMPImageReader::readInfoHeader()
// For non-Windows V4+, m_bitMasks[] et. al will be initialized later
// during processBitmasks().
if (isWindowsV4Plus()) {
- m_bitMasks[0] = readUint32(40);
- m_bitMasks[1] = readUint32(44);
- m_bitMasks[2] = readUint32(48);
- m_bitMasks[3] = readUint32(52);
+ m_bitMasks[0] = readUint32(&fastReader, 40);
+ m_bitMasks[1] = readUint32(&fastReader, 44);
+ m_bitMasks[2] = readUint32(&fastReader, 48);
+ m_bitMasks[3] = readUint32(&fastReader, 52);
}
// Detect top-down BMPs.
@@ -430,9 +435,11 @@ bool BMPImageReader::processBitmasks()
// Read bitmasks.
if ((m_data->size() - m_decodedOffset) < bitmasksSize)
return false;
- m_bitMasks[0] = readUint32(0);
- m_bitMasks[1] = readUint32(4);
- m_bitMasks[2] = readUint32(8);
+
+ FastSharedBufferReader fastReader(m_data);
+ m_bitMasks[0] = readUint32(&fastReader, 0);
+ m_bitMasks[1] = readUint32(&fastReader, 4);
+ m_bitMasks[2] = readUint32(&fastReader, 8);
m_decodedOffset += bitmasksSize;
}
@@ -542,9 +549,9 @@ bool BMPImageReader::processColorTable()
return false;
m_colorTable.resize(m_infoHeader.biClrUsed);
for (size_t i = 0; i < m_infoHeader.biClrUsed; ++i) {
- m_colorTable[i].rgbBlue = m_data->data()[m_decodedOffset++];
- m_colorTable[i].rgbGreen = m_data->data()[m_decodedOffset++];
- m_colorTable[i].rgbRed = m_data->data()[m_decodedOffset++];
+ m_colorTable[i].rgbBlue = getByte(m_decodedOffset++);
+ m_colorTable[i].rgbGreen = getByte(m_decodedOffset++);
+ m_colorTable[i].rgbRed = getByte(m_decodedOffset++);
// Skip padding byte (not present on OS/2 1.x).
if (!m_isOS21x)
++m_decodedOffset;
@@ -594,8 +601,8 @@ BMPImageReader::ProcessingResult BMPImageReader::processRLEData()
// For every entry except EOF, we'd better not have reached the end of
// the image.
- const uint8_t count = m_data->data()[m_decodedOffset];
- const uint8_t code = m_data->data()[m_decodedOffset + 1];
+ const uint8_t count = getByte(m_decodedOffset);
+ const uint8_t code = getByte(m_decodedOffset + 1);
if ((count || (code != 1)) && pastEndOfImage(0))
return Failure;
@@ -629,8 +636,8 @@ BMPImageReader::ProcessingResult BMPImageReader::processRLEData()
// Fail if this takes us past the end of the desired row or
// past the end of the image.
- const uint8_t dx = m_data->data()[m_decodedOffset + 2];
- const uint8_t dy = m_data->data()[m_decodedOffset + 3];
+ const uint8_t dx = getByte(m_decodedOffset + 2);
+ const uint8_t dy = getByte(m_decodedOffset + 3);
if (dx || dy)
m_buffer->setHasAlpha(true);
if (((m_coord.x() + dx) > m_parent->size().width()) || pastEndOfImage(dy))
@@ -670,7 +677,7 @@ BMPImageReader::ProcessingResult BMPImageReader::processRLEData()
return InsufficientData;
// One BGR triple that we copy |count| times.
- fillRGBA(endX, m_data->data()[m_decodedOffset + 3], m_data->data()[m_decodedOffset + 2], code, 0xff);
+ fillRGBA(endX, getByte(m_decodedOffset + 3), getByte(m_decodedOffset + 2), code, 0xff);
m_decodedOffset += 4;
} else {
// RLE8 has one color index that gets repeated; RLE4 has two
@@ -733,7 +740,7 @@ BMPImageReader::ProcessingResult BMPImageReader::processNonRLEData(bool inRLE, i
// the most significant bits in the byte).
const uint8_t mask = (1 << m_infoHeader.biBitCount) - 1;
for (size_t byte = 0; byte < unpaddedNumBytes; ++byte) {
- uint8_t pixelData = m_data->data()[m_decodedOffset + byte];
+ uint8_t pixelData = getByte(m_decodedOffset + byte);
for (size_t pixel = 0; (pixel < pixelsPerByte) && (m_coord.x() < endX); ++pixel) {
const size_t colorIndex = (pixelData >> (8 - m_infoHeader.biBitCount)) & mask;
if (m_decodingAndMask) {
@@ -758,9 +765,11 @@ BMPImageReader::ProcessingResult BMPImageReader::processNonRLEData(bool inRLE, i
}
}
} else {
+ FastSharedBufferReader fastReader(m_data);
+
// RGB data. Decode pixels one at a time, left to right.
while (m_coord.x() < endX) {
- const uint32_t pixel = readCurrentPixel(bytesPerPixel);
+ const uint32_t pixel = readCurrentPixel(&fastReader, bytesPerPixel);
// Some BMPs specify an alpha channel but don't actually use it
// (it contains all 0s). To avoid displaying these images as

Powered by Google App Engine
This is Rietveld 408576698