Index: Source/platform/image-decoders/bmp/BMPImageReader.h |
diff --git a/Source/platform/image-decoders/bmp/BMPImageReader.h b/Source/platform/image-decoders/bmp/BMPImageReader.h |
index 83d70caf4a5bc5cbc5559ae760cc74958289e1f1..78b0cbc4365f764aabb2065829bd2bcea2de1797 100644 |
--- a/Source/platform/image-decoders/bmp/BMPImageReader.h |
+++ b/Source/platform/image-decoders/bmp/BMPImageReader.h |
@@ -31,9 +31,10 @@ |
#ifndef BMPImageReader_h |
#define BMPImageReader_h |
-#include <stdint.h> |
+#include "platform/image-decoders/FastSharedBufferReader.h" |
#include "platform/image-decoders/ImageDecoder.h" |
#include "wtf/CPU.h" |
+#include <stdint.h> |
namespace blink { |
@@ -42,26 +43,16 @@ namespace blink { |
class PLATFORM_EXPORT BMPImageReader { |
WTF_MAKE_FAST_ALLOCATED(BMPImageReader); |
public: |
- // Read a value from |data[offset]|, converting from little to native |
- // endianness. |
- static inline uint16_t readUint16(SharedBuffer* data, int offset) |
+ // Read a value from |buffer|, converting to an int assuming little |
+ // endianness |
+ static inline uint16_t readUint16(const char* buffer) |
{ |
- uint16_t result; |
- memcpy(&result, &data->data()[offset], 2); |
- #if CPU(BIG_ENDIAN) |
- result = ((result & 0xff) << 8) | ((result & 0xff00) >> 8); |
- #endif |
- return result; |
+ return *reinterpret_cast<const uint16_t*>(buffer); |
} |
- static inline uint32_t readUint32(SharedBuffer* data, int offset) |
+ static inline uint32_t readUint32(const char* buffer) |
{ |
- uint32_t result; |
- memcpy(&result, &data->data()[offset], 4); |
- #if CPU(BIG_ENDIAN) |
- result = ((result & 0xff) << 24) | ((result & 0xff00) << 8) | ((result & 0xff0000) >> 8) | ((result & 0xff000000) >> 24); |
- #endif |
- return result; |
+ return *reinterpret_cast<const uint32_t*>(buffer); |
} |
// |parent| is the decoder that owns us. |
@@ -71,7 +62,11 @@ public: |
BMPImageReader(ImageDecoder* parent, size_t decodedAndHeaderOffset, size_t imgDataOffset, bool isInICO); |
void setBuffer(ImageFrame* buffer) { m_buffer = buffer; } |
- void setData(SharedBuffer* data) { m_data = data; } |
+ void setData(SharedBuffer* data) |
+ { |
+ m_data = data; |
+ m_fastReader.setData(data); |
+ } |
// Does the actual decoding. If |onlySize| is true, decoding only |
// progresses as far as necessary to get the image size. Returns |
@@ -124,14 +119,18 @@ private: |
uint8_t rgbRed; |
}; |
- inline uint16_t readUint16(int offset) const |
+ inline uint16_t readUint16(int offset) |
scroggo_chromium
2015/09/01 22:50:30
Note that these are no longer const, since FastSha
Peter Kasting
2015/09/02 22:08:55
I wonder if FastSharedBufferReader's getters shoul
scroggo_chromium
2015/09/02 23:01:07
That is the way I would have written; I was surpri
|
{ |
- return readUint16(m_data.get(), m_decodedOffset + offset); |
+ char buffer[2]; |
+ const char* data = m_fastReader.getConsecutiveData(m_decodedOffset + offset, 2, buffer); |
+ return readUint16(data); |
} |
- inline uint32_t readUint32(int offset) const |
+ inline uint32_t readUint32(int offset) |
{ |
- return readUint32(m_data.get(), m_decodedOffset + offset); |
+ char buffer[4]; |
+ const char* data = m_fastReader.getConsecutiveData(m_decodedOffset + offset, 4, buffer); |
+ return readUint32(data); |
} |
// Determines the size of the BMP info header. Returns true if the size |
@@ -196,19 +195,22 @@ private: |
// row. |
// NOTE: Only as many bytes of the return value as are needed to hold |
// the pixel data will actually be set. |
- inline uint32_t readCurrentPixel(int bytesPerPixel) const |
+ inline uint32_t readCurrentPixel(int bytesPerPixel) |
{ |
+ // We need at most 4 bytes, starting at m_decodedOffset + offset. |
+ char buffer[4]; |
const int offset = m_coord.x() * bytesPerPixel; |
+ const char* encodedPixel = m_fastReader.getConsecutiveData(m_decodedOffset + offset, bytesPerPixel, buffer); |
Peter Kasting
2015/09/02 22:08:55
I'm not convinced this is right. If we're only as
scroggo_chromium
2015/09/02 23:01:07
Wait, what's the problem? I originally called getC
Peter Kasting
2015/09/02 23:48:44
Ah, my bad, I didn't read the code correctly.
I s
|
switch (bytesPerPixel) { |
case 2: |
- return readUint16(offset); |
+ return readUint16(encodedPixel); |
case 3: { |
// It doesn't matter that we never set the most significant byte |
// of the return value here in little-endian mode, the caller |
Peter Kasting
2015/09/02 22:08:55
Nit: Might as well remove "in little-endian mode"
scroggo_chromium
2015/09/02 23:01:07
Done.
|
// won't read it. |
uint32_t pixel; |
- memcpy(&pixel, &m_data->data()[m_decodedOffset + offset], 3); |
+ memcpy(&pixel, encodedPixel, 3); |
#if CPU(BIG_ENDIAN) |
pixel = ((pixel & 0xff00) << 8) | ((pixel & 0xff0000) >> 8) | ((pixel & 0xff000000) >> 24); |
#endif |
@@ -216,7 +218,7 @@ private: |
} |
case 4: |
- return readUint32(offset); |
+ return readUint32(encodedPixel); |
default: |
ASSERT_NOT_REACHED(); |
@@ -238,6 +240,15 @@ private: |
return m_bitMasks[3] ? getComponent(pixel, 3) : 0xff; |
} |
+ // Retrieve one byte from |m_data| at |offset| |
Peter Kasting
2015/09/02 22:08:55
Nit: Trailing period
scroggo_chromium
2015/09/02 23:01:07
Done.
|
+ uint8_t getByte(size_t offset) |
+ { |
+ const char* segment; |
Peter Kasting
2015/09/02 22:08:55
Why is this not just a call to m_fastReader.getOne
scroggo_chromium
2015/09/02 23:01:07
Wrote this function before I had a fastReader. Don
|
+ m_data->getSomeData(segment, offset); |
+ return segment[0]; |
+ } |
+ |
+ |
// Sets the current pixel to the color given by |colorIndex|. This also |
// increments the relevant local variables to move the current pixel |
// right by one. |
@@ -283,6 +294,7 @@ private: |
// The file to decode. |
RefPtr<SharedBuffer> m_data; |
+ FastSharedBufferReader m_fastReader; |
// An index into |m_data| representing how much we've already decoded. |
size_t m_decodedOffset; |