Prusa Slicer 2.6.0
Loading...
Searching...
No Matches
agg::gray16 Struct Reference

#include <src/agg/agg_color_gray.h>

Public Types

enum  base_scale_e { base_shift = 16 , base_scale = 1 << base_shift , base_mask = base_scale - 1 , base_MSB = 1 << (base_shift - 1) }
 
typedef int16u value_type
 
typedef int32u calc_type
 
typedef int64 long_type
 
typedef gray16 self_type
 

Public Member Functions

 gray16 ()
 
 gray16 (unsigned v_, unsigned a_=base_mask)
 
 gray16 (const self_type &c, unsigned a_)
 
 gray16 (const rgba &c)
 
 gray16 (const rgba8 &c)
 
 gray16 (const srgba8 &c)
 
 gray16 (const rgba16 &c)
 
 gray16 (const gray8 &c)
 
 gray16 (const sgray8 &c)
 
 operator rgba8 () const
 
 operator srgba8 () const
 
 operator rgba16 () const
 
 operator rgba32 () const
 
 operator gray8 () const
 
 operator sgray8 () const
 
AGG_INLINE bool is_transparent () const
 
AGG_INLINE bool is_opaque () const
 
self_typeclear ()
 
self_typetransparent ()
 
self_typeopacity (double a_)
 
double opacity () const
 
self_typepremultiply ()
 
self_typedemultiply ()
 
self_type gradient (self_type c, double k) const
 
AGG_INLINE void add (const self_type &c, unsigned cover)
 

Static Public Member Functions

static value_type luminance (const rgba &c)
 
static value_type luminance (const rgba16 &c)
 
static value_type luminance (const rgba8 &c)
 
static value_type luminance (const srgba8 &c)
 
static value_type luminance (const rgba32 &c)
 
static AGG_INLINE double to_double (value_type a)
 
static AGG_INLINE value_type from_double (double a)
 
static AGG_INLINE value_type empty_value ()
 
static AGG_INLINE value_type full_value ()
 
static AGG_INLINE value_type multiply (value_type a, value_type b)
 
static AGG_INLINE value_type demultiply (value_type a, value_type b)
 
template<typename T >
static AGG_INLINEdownscale (T a)
 
template<typename T >
static AGG_INLINEdownshift (T a, unsigned n)
 
static AGG_INLINE value_type mult_cover (value_type a, cover_type b)
 
static AGG_INLINE cover_type scale_cover (cover_type a, value_type b)
 
static AGG_INLINE value_type prelerp (value_type p, value_type q, value_type a)
 
static AGG_INLINE value_type lerp (value_type p, value_type q, value_type a)
 
static self_type no_color ()
 

Public Attributes

value_type v
 
value_type a
 

Detailed Description

Member Typedef Documentation

◆ calc_type

◆ long_type

◆ self_type

◆ value_type

Member Enumeration Documentation

◆ base_scale_e

Enumerator
base_shift 
base_scale 
base_mask 
base_MSB 
425 {
426 base_shift = 16,
427 base_scale = 1 << base_shift,
428 base_mask = base_scale - 1,
429 base_MSB = 1 << (base_shift - 1)
430 };
@ base_scale
Definition agg_color_gray.h:427
@ base_MSB
Definition agg_color_gray.h:429
@ base_mask
Definition agg_color_gray.h:428
@ base_shift
Definition agg_color_gray.h:426

Constructor & Destructor Documentation

◆ gray16() [1/9]

agg::gray16::gray16 ( )
inline
464{}

◆ gray16() [2/9]

agg::gray16::gray16 ( unsigned  v_,
unsigned  a_ = base_mask 
)
inlineexplicit
467 :
468 v(int16u(v_)), a(int16u(a_)) {}
AGG_INT16U int16u
Definition agg_basics.h:122
value_type v
Definition agg_color_gray.h:433
value_type a
Definition agg_color_gray.h:434

◆ gray16() [3/9]

