aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/codec/SkBmpCodec.cpp
diff options
context:
space:
mode:
authorGravatar Leon Scroggins III <scroggo@google.com>2017-06-01 14:06:35 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-06-02 13:14:57 +0000
commitec4400bfe34bbb90eaceaae168b2c6edf9aca4d9 (patch)
tree76121ee3f2c3beedb9927b8cb2dd4187cdb9d1e9 /src/codec/SkBmpCodec.cpp
parent48c9919335c7da6188c08a78552186760bd434ea (diff)
Avoid new for small arrays in SkBmpCodec
Use a buffer on the stack to avoid the cost of new/delete. Change-Id: I5c9208ec283e8345c34553343925097926274978 Reviewed-on: https://skia-review.googlesource.com/18402 Reviewed-by: Matt Sarett <msarett@google.com> Commit-Queue: Leon Scroggins <scroggo@google.com>
Diffstat (limited to 'src/codec/SkBmpCodec.cpp')
-rw-r--r--src/codec/SkBmpCodec.cpp27
1 files changed, 13 insertions, 14 deletions
diff --git a/src/codec/SkBmpCodec.cpp b/src/codec/SkBmpCodec.cpp
index 3d3782b4f5..3158e992d2 100644
--- a/src/codec/SkBmpCodec.cpp
+++ b/src/codec/SkBmpCodec.cpp
@@ -151,15 +151,15 @@ bool SkBmpCodec::ReadHeader(SkStream* stream, bool inIco, SkCodec** codecOut) {
// Bmps embedded in Icos skip the first Bmp header
if (!inIco) {
// Read the first header and the size of the second header
- std::unique_ptr<uint8_t[]> hBuffer(new uint8_t[kBmpHeaderBytesPlusFour]);
- if (stream->read(hBuffer.get(), kBmpHeaderBytesPlusFour) !=
+ uint8_t hBuffer[kBmpHeaderBytesPlusFour];
+ if (stream->read(hBuffer, kBmpHeaderBytesPlusFour) !=
kBmpHeaderBytesPlusFour) {
SkCodecPrintf("Error: unable to read first bitmap header.\n");
return false;
}
- totalBytes = get_int(hBuffer.get(), 2);
- offset = get_int(hBuffer.get(), 10);
+ totalBytes = get_int(hBuffer, 2);
+ offset = get_int(hBuffer, 10);
if (offset < kBmpHeaderBytes + kBmpOS2V1Bytes) {
SkCodecPrintf("Error: invalid starting location for pixel data\n");
return false;
@@ -168,7 +168,7 @@ bool SkBmpCodec::ReadHeader(SkStream* stream, bool inIco, SkCodec** codecOut) {
// The size of the second (info) header in bytes
// The size is the first field of the second header, so we have already
// read the first four infoBytes.
- infoBytes = get_int(hBuffer.get(), 14);
+ infoBytes = get_int(hBuffer, 14);
if (infoBytes < kBmpOS2V1Bytes) {
SkCodecPrintf("Error: invalid second header size.\n");
return false;
@@ -185,12 +185,12 @@ bool SkBmpCodec::ReadHeader(SkStream* stream, bool inIco, SkCodec** codecOut) {
offset = 0;
// Read the size of the second header
- std::unique_ptr<uint8_t[]> hBuffer(new uint8_t[4]);
- if (stream->read(hBuffer.get(), 4) != 4) {
+ uint8_t hBuffer[4];
+ if (stream->read(hBuffer, 4) != 4) {
SkCodecPrintf("Error: unable to read size of second bitmap header.\n");
return false;
}
- infoBytes = get_int(hBuffer.get(), 0);
+ infoBytes = get_int(hBuffer, 0);
if (infoBytes < kBmpOS2V1Bytes) {
SkCodecPrintf("Error: invalid second header size.\n");
return false;
@@ -332,16 +332,15 @@ bool SkBmpCodec::ReadHeader(SkStream* stream, bool inIco, SkCodec** codecOut) {
switch (headerType) {
case kInfoV1_BmpHeaderType: {
// The V1 header stores the bit masks after the header
- std::unique_ptr<uint8_t[]> mBuffer(new uint8_t[kBmpMaskBytes]);
- if (stream->read(mBuffer.get(), kBmpMaskBytes) !=
- kBmpMaskBytes) {
+ uint8_t buffer[kBmpMaskBytes];
+ if (stream->read(buffer, kBmpMaskBytes) != kBmpMaskBytes) {
SkCodecPrintf("Error: unable to read bit inputMasks.\n");
return false;
}
maskBytes = kBmpMaskBytes;
- inputMasks.red = get_int(mBuffer.get(), 0);
- inputMasks.green = get_int(mBuffer.get(), 4);
- inputMasks.blue = get_int(mBuffer.get(), 8);
+ inputMasks.red = get_int(buffer, 0);
+ inputMasks.green = get_int(buffer, 4);
+ inputMasks.blue = get_int(buffer, 8);
break;
}
case kInfoV2_BmpHeaderType: