2011-07-28 14:26:00 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2011 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
2014-06-13 00:40:00 +00:00
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkCanvas.h"
|
2019-07-04 01:34:41 +00:00
|
|
|
#include "include/core/SkFont.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkString.h"
|
|
|
|
#include "include/utils/SkTextUtils.h"
|
|
|
|
#include "samplecode/DecodeFile.h"
|
|
|
|
#include "samplecode/Sample.h"
|
2019-07-04 01:34:41 +00:00
|
|
|
#include "tools/Resources.h"
|
|
|
|
|
|
|
|
#include <vector>
|
2008-12-17 15:59:43 +00:00
|
|
|
|
|
|
|
static const char* gNames[] = {
|
2019-07-04 01:34:41 +00:00
|
|
|
"images/mandrill_512_q075.jpg",
|
|
|
|
"images/dog.jpg",
|
2008-12-17 15:59:43 +00:00
|
|
|
};
|
|
|
|
|
2019-07-04 01:34:41 +00:00
|
|
|
struct Filter2View : public Sample {
|
|
|
|
std::vector<SkBitmap> fBitmaps;
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2019-07-04 01:34:41 +00:00
|
|
|
void onOnceBeforeDraw() override {
|
|
|
|
SkASSERT(fBitmaps.empty());
|
|
|
|
fBitmaps.reserve(SK_ARRAY_COUNT(gNames) * 2);
|
|
|
|
for (const char* name : gNames) {
|
|
|
|
SkBitmap bitmap;
|
|
|
|
(void)decode_file(GetResourceAsData(name), &bitmap);
|
|
|
|
fBitmaps.push_back(std::move(bitmap));
|
2008-12-17 15:59:43 +00:00
|
|
|
}
|
2019-07-04 01:34:41 +00:00
|
|
|
for (const char* name : gNames) {
|
|
|
|
SkBitmap bitmap;
|
|
|
|
(void)decode_file(GetResourceAsData(name), &bitmap, kRGB_565_SkColorType);
|
|
|
|
fBitmaps.push_back(std::move(bitmap));
|
2008-12-17 15:59:43 +00:00
|
|
|
}
|
2011-05-05 14:03:48 +00:00
|
|
|
this->setBGColor(SK_ColorGRAY);
|
2008-12-17 15:59:43 +00:00
|
|
|
}
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2019-07-04 01:34:41 +00:00
|
|
|
SkString name() override { return SkString("Filter/Dither"); }
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2019-07-03 14:55:44 +00:00
|
|
|
void onDrawContent(SkCanvas* canvas) override {
|
2008-12-17 15:59:43 +00:00
|
|
|
canvas->translate(SkIntToScalar(10), SkIntToScalar(50));
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
const SkScalar W = SkIntToScalar(fBitmaps[0].width() + 1);
|
|
|
|
const SkScalar H = SkIntToScalar(fBitmaps[0].height() + 1);
|
|
|
|
SkPaint paint;
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2013-11-25 19:44:07 +00:00
|
|
|
const SkScalar scale = 0.897917f;
|
2008-12-17 15:59:43 +00:00
|
|
|
canvas->scale(SK_Scalar1, scale);
|
|
|
|
|
|
|
|
for (int k = 0; k < 2; k++) {
|
2015-03-16 17:08:34 +00:00
|
|
|
paint.setFilterQuality(k == 1 ? kLow_SkFilterQuality : kNone_SkFilterQuality);
|
2008-12-17 15:59:43 +00:00
|
|
|
for (int j = 0; j < 2; j++) {
|
|
|
|
paint.setDither(j == 1);
|
2019-07-04 01:34:41 +00:00
|
|
|
for (int i = 0; i < (int)fBitmaps.size(); i++) {
|
|
|
|
SkScalar x = (k * (int)fBitmaps.size() + j) * W;
|
2008-12-17 15:59:43 +00:00
|
|
|
SkScalar y = i * H;
|
2013-12-17 19:22:07 +00:00
|
|
|
x = SkScalarRoundToScalar(x);
|
|
|
|
y = SkScalarRoundToScalar(y);
|
2008-12-17 15:59:43 +00:00
|
|
|
canvas->drawBitmap(fBitmaps[i], x, y, &paint);
|
2019-01-03 20:45:53 +00:00
|
|
|
SkFont font;
|
|
|
|
font.setSize(SkIntToScalar(18));
|
2008-12-17 15:59:43 +00:00
|
|
|
if (i == 0) {
|
|
|
|
SkString s("dither=");
|
|
|
|
s.appendS32(paint.isDither());
|
|
|
|
s.append(" filter=");
|
2015-03-16 17:08:34 +00:00
|
|
|
s.appendS32(paint.getFilterQuality() != kNone_SkFilterQuality);
|
2019-01-03 20:45:53 +00:00
|
|
|
SkTextUtils::DrawString(canvas, s.c_str(), x + W/2, y - font.getSize(), font, SkPaint(),
|
2018-10-30 16:53:21 +00:00
|
|
|
SkTextUtils::kCenter_Align);
|
2008-12-17 15:59:43 +00:00
|
|
|
}
|
|
|
|
if (k+j == 2) {
|
|
|
|
SkString s;
|
|
|
|
s.append(" depth=");
|
2014-02-17 02:55:57 +00:00
|
|
|
s.appendS32(fBitmaps[i].colorType() == kRGB_565_SkColorType ? 16 : 32);
|
2019-01-03 20:45:53 +00:00
|
|
|
SkTextUtils::DrawString(canvas, s.c_str(), x + W + SkIntToScalar(4), y + H/2, font, SkPaint());
|
2008-12-17 15:59:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2018-08-08 15:36:17 +00:00
|
|
|
DEF_SAMPLE( return new Filter2View(); )
|