blob: 76dc66ca7cfed3f808436bdab152bbb713202899 [file] [log] [blame]
scroggo@google.com8dc8bc52013-08-07 19:16:05 +00001/*
2 * Copyright 2013 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#include "gm.h"
9#include "SkCanvas.h"
10#include "SkImageDecoder.h"
11#include "SkOSFile.h"
12
13namespace skiagm {
14
15/**
16 * Test copying an image from 8888 to 4444.
17 */
18class CopyTo4444GM : public GM {
19public:
20 CopyTo4444GM() {}
21
22protected:
23 virtual SkString onShortName() {
24 return SkString("copyTo4444");
25 }
26
27 virtual SkISize onISize() {
tfarinaf5393182014-06-09 23:59:03 -070028 return SkISize::Make(1024, 512);
scroggo@google.com8dc8bc52013-08-07 19:16:05 +000029 }
30
31 virtual void onDraw(SkCanvas* canvas) {
32 SkBitmap bm, bm4444;
tfarina880914c2014-06-09 12:05:34 -070033 SkString filename = SkOSPath::SkPathJoin(INHERITED::gResourcePath, "mandrill_512.png");
reedbfefc7c2014-06-12 17:40:00 -070034 if (!SkImageDecoder::DecodeFile(filename.c_str(), &bm, kN32_SkColorType,
scroggo@google.com8dc8bc52013-08-07 19:16:05 +000035 SkImageDecoder::kDecodePixels_Mode)) {
36 SkDebugf("Could not decode the file. Did you forget to set the "
37 "resourcePath?\n");
38 return;
39 }
40 canvas->drawBitmap(bm, 0, 0);
commit-bot@chromium.org8a2ad3c2014-02-23 03:59:35 +000041 SkAssertResult(bm.copyTo(&bm4444, kARGB_4444_SkColorType));
scroggo@google.com7bb36ab2013-08-07 19:39:56 +000042 canvas->drawBitmap(bm4444, SkIntToScalar(bm.width()), 0);
scroggo@google.com8dc8bc52013-08-07 19:16:05 +000043 }
44
45private:
46 typedef GM INHERITED;
47};
48
49//////////////////////////////////////////////////////////////////////////////
50
51static GM* MyFactory(void*) { return new CopyTo4444GM; }
52static GMRegistry reg(MyFactory);
53
54}