aboutsummaryrefslogtreecommitdiffhomepage
path: root/gm/copyTo4444.cpp
blob: 76dc66ca7cfed3f808436bdab152bbb713202899 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/*
 * Copyright 2013 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#include "gm.h"
#include "SkCanvas.h"
#include "SkImageDecoder.h"
#include "SkOSFile.h"

namespace skiagm {

/**
 *  Test copying an image from 8888 to 4444.
 */
class CopyTo4444GM : public GM {
public:
    CopyTo4444GM() {}

protected:
    virtual SkString onShortName() {
        return SkString("copyTo4444");
    }

    virtual SkISize onISize() {
        return SkISize::Make(1024, 512);
    }

    virtual void onDraw(SkCanvas* canvas) {
        SkBitmap bm, bm4444;
        SkString filename = SkOSPath::SkPathJoin(INHERITED::gResourcePath, "mandrill_512.png");
        if (!SkImageDecoder::DecodeFile(filename.c_str(), &bm, kN32_SkColorType,
                                        SkImageDecoder::kDecodePixels_Mode)) {
            SkDebugf("Could not decode the file. Did you forget to set the "
                     "resourcePath?\n");
            return;
        }
        canvas->drawBitmap(bm, 0, 0);
        SkAssertResult(bm.copyTo(&bm4444, kARGB_4444_SkColorType));
        canvas->drawBitmap(bm4444, SkIntToScalar(bm.width()), 0);
    }

private:
    typedef GM INHERITED;
};

//////////////////////////////////////////////////////////////////////////////

static GM* MyFactory(void*) { return new CopyTo4444GM; }
static GMRegistry reg(MyFactory);

}