2013-08-07 19:16:05 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2013 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "gm/gm.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "include/core/SkBitmap.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkCanvas.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "include/core/SkColor.h"
|
|
|
|
#include "include/core/SkImageInfo.h"
|
|
|
|
#include "include/core/SkPixmap.h"
|
|
|
|
#include "include/core/SkScalar.h"
|
|
|
|
#include "include/core/SkSize.h"
|
|
|
|
#include "include/core/SkString.h"
|
|
|
|
#include "include/core/SkTypes.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "tools/Resources.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "tools/ToolUtils.h"
|
2013-08-07 19:16:05 +00:00
|
|
|
|
2019-07-18 15:51:19 +00:00
|
|
|
namespace {
|
2013-08-07 19:16:05 +00:00
|
|
|
/**
|
|
|
|
* Test copying an image from 8888 to 4444.
|
|
|
|
*/
|
2019-07-18 15:51:19 +00:00
|
|
|
class CopyTo4444GM : public skiagm::GM {
|
|
|
|
SkString onShortName() override { return SkString("copyTo4444"); }
|
2013-08-07 19:16:05 +00:00
|
|
|
|
2019-07-18 15:51:19 +00:00
|
|
|
SkISize onISize() override { return {360, 180}; }
|
2013-08-07 19:16:05 +00:00
|
|
|
|
2019-07-18 15:51:19 +00:00
|
|
|
DrawResult onDraw(SkCanvas* canvas, SkString* errorMsg) override {
|
2013-08-07 19:16:05 +00:00
|
|
|
SkBitmap bm, bm4444;
|
2017-12-08 15:21:31 +00:00
|
|
|
if (!GetResourceAsBitmap("images/dog.jpg", &bm)) {
|
2019-02-07 23:20:09 +00:00
|
|
|
*errorMsg = "Could not decode the file. Did you forget to set the resourcePath?";
|
|
|
|
return DrawResult::kFail;
|
2013-08-07 19:16:05 +00:00
|
|
|
}
|
|
|
|
canvas->drawBitmap(bm, 0, 0);
|
2017-05-26 15:40:25 +00:00
|
|
|
|
|
|
|
// This should dither or we will see artifacts in the background of the image.
|
2019-03-20 16:12:10 +00:00
|
|
|
SkAssertResult(ToolUtils::copy_to(&bm4444, kARGB_4444_SkColorType, bm));
|
2013-08-07 19:39:56 +00:00
|
|
|
canvas->drawBitmap(bm4444, SkIntToScalar(bm.width()), 0);
|
2019-02-07 23:20:09 +00:00
|
|
|
return DrawResult::kOk;
|
2013-08-07 19:16:05 +00:00
|
|
|
}
|
|
|
|
};
|
2019-07-18 15:51:19 +00:00
|
|
|
} // namespace
|
2013-08-07 19:16:05 +00:00
|
|
|
|
2019-01-23 15:22:01 +00:00
|
|
|
DEF_GM( return new CopyTo4444GM; )
|
2013-08-07 19:16:05 +00:00
|
|
|
|
2019-07-18 15:51:19 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
2018-02-21 13:14:26 +00:00
|
|
|
|
|
|
|
DEF_SIMPLE_GM(format4444, canvas, 64, 64) {
|
|
|
|
canvas->scale(16, 16);
|
|
|
|
SkBitmap bitmap;
|
|
|
|
SkImageInfo imageInfo = SkImageInfo::Make(1, 1, kARGB_4444_SkColorType, kPremul_SkAlphaType);
|
|
|
|
bitmap.allocPixels(imageInfo);
|
|
|
|
SkCanvas offscreen(bitmap);
|
|
|
|
offscreen.clear(SK_ColorRED);
|
|
|
|
canvas->drawBitmap(bitmap, 0, 0);
|
|
|
|
offscreen.clear(SK_ColorBLUE);
|
|
|
|
canvas->drawBitmap(bitmap, 1, 1);
|
|
|
|
auto pack4444 = [](unsigned a, unsigned r, unsigned g, unsigned b) -> uint16_t {
|
|
|
|
return (a << 0) | (b << 4) | (g << 8) | (r << 12);
|
|
|
|
};
|
|
|
|
uint16_t red4444 = pack4444(0xF, 0xF, 0x0, 0x0);
|
|
|
|
uint16_t blue4444 = pack4444(0xF, 0x0, 0x0, 0x0F);
|
|
|
|
SkPixmap redPixmap(imageInfo, &red4444, 2);
|
|
|
|
if (bitmap.writePixels(redPixmap, 0, 0)) {
|
|
|
|
canvas->drawBitmap(bitmap, 2, 2);
|
|
|
|
}
|
|
|
|
SkPixmap bluePixmap(imageInfo, &blue4444, 2);
|
|
|
|
if (bitmap.writePixels(bluePixmap, 0, 0)) {
|
|
|
|
canvas->drawBitmap(bitmap, 3, 3);
|
|
|
|
}
|
|
|
|
}
|