Home | History | Annotate | Download | only in core
      1 /*
      2  * Copyright 2011 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 SkPixelInfo_DEFINED
      9 #define SkPixelInfo_DEFINED
     10 
     11 #include "SkImageInfo.h"
     12 
     13 class SkColorTable;
     14 
     15 struct SkPixelInfo {
     16     SkColorType fColorType;
     17     SkAlphaType fAlphaType;
     18     size_t      fRowBytes;
     19 
     20     static bool CopyPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes,
     21                            const SkImageInfo& srcInfo, const void* srcPixels, size_t srcRowBytes,
     22                            SkColorTable* srcCTable = nullptr);
     23 };
     24 
     25 struct SkDstPixelInfo : SkPixelInfo {
     26     void* fPixels;
     27 };
     28 
     29 struct SkSrcPixelInfo : SkPixelInfo {
     30     const void* fPixels;
     31 
     32     // Guaranteed to work even if src.fPixels and dst.fPixels are the same
     33     // (but not if they overlap partially)
     34     bool convertPixelsTo(SkDstPixelInfo* dst, int width, int height) const;
     35 };
     36 
     37 static inline void SkRectMemcpy(void* dst, size_t dstRB, const void* src, size_t srcRB,
     38                                 size_t bytesPerRow, int rowCount) {
     39     SkASSERT(bytesPerRow <= srcRB);
     40     SkASSERT(bytesPerRow <= dstRB);
     41     for (int i = 0; i < rowCount; ++i) {
     42         memcpy(dst, src, bytesPerRow);
     43         dst = (char*)dst + dstRB;
     44         src = (const char*)src + srcRB;
     45     }
     46 }
     47 
     48 #endif
     49