Revert of Remove uses of SkImageDecoder from gms (patchset #2 id:20001 of https://codereview.chromium.org/1791583002/ )

Reason for revert:
Suspected of causing assertion failures in unrelated tests on Windows.

Original issue's description:
> Remove uses of SkImageDecoder from gms
>
> BUG=skia:
> GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1791583002
>
> Committed: https://skia.googlesource.com/skia/+/d427266a58af7e6ea6c12c9cd56ade3e179a0c04

TBR=scroggo@google.com,reed@google.com,msarett@google.com
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=skia:

Review URL: https://codereview.chromium.org/1806383002
This commit is contained in:
bungeman 2016-03-17 10:38:36 -07:00 committed by Commit bot
parent c85ce7ce80
commit 003571887d
12 changed files with 155 additions and 26 deletions

View File

@ -10,8 +10,8 @@
#include "Resources.h"
#include "SkCanvas.h"
#include "SkData.h"
#include "SkImage.h"
#include "SkImageGenerator.h"
#include "SkImageDecoder.h"
#include "SkOSFile.h"
#include "SkTextureCompressor.h"

View File

@ -8,6 +8,7 @@
#include "gm.h"
#include "Resources.h"
#include "SkImageDecoder.h"
#include "SkAvoidXfermode.h"
#include "SkStream.h"
@ -23,7 +24,17 @@ protected:
SkISize onISize() override { return SkISize::Make(128, 128); }
void onOnceBeforeDraw() override {
if (!GetResourceAsBitmap("color_wheel.png", &fBM)) {
SkImageDecoder* codec = nullptr;
SkString resourcePath = GetResourcePath("color_wheel.png");
SkFILEStream stream(resourcePath.c_str());
if (stream.isValid()) {
codec = SkImageDecoder::Factory(&stream);
}
if (codec) {
stream.rewind();
codec->decode(&stream, &fBM, kN32_SkColorType, SkImageDecoder::kDecodePixels_Mode);
delete codec;
} else {
fBM.allocN32Pixels(1, 1);
fBM.eraseARGB(255, 255, 0 , 0); // red == bad
}

70
gm/cmykjpeg.cpp Normal file
View File

@ -0,0 +1,70 @@
/*
* Copyright 2012 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "gm.h"
#include "Resources.h"
#include "SkCanvas.h"
#include "SkImageDecoder.h"
#include "SkStream.h"
namespace skiagm {
/** Draw a CMYK encoded jpeg - libjpeg doesn't support CMYK->RGB
conversion so this tests Skia's internal processing
*/
class CMYKJpegGM : public GM {
public:
CMYKJpegGM() {}
protected:
void onOnceBeforeDraw() override {
// parameters to the "decode" call
bool dither = false;
SkString jpgFilename = GetResourcePath("CMYK.jpg");
SkFILEStream stream(jpgFilename.c_str());
if (!stream.isValid()) {
SkDebugf("Could not find CMYK.jpg, please set --resourcePath correctly.\n");
return;
}
SkImageDecoder* codec = SkImageDecoder::Factory(&stream);
if (codec) {
stream.rewind();
codec->setDitherImage(dither);
codec->decode(&stream, &fBitmap, kN32_SkColorType, SkImageDecoder::kDecodePixels_Mode);
delete codec;
}
}
virtual SkString onShortName() override {
return SkString("cmykjpeg");
}
virtual SkISize onISize() override {
return SkISize::Make(640, 480);
}
virtual void onDraw(SkCanvas* canvas) override {
canvas->translate(20*SK_Scalar1, 20*SK_Scalar1);
canvas->drawBitmap(fBitmap, 0, 0);
}
private:
SkBitmap fBitmap;
typedef GM INHERITED;
};
//////////////////////////////////////////////////////////////////////////////
static GM* MyFactory(void*) { return new CMYKJpegGM; }
static GMRegistry reg(MyFactory);
}

View File

@ -32,7 +32,9 @@ protected:
virtual void onDraw(SkCanvas* canvas) {
SkBitmap bm, bm4444;
if (!GetResourceAsBitmap("mandrill_512.png", &bm)) {
SkString pngFilename = GetResourcePath("mandrill_512.png");
if (!SkImageDecoder::DecodeFile(pngFilename.c_str(), &bm, kN32_SkColorType,
SkImageDecoder::kDecodePixels_Mode)) {
SkDebugf("Could not decode the file. Did you forget to set the "
"resourcePath?\n");
return;

View File

@ -10,6 +10,7 @@
#include "Resources.h"
#include "SkGradientShader.h"
#include "SkTypeface.h"
#include "SkImageDecoder.h"
#include "SkStream.h"
#include "SkPaint.h"
@ -170,11 +171,21 @@ class DownsampleBitmapImageGM: public DownsampleBitmapGM {
int fSize;
void make_bitmap() override {
if (!GetResourceAsBitmap(fFilename.c_str(), &fBM)) {
fBM.allocN32Pixels(1, 1);
fBM.eraseARGB(255, 255, 0 , 0); // red == bad
}
fSize = fBM.height();
SkImageDecoder* codec = nullptr;
SkString resourcePath = GetResourcePath(fFilename.c_str());
SkFILEStream stream(resourcePath.c_str());
if (stream.isValid()) {
codec = SkImageDecoder::Factory(&stream);
}
if (codec) {
stream.rewind();
codec->decode(&stream, &fBM, kN32_SkColorType, SkImageDecoder::kDecodePixels_Mode);
delete codec;
} else {
fBM.allocN32Pixels(1, 1);
*(fBM.getAddr32(0,0)) = 0xFF0000FF; // red == bad
}
fSize = fBM.height();
}
private:
typedef DownsampleBitmapGM INHERITED;

View File

@ -10,8 +10,8 @@
#include "Resources.h"
#include "SkCanvas.h"
#include "SkData.h"
#include "SkImage.h"
#include "SkImageGenerator.h"
#include "SkImageDecoder.h"
#include "SkOSFile.h"
#include "SkTemplates.h"

View File

@ -12,6 +12,7 @@
#include "SkData.h"
#include "SkDiscardableMemoryPool.h"
#include "SkDiscardablePixelRef.h"
#include "SkImageDecoder.h"
#include "SkImageGeneratorPriv.h"
#include "SkOSFile.h"
#include "SkStream.h"

View File

@ -9,6 +9,7 @@
#include "Resources.h"
#include "SkGradientShader.h"
#include "SkImageDecoder.h"
#include "SkStream.h"
#include "SkTypeface.h"
@ -195,17 +196,26 @@ protected:
}
void makeBitmap() override {
if (!GetResourceAsBitmap(fFilename.c_str(), &fBM)) {
fBM.allocN32Pixels(1, 1);
fBM.eraseARGB(255, 255, 0 , 0); // red == bad
}
fSize = fBM.height();
if (fConvertToG8) {
SkBitmap tmp;
fBM.copyTo(&tmp, kGray_8_SkColorType);
fBM = tmp;
}
SkImageDecoder* codec = nullptr;
SkString resourcePath = GetResourcePath(fFilename.c_str());
SkFILEStream stream(resourcePath.c_str());
if (stream.isValid()) {
codec = SkImageDecoder::Factory(&stream);
}
if (codec) {
stream.rewind();
codec->decode(&stream, &fBM, kN32_SkColorType, SkImageDecoder::kDecodePixels_Mode);
delete codec;
} else {
fBM.allocN32Pixels(1, 1);
*(fBM.getAddr32(0,0)) = 0xFF0000FF; // red == bad
}
fSize = fBM.height();
if (fConvertToG8) {
SkBitmap tmp;
fBM.copyTo(&tmp, kGray_8_SkColorType);
fBM = tmp;
}
}
private:
const bool fConvertToG8;

View File

@ -11,6 +11,7 @@
#include "SkBitmapProcState.h"
#include "SkBitmapScaler.h"
#include "SkGradientShader.h"
#include "SkImageDecoder.h"
#include "SkImageEncoder.h"
#include "SkStream.h"
#include "SkTypeface.h"
@ -98,11 +99,21 @@ protected:
}
void makeBitmap() {
if (!GetResourceAsBitmap(fFilename.c_str(), &fBM)) {
fBM.allocN32Pixels(1, 1);
fBM.eraseARGB(255, 255, 0 , 0); // red == bad
}
fSize = fBM.height();
SkImageDecoder* codec = nullptr;
SkString resourcePath = GetResourcePath(fFilename.c_str());
SkFILEStream stream(resourcePath.c_str());
if (stream.isValid()) {
codec = SkImageDecoder::Factory(&stream);
}
if (codec) {
stream.rewind();
codec->decode(&stream, &fBM, kN32_SkColorType, SkImageDecoder::kDecodePixels_Mode);
delete codec;
} else {
fBM.allocN32Pixels(1, 1);
*(fBM.getAddr32(0,0)) = 0xFF0000FF; // red == bad
}
fSize = fBM.height();
}
private:
typedef skiagm::GM INHERITED;

View File

@ -8,6 +8,7 @@
#include "gm.h"
#include "Resources.h"
#include "SkImageDecoder.h"
#include "SkPixelXorXfermode.h"
#include "SkStream.h"
@ -23,7 +24,17 @@ protected:
SkISize onISize() override { return SkISize::Make(512, 512); }
void onOnceBeforeDraw() override {
if (!GetResourceAsBitmap("mandrill_512.png", &fBM)) {
SkImageDecoder* codec = nullptr;
SkString resourcePath = GetResourcePath("mandrill_512.png");
SkFILEStream stream(resourcePath.c_str());
if (stream.isValid()) {
codec = SkImageDecoder::Factory(&stream);
}
if (codec) {
stream.rewind();
codec->decode(&stream, &fBM, kN32_SkColorType, SkImageDecoder::kDecodePixels_Mode);
delete codec;
} else {
fBM.allocN32Pixels(1, 1);
fBM.eraseARGB(255, 255, 0 , 0); // red == bad
}

View File

@ -11,6 +11,7 @@
#include "SkBitmapScaler.h"
#include "SkGradientShader.h"
#include "SkTypeface.h"
#include "SkImageDecoder.h"
#include "SkStream.h"
#include "SkPaint.h"
#include "SkMipMap.h"

View File

@ -9,6 +9,7 @@
#include "Resources.h"
#include "SkBitmap.h"
#include "SkImageDecoder.h"
#include "SkPaint.h"
#include "SkShader.h"
#include "SkStream.h"