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