agg::gray16::gray16 ( const self_type c,
unsigned  a_ 
)
inline
471 :
472 v(c.v), a(value_type(a_)) {}
int16u value_type
Definition agg_color_gray.h:421

◆ gray16() [4/9]

agg::gray16::gray16 ( const rgba c)
inline
475 :
476 v(luminance(c)),
477 a((value_type)uround(c.a * double(base_mask))) {}
AGG_INLINE int uround(double v)
Definition agg_basics.h:192
static value_type luminance(const rgba &c)
Definition agg_color_gray.h:436

◆ gray16() [5/9]

agg::gray16::gray16 ( const rgba8 c)
inline
480 :
481 v(luminance(c)),
482 a((value_type(c.a) << 8) | c.a) {}

◆ gray16() [6/9]

agg::gray16::gray16 ( const srgba8 c)
inline
485 :
486 v(luminance(c)),
487 a((value_type(c.a) << 8) | c.a) {}

◆ gray16() [7/9]

agg::gray16::gray16 ( const rgba16 c)
inline
490 :
491 v(luminance(c)),
492 a(c.a) {}

◆ gray16() [8/9]

agg::gray16::gray16 ( const gray8 c)
inline
495 :
496 v((value_type(c.v) << 8) | c.v),
497 a((value_type(c.a) << 8) | c.a) {}

◆ gray16() [9/9]

agg::gray16::gray16 ( const sgray8 c)
inline
500 :
501 v(sRGB_conv<value_type>::rgb_from_sRGB(c.v)),
502 a(sRGB_conv<value_type>::alpha_from_sRGB(c.a)) {}

Member Function Documentation

◆ add()

AGG_INLINE void agg::gray16::add ( const self_type c,
unsigned  cover 
)
inline
716 {
717 calc_type cv, ca;
718 if (cover == cover_mask)
719 {
720 if (c.a == base_mask)
721 {
722 *this = c;
723 return;
724 }
725 else
726 {
727 cv = v + c.v;
728 ca = a + c.a;
729 }
730 }
731 else
732 {
733 cv = v + mult_cover(c.v, cover);
734 ca = a + mult_cover(c.a, cover);
735 }
736 v = (value_type)((cv > calc_type(base_mask)) ? calc_type(base_mask) : cv);
737 a = (value_type)((ca > calc_type(base_mask)) ? calc_type(base_mask) : ca);
738 }
@ cover_mask
Definition agg_basics.h:242
static AGG_INLINE value_type mult_cover(value_type a, cover_type b)
Definition agg_color_gray.h:619
int32u calc_type
Definition agg_color_gray.h:422

References a, base_mask, agg::cover_mask, mult_cover(), and v.

+ Here is the call graph for this function:

◆ clear()

self_type & agg::gray16::clear ( )
inline
647 {
648 v = a = 0;
649 return *this;
650 }

References a, and v.

◆ demultiply() [1/2]

self_type & agg::gray16::demultiply ( )
inline
688 {
689 if (a < base_mask)
690 {
691 if (a == 0)
692 {
693 v = 0;
694 }
695 else
696 {
697 calc_type v_ = (calc_type(v) * base_mask) / a;
698 v = (v_ > base_mask) ? value_type(base_mask) : value_type(v_);
699 }
700 }
701 return *this;
702 }

References a, base_mask, and v.

◆ demultiply() [2/2]

static AGG_INLINE value_type agg::gray16::demultiply ( value_type  a,
value_type  b 
)
inlinestatic
590 {
591 if (a * b == 0)
592 {
593 return 0;
594 }
595 else if (a >= b)
596 {
597 return base_mask;
598 }
599 else return value_type((a * base_mask + (b >> 1)) / b);
600 }

References a, and base_mask.

◆ downscale()

template<typename T >
static AGG_INLINE T agg::gray16::downscale ( a)
inlinestatic
605 {
606 return a >> base_shift;
607 }

References a, and base_shift.

◆ downshift()

