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

Unified Diff: src/images/SkImageDecoder_libbmp.cpp

Issue 1820503002: Delete SkImageDecoder (Closed) Base URL: https://skia.googlesource.com/skia.git@fix-animator
Patch Set: Include SkImage Created 4 years, 9 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
« no previous file with comments | « src/images/SkImageDecoder_ktx.cpp ('k') | src/images/SkImageDecoder_libgif.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/images/SkImageDecoder_libbmp.cpp
diff --git a/src/images/SkImageDecoder_libbmp.cpp b/src/images/SkImageDecoder_libbmp.cpp
deleted file mode 100644
index b9359bea7a1e169f8b770a0971c38337a0856bec..0000000000000000000000000000000000000000
--- a/src/images/SkImageDecoder_libbmp.cpp
+++ /dev/null
@@ -1,166 +0,0 @@
-
-/*
- * Copyright 2007 The Android Open Source Project
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-
-#include "bmpdecoderhelper.h"
-#include "SkColorPriv.h"
-#include "SkData.h"
-#include "SkImageDecoder.h"
-#include "SkScaledBitmapSampler.h"
-#include "SkStream.h"
-#include "SkStreamPriv.h"
-#include "SkTDArray.h"
-
-class SkBMPImageDecoder : public SkImageDecoder {
-public:
- SkBMPImageDecoder() {}
-
- Format getFormat() const override {
- return kBMP_Format;
- }
-
-protected:
- Result onDecode(SkStream* stream, SkBitmap* bm, Mode mode) override;
-
-private:
- typedef SkImageDecoder INHERITED;
-};
-
-///////////////////////////////////////////////////////////////////////////////
-DEFINE_DECODER_CREATOR(BMPImageDecoder);
-///////////////////////////////////////////////////////////////////////////////
-
-static bool is_bmp(SkStreamRewindable* stream) {
- static const char kBmpMagic[] = { 'B', 'M' };
-
-
- char buffer[sizeof(kBmpMagic)];
-
- return stream->read(buffer, sizeof(kBmpMagic)) == sizeof(kBmpMagic) &&
- !memcmp(buffer, kBmpMagic, sizeof(kBmpMagic));
-}
-
-static SkImageDecoder* sk_libbmp_dfactory(SkStreamRewindable* stream) {
- if (is_bmp(stream)) {
- return new SkBMPImageDecoder;
- }
- return nullptr;
-}
-
-static SkImageDecoder_DecodeReg gReg(sk_libbmp_dfactory);
-
-static SkImageDecoder::Format get_format_bmp(SkStreamRewindable* stream) {
- if (is_bmp(stream)) {
- return SkImageDecoder::kBMP_Format;
- }
- return SkImageDecoder::kUnknown_Format;
-}
-
-static SkImageDecoder_FormatReg gFormatReg(get_format_bmp);
-
-///////////////////////////////////////////////////////////////////////////////
-
-class SkBmpDecoderCallback : public image_codec::BmpDecoderCallback {
-public:
- // we don't copy the bitmap, just remember the pointer
- SkBmpDecoderCallback(bool justBounds) : fJustBounds(justBounds) {}
-
- // override from BmpDecoderCallback
- virtual uint8* SetSize(int width, int height) {
- fWidth = width;
- fHeight = height;
- if (fJustBounds) {
- return nullptr;
- }
-
- fRGB.setCount(width * height * 3); // 3 == r, g, b
- return fRGB.begin();
- }
-
- int width() const { return fWidth; }
- int height() const { return fHeight; }
- const uint8_t* rgb() const { return fRGB.begin(); }
-
-private:
- SkTDArray<uint8_t> fRGB;
- int fWidth;
- int fHeight;
- bool fJustBounds;
-};
-
-SkImageDecoder::Result SkBMPImageDecoder::onDecode(SkStream* stream, SkBitmap* bm, Mode mode) {
- // First read the entire stream, so that all of the data can be passed to
- // the BmpDecoderHelper.
-
- auto data = SkCopyStreamToData(stream);
- if (!data) {
- return kFailure;
- }
-
- // Byte length of all of the data.
- const size_t length = data->size();
- if (0 == length) {
- return kFailure;
- }
-
- const bool justBounds = SkImageDecoder::kDecodeBounds_Mode == mode;
- SkBmpDecoderCallback callback(justBounds);
-
- // Now decode the BMP into callback's rgb() array [r,g,b, r,g,b, ...]
- {
- image_codec::BmpDecoderHelper helper;
- const int max_pixels = 16383*16383; // max width*height
- if (!helper.DecodeImage((const char*) data->data(), length,
- max_pixels, &callback)) {
- return kFailure;
- }
- }
-
- // we don't need this anymore, so free it now (before we try to allocate
- // the bitmap's pixels) rather than waiting for its destructor
- data.reset(nullptr);
-
- int width = callback.width();
- int height = callback.height();
- SkColorType colorType = this->getPrefColorType(k32Bit_SrcDepth, false);
-
- // only accept prefConfig if it makes sense for us
- if (kARGB_4444_SkColorType != colorType && kRGB_565_SkColorType != colorType) {
- colorType = kN32_SkColorType;
- }
-
- SkScaledBitmapSampler sampler(width, height, getSampleSize());
-
- bm->setInfo(SkImageInfo::Make(sampler.scaledWidth(), sampler.scaledHeight(),
- colorType, kOpaque_SkAlphaType));
-
- if (justBounds) {
- return kSuccess;
- }
-
- if (!this->allocPixelRef(bm, nullptr)) {
- return kFailure;
- }
-
- SkAutoLockPixels alp(*bm);
-
- if (!sampler.begin(bm, SkScaledBitmapSampler::kRGB, *this)) {
- return kFailure;
- }
-
- const int srcRowBytes = width * 3;
- const int dstHeight = sampler.scaledHeight();
- const uint8_t* srcRow = callback.rgb();
-
- srcRow += sampler.srcY0() * srcRowBytes;
- for (int y = 0; y < dstHeight; y++) {
- sampler.next(srcRow);
- srcRow += sampler.srcDY() * srcRowBytes;
- }
- return kSuccess;
-}
« no previous file with comments | « src/images/SkImageDecoder_ktx.cpp ('k') | src/images/SkImageDecoder_libgif.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698