1/*
2 * Copyright 2014 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#ifndef SkReadPixelsRec_DEFINED
9#define SkReadPixelsRec_DEFINED
10
11#include "include/core/SkImageInfo.h"
12#include "include/core/SkPixmap.h"
13
14/**
15 * Helper class to package and trim the parameters passed to readPixels()
16 */
17struct SkReadPixelsRec {
18 SkReadPixelsRec(const SkImageInfo& info, void* pixels, size_t rowBytes, int x, int y)
19 : fPixels(pixels)
20 , fRowBytes(rowBytes)
21 , fInfo(info)
22 , fX(x)
23 , fY(y)
24 {}
25
26 SkReadPixelsRec(const SkPixmap& pm, int x, int y)
27 : fPixels(pm.writable_addr())
28 , fRowBytes(pm.rowBytes())
29 , fInfo(pm.info())
30 , fX(x)
31 , fY(y)
32 {}
33
34 void* fPixels;
35 size_t fRowBytes;
36 SkImageInfo fInfo;
37 int fX;
38 int fY;
39
40 /*
41 * On true, may have modified its fields (except fRowBytes) to make it a legal subset
42 * of the specified src width/height.
43 *
44 * On false, leaves self unchanged, but indicates that it does not overlap src, or
45 * is not valid (e.g. bad fInfo) for readPixels().
46 */
47 bool trim(int srcWidth, int srcHeight);
48};
49
50#endif
51