template<typename T >
static AGG_INLINE T agg::gray16::downshift ( a,
unsigned  n 
)
inlinestatic
612 {
613 return a >> n;
614 }

References a.

◆ empty_value()

static AGG_INLINE value_type agg::gray16::empty_value ( )
inlinestatic
558 {
559 return 0;
560 }

◆ from_double()

static AGG_INLINE value_type agg::gray16::from_double ( double  a)
inlinestatic
552 {
553 return value_type(uround(a * base_mask));
554 }

References a, base_mask, and agg::uround().

+ Here is the call graph for this function:

◆ full_value()

static AGG_INLINE value_type agg::gray16::full_value ( )
inlinestatic
564 {
565 return base_mask;
566 }

References base_mask.

◆ gradient()

self_type agg::gray16::gradient ( self_type  c,
double  k 
) const
inline
706 {
707 self_type ret;
708 calc_type ik = uround(k * base_scale);
709 ret.v = lerp(v, c.v, ik);
710 ret.a = lerp(a, c.a, ik);
711 return ret;
712 }
static AGG_INLINE value_type lerp(value_type p, value_type q, value_type a)
Definition agg_color_gray.h:639
gray16 self_type
Definition agg_color_gray.h:431

References a, base_scale, lerp(), agg::uround(), and v.

+ Here is the call graph for this function:

◆ is_opaque()

AGG_INLINE bool agg::gray16::is_opaque ( ) const
inline
576 {
577 return a == base_mask;
578 }

References a, and base_mask.

◆ is_transparent()

AGG_INLINE bool agg::gray16::is_transparent ( ) const
inline
570 {
571 return a == 0;
572 }

References a.

◆ lerp()

static AGG_INLINE value_type agg::gray16::lerp ( value_type  p,
value_type  q,
value_type  a 
)
inlinestatic
640 {
641 int t = (q - p) * a + base_MSB - (p > q);
642 return value_type(p + (((t >> base_shift) + t) >> base_shift));
643 }

References a, base_MSB, and base_shift.

Referenced by gradient().

+ Here is the caller graph for this function:

◆ luminance() [1/5]

static value_type agg::gray16::luminance ( const rgba c)
inlinestatic
437 {
438 // Calculate grayscale value as per ITU-R BT.709.
439 return value_type(uround((0.2126 * c.r + 0.7152 * c.g + 0.0722 * c.b) * base_mask));
440 }

References base_mask, and agg::uround().

Referenced by luminance(), luminance(), and luminance().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ luminance() [2/5]

static value_type agg::gray16::luminance ( const rgba16 c)
inlinestatic
443 {
444 // Calculate grayscale value as per ITU-R BT.709.
445 return value_type((13933u * c.r + 46872u * c.g + 4732u * c.b) >> 16);
446 }

◆ luminance() [3/5]

static value_type agg::gray16::luminance ( const rgba32 c)
inlinestatic
459 {
460 return luminance(rgba(c));
461 }

References luminance().

+ Here is the call graph for this function:

◆ luminance() [4/5]

static value_type agg::gray16::luminance ( const rgba8 c)
inlinestatic
449 {
450 return luminance(rgba16(c));
451 }

References luminance().

+ Here is the call graph for this function:

◆ luminance() [5/5]

static value_type agg::gray16::luminance ( const srgba8 c)
inlinestatic
454 {
455 return luminance(rgba16(c));
456 }

References luminance().

+ Here is the call graph for this function:

◆ mult_cover()

static AGG_INLINE value_type agg::gray16::mult_cover ( value_type  a,
cover_type  b 
)
inlinestatic
620 {
621 return multiply(a, b << 8 | b);
622 }
static AGG_INLINE value_type multiply(value_type a, value_type b)
Definition agg_color_gray.h:582

References a, and multiply().

Referenced by add(), and scale_cover().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ multiply()

static AGG_INLINE value_type agg::gray16::multiply ( value_type  a,
value_type  b 
)
inlinestatic
583 {
584 calc_type t = a * b + base_MSB;
585 return value_type(((t >> base_shift) + t) >> base_shift);
586 }

