blob: ed0c046fa969590cbdb167fdf21f541def609f06 [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");
scroggo@google.com8dc8bc52013-08-07 19:16:05 +000034 if (!SkImageDecoder::DecodeFile(filename.c_str(), &bm,
35 SkBitmap::kARGB_8888_Config,
36 SkImageDecoder::kDecodePixels_Mode)) {
37 SkDebugf("Could not decode the file. Did you forget to set the "
38 "resourcePath?\n");
39 return;
40 }
41 canvas->drawBitmap(bm, 0, 0);
commit-bot@chromium.org8a2ad3c2014-02-23 03:59:35 +000042 SkAssertResult(bm.copyTo(&bm4444, kARGB_4444_SkColorType));
scroggo@google.com7bb36ab2013-08-07 19:39:56 +000043 canvas->drawBitmap(bm4444, SkIntToScalar(bm.width()), 0);
scroggo@google.com8dc8bc52013-08-07 19:16:05 +000044 }
45
46private:
47 typedef GM INHERITED;
48};
49
50//////////////////////////////////////////////////////////////////////////////
51
52static GM* MyFactory(void*) { return new CopyTo4444GM; }
53static GMRegistry reg(MyFactory);
54
55}