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

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: 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.h
diff --git a/Source/platform/image-decoders/bmp/BMPImageReader.h b/Source/platform/image-decoders/bmp/BMPImageReader.h
index 83d70caf4a5bc5cbc5559ae760cc74958289e1f1..ef309e62b83341d15fa6f45517cf4b7738e1f74e 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>
Peter Kasting 2015/08/31 19:53:42 Why was this header moved down? I think it should
scroggo_chromium 2015/09/01 22:50:30 The style guide disagrees (https://www.chromium.or
Peter Kasting 2015/09/02 22:08:54 It is SO DUMB that Blink has its own style guide t
namespace blink {
@@ -42,22 +43,22 @@ namespace blink {
class PLATFORM_EXPORT BMPImageReader {
WTF_MAKE_FAST_ALLOCATED(BMPImageReader);
public:
- // Read a value from |data[offset]|, converting from little to native
+ // Read a value from |buffer|, converting from little to native
// endianness.
Peter Kasting 2015/08/31 19:53:42 Do we actually compile on any big-endian targets?
scroggo_chromium 2015/09/01 22:50:30 According to [1], you are correct! From that same
- static inline uint16_t readUint16(SharedBuffer* data, int offset)
+ static inline uint16_t readUint16(const char* buffer)
{
uint16_t result;
- memcpy(&result, &data->data()[offset], 2);
+ memcpy(&result, buffer, 2);
#if CPU(BIG_ENDIAN)
result = ((result & 0xff) << 8) | ((result & 0xff00) >> 8);
#endif
return result;
}
- 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);
+ memcpy(&result, buffer, 4);
#if CPU(BIG_ENDIAN)
result = ((result & 0xff) << 24) | ((result & 0xff00) << 8) | ((result & 0xff0000) >> 8) | ((result & 0xff000000) >> 24);
#endif
@@ -124,14 +125,18 @@ private:
uint8_t rgbRed;
};
- inline uint16_t readUint16(int offset) const
+ inline uint16_t readUint16(FastSharedBufferReader* reader, int offset) const
{
- return readUint16(m_data.get(), m_decodedOffset + offset);
+ char buffer[2];
+ const char* data = reader->getConsecutiveData(m_decodedOffset + offset, 2, buffer);
+ return readUint16(data);
}
- inline uint32_t readUint32(int offset) const
+ inline uint32_t readUint32(FastSharedBufferReader* reader, int offset) const
{
- return readUint32(m_data.get(), m_decodedOffset + offset);
+ char buffer[4];
+ const char* data = reader->getConsecutiveData(m_decodedOffset + offset, 4, buffer);
+ return readUint32(data);
}
// Determines the size of the BMP info header. Returns true if the size
@@ -196,19 +201,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(FastSharedBufferReader* fastReader, int bytesPerPixel) const
scroggo_chromium 2015/08/31 19:07:00 This seems like an odd API to me - initially I cre
Peter Kasting 2015/08/31 19:53:42 I think it would make sense to have a member FastS
scroggo_chromium 2015/09/01 22:50:30 I've made the FastSharedBufferReader to the BMPIma
{
+ // We need at most 4 bytes, starting at m_decodedOffset + offset.
+ char buffer[4];
const int offset = m_coord.x() * bytesPerPixel;
+ const char* encodedPixel = 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.
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 +224,7 @@ private:
}
case 4:
- return readUint32(offset);
+ return readUint32(encodedPixel);
default:
ASSERT_NOT_REACHED();
@@ -238,6 +246,19 @@ private:
return m_bitMasks[3] ? getComponent(pixel, 3) : 0xff;
}
+ // Retrieve one byte from |m_data| at |offset|
+ uint8_t getByte(size_t offset)
+ {
+ const char* segment;
+#if ENABLE(ASSERT)
+ unsigned bytes =
Peter Kasting 2015/08/31 19:53:42 If you really want this assert, I'd do this: #if
scroggo_chromium 2015/09/01 22:50:30 Removed.
+#endif
+ m_data->getSomeData(segment, offset);
scroggo_chromium 2015/08/31 19:07:00 I think there might be a tradeoff between speed an
Peter Kasting 2015/08/31 19:53:42 It does kind of bug me that we have a method like
+ ASSERT(bytes >= 1);
+ 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.

Powered by Google App Engine
This is Rietveld 408576698