References a, base_MSB, and base_shift.

Referenced by mult_cover(), prelerp(), and premultiply().

+ Here is the caller graph for this function:

◆ no_color()

static self_type agg::gray16::no_color ( )
inlinestatic
741{ return self_type(0,0); }

◆ opacity() [1/2]

double agg::gray16::opacity ( ) const
inline
670 {
671 return double(a) / double(base_mask);
672 }

References a, and base_mask.

◆ opacity() [2/2]

self_type & agg::gray16::opacity ( double  a_)
inline
661 {
662 if (a_ < 0) a = 0;
663 else if(a_ > 1) a = 1;
664 else a = (value_type)uround(a_ * double(base_mask));
665 return *this;
666 }

References a, base_mask, and agg::uround().

+ Here is the call graph for this function:

◆ operator gray8()

agg::gray16::operator gray8 ( ) const
inline
532 {
533 return gray8(v >> 8, a >> 8);
534 }
gray8T< linear > gray8
Definition agg_color_gray.h:414

References a, and v.

◆ operator rgba16()

agg::gray16::operator rgba16 ( ) const
inline
519 {
520 return rgba16(v, v, v, a);
521 }

References a, and v.

◆ operator rgba32()

agg::gray16::operator rgba32 ( ) const
inline
525 {
526 rgba32::value_type v32 = v / 65535.0f;
527 return rgba32(v32, v32, v32, a / 65535.0f);
528 }
float value_type
Definition agg_color_rgba.h:1033

References a, and v.

◆ operator rgba8()

agg::gray16::operator rgba8 ( ) const
inline
506 {
507 return rgba8(v >> 8, v >> 8, v >> 8, a >> 8);
508 }
rgba8T< linear > rgba8
Definition agg_color_rgba.h:623

References a, and v.

◆ operator sgray8()

agg::gray16::operator sgray8 ( ) const
inline
538 {
539 return sgray8(
540 sRGB_conv<value_type>::rgb_to_sRGB(v),
541 sRGB_conv<value_type>::alpha_to_sRGB(a));
542 }
gray8T< sRGB > sgray8
Definition agg_color_gray.h:415

References a, and v.

◆ operator srgba8()

agg::gray16::operator srgba8 ( ) const
inline
512 {
513 value_type y = sRGB_conv<value_type>::rgb_to_sRGB(v);
514 return srgba8(y, y, y, sRGB_conv<value_type>::alpha_to_sRGB(a));
515 }
const Scalar & y
Definition MathFunctions.h:552
rgba8T< sRGB > srgba8
Definition agg_color_rgba.h:624

References a, and v.

◆ prelerp()

static AGG_INLINE value_type agg::gray16::prelerp ( value_type  p,
value_type  q,
value_type  a 
)
inlinestatic
633 {
634 return p + q - multiply(p, a);
635 }

References a, and multiply().

+ Here is the call graph for this function:

◆ premultiply()

self_type & agg::gray16::premultiply ( )
inline
677 {
678 if (a < base_mask)
679 {
680 if(a == 0) v = 0;
681 else v = multiply(v, a);
682 }
683 return *this;
684 }

References a, base_mask, multiply(), and v.

+ Here is the call graph for this function:

◆ scale_cover()

static AGG_INLINE cover_type agg::gray16::scale_cover ( cover_type  a,
value_type  b 
)
inlinestatic
626 {
627 return mult_cover(b, a) >> 8;
628 }

References a, and mult_cover().

+ Here is the call graph for this function:

◆ to_double()

static AGG_INLINE double agg::gray16::to_double ( value_type  a)
inlinestatic
546 {
547 return double(a) / base_mask;
548 }

References a, and base_mask.

◆ transparent()

self_type & agg::gray16::transparent ( )
inline
654 {
655 a = 0;
656 return *this;
657 }

References a.

Member Data Documentation

◆ a

◆ v


The documentation for this struct was generated from the following file: