Home | History | Annotate | Download | only in docs
      1 #Topic Color4f
      2 #Alias Color4f_Reference ##
      3 
      4 #Struct SkPM4f
      5 ##
      6 
      7 #Struct SkRGBA4f
      8 
      9 #Code
     10 #Populate
     11 ##
     12 
     13 Each component is stored as a 32-bit single precision floating point float value.
     14 All values are allowed, but only the range from zero to one is meaningful.
     15 
     16 Components are independent of the others if defined with kUnpremul_SkAlphaType;
     17 fA Alpha is may be greater or smaller than fG green, fB blue, or fR red.
     18 SkColor4f is shorthand for Unpremultiplied SkRGBA4f.
     19 
     20 Components are connected if defined with kPremul_SkAlphaType; 
     21 fA Alpha is equal to or larger than fG green, fB blue, and fR red. The values
     22 stored in fG, fB, and fR combine the color component with the Alpha component.
     23 
     24 Values smaller than zero or larger than one are allowed. Values out of range
     25 may be used with Blend_Mode so that the final component is in range.
     26 
     27 #Member float  fR
     28 #Line # red component ##
     29 Single precision float for red ranges from no red (0.0) to full red (1.0).
     30 ##
     31 
     32 #Member float  fG
     33 #Line # green component ##
     34 Single precision float for green ranges from no green (0.0) to full green (1.0).
     35 ##
     36 
     37 #Member float  fB
     38 #Line # blue component ##
     39 Single precision float for blue ranges from no blue (0.0) to full blue (1.0).
     40 ##
     41 
     42 #Member float  fA
     43 #Line # alpha component ##
     44 Single precision float for Alpha ranges from no Alpha (0.0) to full Alpha (1.0).
     45 ##
     46 
     47 
     48 # ------------------------------------------------------------------------------
     49 
     50 #Method bool operator==(const SkRGBA4f& other) const
     51 #Line # compares SkRGBA4f for equality ##
     52 
     53 Compares SkRGBA4f with other, and returns true if all components are equivalent.
     54 
     55 #Param other  SkRGBA4f to compare ##
     56 
     57 #Return true if SkRGBA4f equals other ##
     58 
     59 #Example
     60     SkColor4f colorRed = { 1, 0, 0, 1 };
     61     SkColor4f colorNamedRed = SkColor4f::FromColor(SK_ColorRED);
     62     SkDebugf("colorRed %c= colorNamedRed", colorRed == colorNamedRed ? '=' : '!');
     63 #StdOut
     64 colorRed == colorNamedRed
     65 ##
     66 ##
     67 
     68 #SeeAlso operator!=(const SkRGBA4f& other) const
     69 
     70 #Method ##
     71 
     72 # ------------------------------------------------------------------------------
     73 
     74 #Method bool operator!=(const SkRGBA4f& other) const
     75 #Line # compares SkRGBA4f for inequality ##
     76 
     77 Compares SkRGBA4f with other, and returns true if all components are not
     78 equivalent.
     79 
     80 #Param other  SkRGBA4f to compare ##
     81 
     82 #Return true if SkRGBA4f is not equal to other ##
     83 
     84 #Example
     85     SkColor4f colorGray = { .5, .5, .5, 1 };
     86     SkColor4f colorNamedGray = SkColor4f::FromColor(SK_ColorGRAY);
     87     SkDebugf("colorGray %c= colorNamedGray ", colorGray != colorNamedGray ? '!' : '=');
     88 #StdOut
     89 colorGray != colorNamedGray
     90 ##
     91 ##
     92 
     93 #SeeAlso operator==(const SkRGBA4f& other) const
     94 
     95 #Method ##
     96 
     97 #Method SkRGBA4f operator*(float scale) const
     98 #Line # multiplies components by scale ##
     99 
    100 Multiplies each component by scale. Does not pin the result.
    101 
    102 #Param scale  component multiplier ##
    103 
    104 #Return scaled color ##
    105 
    106 #NoExample
    107 ##
    108 
    109 #SeeAlso SkBlendMode::kMultiply
    110 
    111 #Method ##
    112 
    113 #Method SkRGBA4f operator*(const SkRGBA4f& scale) const
    114 
    115 Multiplies each component by scale component. Does not pin the result.
    116 
    117 #Param scale  SkRGBA4f component multipliers ##
    118 
    119 #Return scaled color ##
    120 
    121 #NoExample
    122 ##
    123 
    124 #SeeAlso SkBlendMode::kMultiply
    125 
    126 #Method ##
    127 
    128 # ------------------------------------------------------------------------------
    129 
    130 #Subtopic Property_Functions
    131 #Line # member values ##
    132 #Subtopic Property_Functions ##
    133 
    134 #Method const float* vec() const
    135 #In Property_Functions
    136 #Line # returns array of components ##
    137 
    138 Returns SkRGBA4f components as a read-only array.
    139 
    140 #Return components as read-only array ##
    141 
    142 #Example
    143     SkColor4f color = SkColor4f::FromColor(0x884488CC);
    144     SkDebugf("red=%g green=%g blue=%g alpha=%g\n", color.fR, color.fG, color.fB, color.fA);
    145     const float* array = color.vec();
    146     SkDebugf("[0]=%g [1]=%g [2]=%g [3]=%g\n", array[0], array[1], array[2], array[3]);
    147 #StdOut
    148 red=0.266667 green=0.533333 blue=0.8 alpha=0.533333
    149 [0]=0.266667 [1]=0.533333 [2]=0.8 [3]=0.533333
    150 ##
    151 ##
    152 
    153 #SeeAlso SkColor4f
    154 
    155 #Method ##
    156 
    157 # ------------------------------------------------------------------------------
    158 
    159 #Method float* vec()
    160 #In Property_Functions
    161 #Line # returns array of components ##
    162 
    163 Returns SkRGBA4f components as a writable array.
    164 
    165 #Return components as writable array ##
    166 
    167 #Example
    168     SkColor4f color = SkColor4f::FromColor(0x884488CC);
    169     SkDebugf("red=%g green=%g blue=%g alpha=%g\n", color.fR, color.fG, color.fB, color.fA);
    170     float* array = color.vec();
    171     array[3] = 1;
    172     SkDebugf("[0]=%g [1]=%g [2]=%g [3]=%g\n", array[0], array[1], array[2], array[3]);
    173 #StdOut
    174 red=0.266667 green=0.533333 blue=0.8 alpha=0.533333
    175 [0]=0.266667 [1]=0.533333 [2]=0.8 [3]=1
    176 ##
    177 ##
    178 
    179 #SeeAlso SkColor4f
    180 
    181 #Method ##
    182 
    183 #Method float operator[](int index) const
    184 #Line # returns component by index ##
    185 
    186 Returns SkRGBA4f component by index, zero through three. index out of range
    187 triggers an assert in debug builds.
    188 
    189 #Param index component, zero through three ##
    190 #Return component by index ##
    191 
    192 #NoExample
    193 ##
    194 
    195 #SeeAlso vec
    196 
    197 #Method ##
    198 
    199 #Method float& operator[](int index)
    200 #Line # returns writable component reference ##
    201   
    202 Returns writable component reference by index, zero through three. index out of range
    203 triggers an assert in debug builds.
    204 
    205 #Param index component, zero through three ##
    206 #Return writable component reference by index ##
    207 
    208 #NoExample
    209 ##
    210 
    211 #SeeAlso vec
    212 
    213 #Method ##
    214 
    215 # ------------------------------------------------------------------------------
    216 
    217 #Subtopic Utility_Functions
    218 #Line # less common functions ##
    219 #Subtopic Utility_Functions ##
    220 
    221 #Method bool isOpaque() const
    222 #In Utility_Functions
    223 #Line # returns if Alpha component is at maximum ##
    224 
    225 Returns true if Alpha component is one. Color has no transparency regardless of
    226 whether color is Premultiplied or Unpremultiplied. Triggers a debugging assert
    227 if Alpha not valid.
    228 
    229 #Return true if Alpha is one ##
    230 
    231 #NoExample
    232 ##
    233 
    234 #SeeAlso vec SkColorGetA
    235 
    236 ##
    237 
    238 # ------------------------------------------------------------------------------
    239 
    240 #Method bool fitsInBytes() const
    241 #In Utility_Functions
    242 #Line # returns if r,g,b are all in [0..1] ##
    243 
    244 Returns true if the Red, Green, and Blue component are all in [0..1].
    245 Asserts the Alpha is [0..1]
    246 
    247 #Return true Red, Green, and Blue component are all in [0..1] ##
    248 
    249 #NoExample
    250 ##
    251 
    252 ##
    253 
    254 # ------------------------------------------------------------------------------
    255 
    256 #Method static SkRGBA4f FromColor(SkColor color)
    257 #In Utility_Functions
    258 #Line # sets components from Color ##
    259 #Populate
    260 
    261 #Example
    262     uint8_t red = 77, green = 101, blue = 153, alpha = 43;
    263     SkColor argb = SkColorSetARGB(alpha, red, green, blue);
    264     SkColor4f color4f = SkColor4f::FromColor(argb);
    265     SkDebugf("red=%g green=%g blue=%g alpha=%g\n", color4f.fR, color4f.fG, color4f.fB, color4f.fA);
    266     SkColor fromColor4f = color4f.toSkColor();
    267     SkDebugf("red=%d green=%d blue=%d alpha=%d\n", SkColorGetR(fromColor4f),
    268              SkColorGetG(fromColor4f), SkColorGetB(fromColor4f), SkColorGetA(fromColor4f));
    269 #StdOut
    270 red=0.301961 green=0.396078 blue=0.6 alpha=0.168627
    271 red=77 green=101 blue=153 alpha=43
    272 ##
    273 ##
    274 
    275 #SeeAlso toSkColor
    276 
    277 #Method ##
    278 
    279 # ------------------------------------------------------------------------------
    280 
    281 #Method SkColor toSkColor() const
    282 #In Utility_Functions
    283 #Line # returns closest Color ##
    284 
    285 Converts to closest SkColor.
    286 
    287 #Return closest Color ##
    288 
    289 #Example
    290     float red = 0.07, green = 0.13, blue = 0.32, alpha = 0.17;
    291     SkColor4f color4f = { red, green, blue, alpha };
    292     SkColor argb = color4f.toSkColor();
    293     SkDebugf("red=%d green=%d blue=%d alpha=%d\n", SkColorGetR(argb),
    294              SkColorGetG(argb), SkColorGetB(argb), SkColorGetA(argb));
    295     SkColor4f fromSkColor = SkColor4f::FromColor(argb);
    296     SkDebugf("red=%g green=%g blue=%g alpha=%g\n", fromSkColor.fR, fromSkColor.fG,
    297                                                    fromSkColor.fB, fromSkColor.fA);
    298 #StdOut
    299 red=18 green=33 blue=82 alpha=43
    300 red=0.0705882 green=0.129412 blue=0.321569 alpha=0.168627
    301 ##
    302 ##
    303 
    304 #SeeAlso FromColor
    305 
    306 #Method ##
    307 
    308 # ------------------------------------------------------------------------------
    309 
    310 #Method static SkRGBA4f FromPMColor(SkPMColor)
    311 #In Utility_Functions
    312 #Line # converts from Premultiplied Color ##
    313 
    314 Converts from Premultiplied integer components to Unpremultiplied float
    315 components.
    316 
    317 #Param SkPMColor  Premultiplied color ##
    318 
    319 #Return Unpremultiplied color ##
    320 
    321 #NoExample
    322 ##
    323 
    324 #SeeAlso FromColor
    325 
    326 #Method ##
    327 
    328 # ------------------------------------------------------------------------------
    329 
    330 #Method SkRGBA4f<kPremul_SkAlphaType> premul() const
    331 #In Utility
    332 #Line # returns Premultiplied color ##
    333 
    334 Returns SkColor4f with all components premultiplied by Alpha.
    335 
    336 #Return Premultiplied color ##
    337 
    338 #NoExample
    339 ##
    340 
    341 #SeeAlso unpremul
    342 
    343 #Method ##
    344 
    345 #Method SkRGBA4f<kUnpremul_SkAlphaType> unpremul() const
    346 #In Utility
    347 #Line # returns Unpremultiplied color ##
    348 
    349 Returns SkRGBA4f with all components independent of Alpha.
    350 
    351 #Return Unpremultiplied color ##
    352 
    353 #NoExample
    354 ##
    355 
    356 #SeeAlso premul
    357 
    358 #Method ##
    359 
    360 #Method uint32_t toBytes_RGBA() const
    361 #In Utility
    362 #Line # returns kRGBA_8888_SkColorType color ##
    363 
    364 Produces bytes in RGBA order. Component values are not affected by color Alpha.
    365 
    366 #Return color ##
    367 
    368 #NoExample
    369 ##
    370 
    371 #Method ##
    372 
    373 #Method static SkRGBA4f FromBytes_RGBA(uint32_t color)
    374 #In Utility
    375 #Line # sets kRGBA_8888_SkColorType color ##
    376 
    377 Returns from color kRGBA_8888_SkColorType order. Component values are
    378 not affected by color Alpha.
    379 
    380 #Param color  Premultiplied or Unpremultiplied ##
    381 #Return color ##
    382 
    383 #NoExample
    384 ##
    385 
    386 #Method ##
    387 
    388 #Method SkRGBA4f makeOpaque() const
    389 #In Utility
    390 #Line # returns color without transparency ##
    391 
    392 Returns color with Alpha set to one.
    393 
    394 #Return color ##
    395 
    396 #NoExample
    397 ##
    398 
    399 #Method ##
    400 
    401 #Struct ##
    402 
    403 #Typedef SkRGBA4f SkColor4f
    404 #Line # defines Unpremultiplied Color using floats ##
    405 
    406 #Code
    407 using SkColor4f = SkRGBA4f<kUnpremul_SkAlphaType>;
    408 ##
    409 
    410 ##
    411 
    412 #Topic Color4f ##
    413