Skia
2DGraphicsLibrary
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SkMask.h
1 
2 /*
3  * Copyright 2006 The Android Open Source Project
4  *
5  * Use of this source code is governed by a BSD-style license that can be
6  * found in the LICENSE file.
7  */
8 
9 
10 #ifndef SkMask_DEFINED
11 #define SkMask_DEFINED
12 
13 #include "SkRect.h"
14 
19 struct SkMask {
20  SkMask() : fImage(nullptr) {}
21 
22  enum Format {
28  };
29 
30  enum {
31  kCountMaskFormats = kLCD16_Format + 1
32  };
33 
34  uint8_t* fImage;
35  SkIRect fBounds;
36  uint32_t fRowBytes;
37  Format fFormat;
38 
41  bool isEmpty() const { return fBounds.isEmpty(); }
42 
47  size_t computeImageSize() const;
48 
53  size_t computeTotalImageSize() const;
54 
59  uint8_t* getAddr1(int x, int y) const {
60  SkASSERT(kBW_Format == fFormat);
61  SkASSERT(fBounds.contains(x, y));
62  SkASSERT(fImage != NULL);
63  return fImage + ((x - fBounds.fLeft) >> 3) + (y - fBounds.fTop) * fRowBytes;
64  }
65 
70  uint8_t* getAddr8(int x, int y) const {
71  SkASSERT(kA8_Format == fFormat);
72  SkASSERT(fBounds.contains(x, y));
73  SkASSERT(fImage != NULL);
74  return fImage + x - fBounds.fLeft + (y - fBounds.fTop) * fRowBytes;
75  }
76 
82  uint16_t* getAddrLCD16(int x, int y) const {
83  SkASSERT(kLCD16_Format == fFormat);
84  SkASSERT(fBounds.contains(x, y));
85  SkASSERT(fImage != NULL);
86  uint16_t* row = (uint16_t*)(fImage + (y - fBounds.fTop) * fRowBytes);
87  return row + (x - fBounds.fLeft);
88  }
89 
95  uint32_t* getAddr32(int x, int y) const {
96  SkASSERT(kARGB32_Format == fFormat);
97  SkASSERT(fBounds.contains(x, y));
98  SkASSERT(fImage != NULL);
99  uint32_t* row = (uint32_t*)(fImage + (y - fBounds.fTop) * fRowBytes);
100  return row + (x - fBounds.fLeft);
101  }
102 
115  void* getAddr(int x, int y) const;
116 
117  static uint8_t* AllocImage(size_t bytes);
118  static void FreeImage(void* image);
119 
120  enum CreateMode {
124  };
125 };
126 
128 
136 public:
137  SkAutoMaskFreeImage(uint8_t* maskImage) {
138  fImage = maskImage;
139  }
140 
142  SkMask::FreeImage(fImage);
143  }
144 
145 private:
146  uint8_t* fImage;
147 };
148 #define SkAutoMaskFreeImage(...) SK_REQUIRE_LOCAL_VAR(SkAutoMaskFreeImage)
149 
150 #endif
uint8_t * getAddr1(int x, int y) const
Returns the address of the byte that holds the specified bit.
Definition: SkMask.h:59
3 8bit per pixl planes: alpha, mul, add
Definition: SkMask.h:25
size_t computeImageSize() const
Return the byte size of the mask, assuming only 1 plane.
compute bounds, alloc image and render into it
Definition: SkMask.h:123
bool isEmpty() const
Returns true if the mask is empty: i.e.
Definition: SkMask.h:41
SkPMColor.
Definition: SkMask.h:26
CreateMode
Definition: SkMask.h:120
uint16_t * getAddrLCD16(int x, int y) const
Return the address of the specified 16bit mask.
Definition: SkMask.h:82
SkMask is used to describe alpha bitmaps, either 1bit, 8bit, or the 3-channel 3D format.
Definition: SkMask.h:19
Definition: SkMask.h:135
8bits per pixel mask (e.g. antialiasing)
Definition: SkMask.h:24
bool contains(int32_t x, int32_t y) const
Returns true if (x,y) is inside the rectangle and the rectangle is not empty.
Definition: SkRect.h:234
uint32_t * getAddr32(int x, int y) const
Return the address of the specified 32bit mask.
Definition: SkMask.h:95
bool isEmpty() const
Return true if the rectangle's width or height are <= 0.
Definition: SkRect.h:103
uint8_t * getAddr8(int x, int y) const
Returns the address of the specified byte.
Definition: SkMask.h:70
size_t computeTotalImageSize() const
Return the byte size of the mask, taking into account any extra planes (e.g.
render into preallocate mask
Definition: SkMask.h:122
void * getAddr(int x, int y) const
Returns the address of the specified pixel, computing the pixel-size at runtime based on the mask for...
Format
Definition: SkMask.h:22
565 alpha for r/g/b
Definition: SkMask.h:27
1bit per pixel mask (e.g. monochrome)
Definition: SkMask.h:23
compute bounds and return
Definition: SkMask.h:121
SkIRect holds four 32 bit integer coordinates for a rectangle.
Definition: SkRect.h:20