aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/image/SkReadPixelsRec.h
blob: 6626ef26fcd6d9dee0815b7b2b6477901b1e81b3 (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
/*
 * Copyright 2014 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#ifndef SkReadPixelsRec_DEFINED
#define SkReadPixelsRec_DEFINED

#include "SkImageInfo.h"

/**
 *  Helper class to package and trim the parameters passed to readPixels()
 */
struct SkReadPixelsRec {
    SkReadPixelsRec(const SkImageInfo& info, void* pixels, size_t rowBytes, int x, int y)
        : fPixels(pixels)
        , fRowBytes(rowBytes)
        , fInfo(info)
        , fX(x)
        , fY(y)
    {}

    SkReadPixelsRec(const SkPixmap& pm, int x, int y)
        : fPixels(pm.writable_addr())
        , fRowBytes(pm.rowBytes())
        , fInfo(pm.info())
        , fX(x)
        , fY(y)
    {}

    void*       fPixels;
    size_t      fRowBytes;
    SkImageInfo fInfo;
    int         fX;
    int         fY;

    /*
     *  On true, may have modified its fields (except fRowBytes) to make it a legal subset
     *  of the specified src width/height.
     *
     *  On false, leaves self unchanged, but indicates that it does not overlap src, or
     *  is not valid (e.g. bad fInfo) for readPixels().
     */
    bool trim(int srcWidth, int srcHeight);
};

#endif