aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/codec/SkBmpBaseCodec.cpp
diff options
context:
space:
mode:
authorGravatar Leon Scroggins III <scroggo@google.com>2017-06-01 13:42:28 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-06-05 15:09:40 +0000
commitd81fed9ce2b9c8f2f227cf74c2578b90aafbe196 (patch)
tree9068d9db4b13e46c99af764ca4d2e2ae567b0df9 /src/codec/SkBmpBaseCodec.cpp
parent98fae7001dd3e617d02825490d3a1f1f12e6c0ad (diff)
Replace BMP calls to new with calls to malloc
A BMP can have an arbitrarily large width. We typically read a row into a block of memory before swizzling it to the output. Rather than calling new to create that block of memory, which may crash when we run out of memory, call malloc, and return null if malloc fails. Add a common base class for Mask and Standard BMP codecs. This class handles allocating and freeing the buffer. Bug: b/37623797 Change-Id: I0510b76d688d030865faa481bb2fb1351dac2c97 Reviewed-on: https://skia-review.googlesource.com/18400 Reviewed-by: Matt Sarett <msarett@google.com> Commit-Queue: Leon Scroggins <scroggo@google.com>
Diffstat (limited to 'src/codec/SkBmpBaseCodec.cpp')
-rw-r--r--src/codec/SkBmpBaseCodec.cpp16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/codec/SkBmpBaseCodec.cpp b/src/codec/SkBmpBaseCodec.cpp
new file mode 100644
index 0000000000..0e744351f0
--- /dev/null
+++ b/src/codec/SkBmpBaseCodec.cpp
@@ -0,0 +1,16 @@
+/*
+ * Copyright 2017 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+#include "SkBmpBaseCodec.h"
+#include "../private/SkMalloc.h"
+
+SkBmpBaseCodec::~SkBmpBaseCodec() {}
+
+SkBmpBaseCodec::SkBmpBaseCodec(int width, int height, const SkEncodedInfo& info, SkStream* stream,
+ uint16_t bitsPerPixel, SkCodec::SkScanlineOrder rowOrder)
+ : INHERITED(width, height, info, stream, bitsPerPixel, rowOrder)
+ , fSrcBuffer(sk_malloc_flags(this->srcRowBytes(), 0))
+{}