blob: 4efe00b6dc88e866fbfd40333318c253650db656 [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() {
28 return make_isize(1024, 512);
29 }
30
31 virtual void onDraw(SkCanvas* canvas) {
32 SkBitmap bm, bm4444;
33 SkString filename = SkOSPath::SkPathJoin(
34 INHERITED::gResourcePath.c_str(), "mandrill_512.png");
35 if (!SkImageDecoder::DecodeFile(filename.c_str(), &bm,
36 SkBitmap::kARGB_8888_Config,
37 SkImageDecoder::kDecodePixels_Mode)) {
38 SkDebugf("Could not decode the file. Did you forget to set the "
39 "resourcePath?\n");
40 return;
41 }
42 canvas->drawBitmap(bm, 0, 0);
43 SkAssertResult(bm.copyTo(&bm4444, SkBitmap::kARGB_4444_Config));
scroggo@google.com7bb36ab2013-08-07 19:39:56 +000044 canvas->drawBitmap(bm4444, SkIntToScalar(bm.width()), 0);
scroggo@google.com8dc8bc52013-08-07 19:16:05 +000045 }
46
47private:
48 typedef GM INHERITED;
49};
50
51//////////////////////////////////////////////////////////////////////////////
52
53static GM* MyFactory(void*) { return new CopyTo4444GM; }
54static GMRegistry reg(MyFactory);
55
56}