blob: 6465d002124a1ec453deee621ed01159cbda3c1c [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"
tfarinabcbc1782014-06-18 14:32:48 -07009
10#include "Resources.h"
scroggo@google.com8dc8bc52013-08-07 19:16:05 +000011#include "SkCanvas.h"
12#include "SkImageDecoder.h"
13#include "SkOSFile.h"
14
15namespace skiagm {
16
17/**
18 * Test copying an image from 8888 to 4444.
19 */
20class CopyTo4444GM : public GM {
21public:
22 CopyTo4444GM() {}
23
24protected:
25 virtual SkString onShortName() {
26 return SkString("copyTo4444");
27 }
28
29 virtual SkISize onISize() {
tfarinaf5393182014-06-09 23:59:03 -070030 return SkISize::Make(1024, 512);
scroggo@google.com8dc8bc52013-08-07 19:16:05 +000031 }
32
33 virtual void onDraw(SkCanvas* canvas) {
34 SkBitmap bm, bm4444;
tfarinabcbc1782014-06-18 14:32:48 -070035 SkString resourcePath = GetResourcePath();
36 SkString filename = SkOSPath::SkPathJoin(resourcePath.c_str(), "mandrill_512.png");
reedbfefc7c2014-06-12 17:40:00 -070037 if (!SkImageDecoder::DecodeFile(filename.c_str(), &bm, kN32_SkColorType,
scroggo@google.com8dc8bc52013-08-07 19:16:05 +000038 SkImageDecoder::kDecodePixels_Mode)) {
39 SkDebugf("Could not decode the file. Did you forget to set the "
40 "resourcePath?\n");
41 return;
42 }
43 canvas->drawBitmap(bm, 0, 0);
commit-bot@chromium.org8a2ad3c2014-02-23 03:59:35 +000044 SkAssertResult(bm.copyTo(&bm4444, kARGB_4444_SkColorType));
scroggo@google.com7bb36ab2013-08-07 19:39:56 +000045 canvas->drawBitmap(bm4444, SkIntToScalar(bm.width()), 0);
scroggo@google.com8dc8bc52013-08-07 19:16:05 +000046 }
47
48private:
49 typedef GM INHERITED;
50};
51
52//////////////////////////////////////////////////////////////////////////////
53
54static GM* MyFactory(void*) { return new CopyTo4444GM; }
55static GMRegistry reg(MyFactory);
56
57}