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

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

Issue 1259083003: Do not consolidate data in BMPImageDecoder (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@SegmentedBuffer
Patch Set: Do not use a raw pointer Created 5 years, 3 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.h
diff --git a/Source/platform/image-decoders/bmp/BMPImageReader.h b/Source/platform/image-decoders/bmp/BMPImageReader.h
index 83d70caf4a5bc5cbc5559ae760cc74958289e1f1..54960edd7a50ea11dce507e9beaafe275931580e 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,23 @@ private:
uint8_t rgbRed;
};
- inline uint16_t readUint16(int offset) const
+ inline uint8_t readUint8(size_t offset)
+ {
+ return m_fastReader.getOneByte(m_decodedOffset + offset);
+ }
+
+ inline uint16_t readUint16(int offset)
{
- 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,27 +200,26 @@ 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);
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
- // won't read it.
+ // of the return value, the caller won't read it.
uint32_t pixel;
- memcpy(&pixel, &m_data->data()[m_decodedOffset + offset], 3);
- #if CPU(BIG_ENDIAN)
- pixel = ((pixel & 0xff00) << 8) | ((pixel & 0xff0000) >> 8) | ((pixel & 0xff000000) >> 24);
- #endif
+ memcpy(&pixel, encodedPixel, 3);
return pixel;
}
case 4:
- return readUint32(offset);
+ return readUint32(encodedPixel);
default:
ASSERT_NOT_REACHED();
@@ -283,6 +286,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;
« no previous file with comments | « Source/platform/image-decoders/bmp/BMPImageDecoder.cpp ('k') | Source/platform/image-decoders/bmp/BMPImageReader.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698