34 #include "dcmtk/config/osconfig.h"
35 #include "dcmtk/dcmimage/diqtpix.h"
36 #include "dcmtk/ofstd/ofcond.h"
42 #define DcmQuantFloydSteinbergScale 1024
73 register long sr = px.
getRed() +
thisrerr[col + 1] / DcmQuantFloydSteinbergScale;
74 register long sg = px.
getGreen() +
thisgerr[col + 1] / DcmQuantFloydSteinbergScale;
75 register long sb = px.
getBlue() +
thisberr[col + 1] / DcmQuantFloydSteinbergScale;
77 else if ( sr > OFstatic_cast(
long, maxval) ) sr = maxval;
79 else if ( sg > OFstatic_cast(
long, maxval) ) sg = maxval;
81 else if ( sb > OFstatic_cast(
long, maxval) ) sb = maxval;
82 px.
assign(OFstatic_cast(DcmQuantComponent, sr), OFstatic_cast(DcmQuantComponent, sg), OFstatic_cast(DcmQuantComponent, sb));
97 err = ( OFstatic_cast(
long, px.
getRed()) - OFstatic_cast(
long, mapped.
getRed()) ) * DcmQuantFloydSteinbergScale;
98 thisrerr[col + 2] += ( err * 7 ) / 16;
100 nextrerr[col + 1] += ( err * 5 ) / 16;
102 err = ( OFstatic_cast(
long, px.
getGreen()) - OFstatic_cast(
long, mapped.
getGreen()) ) * DcmQuantFloydSteinbergScale;
103 thisgerr[col + 2] += ( err * 7 ) / 16;
105 nextgerr[col + 1] += ( err * 5 ) / 16;
107 err = ( OFstatic_cast(
long, px.
getBlue()) - OFstatic_cast(
long, mapped.
getBlue()) ) * DcmQuantFloydSteinbergScale;
108 thisberr[col + 2] += ( err * 7 ) / 16;
110 nextberr[col + 1] += ( err * 5 ) / 16;
115 err = ( OFstatic_cast(
long, px.
getRed()) - OFstatic_cast(
long, mapped.
getRed()) ) * DcmQuantFloydSteinbergScale;
117 nextrerr[col + 2] += ( err * 3 ) / 16;
118 nextrerr[col + 1] += ( err * 5 ) / 16;
120 err = ( OFstatic_cast(
long, px.
getGreen()) - OFstatic_cast(
long, mapped.
getGreen()) ) * DcmQuantFloydSteinbergScale;
122 nextgerr[col + 2] += ( err * 3 ) / 16;
123 nextgerr[col + 1] += ( err * 5 ) / 16;
125 err = ( OFstatic_cast(
long, px.
getBlue()) - OFstatic_cast(
long, mapped.
getBlue()) ) * DcmQuantFloydSteinbergScale;
127 nextberr[col + 2] += ( err * 3 ) / 16;
128 nextberr[col + 1] += ( err * 5 ) / 16;
142 for (
unsigned long c = 0; c <
columns + 2; ++c)
void cleanup()
frees all memory allocated by the error vectors
void startRow(long &col, long &limitcol)
starts error diffusion for a new row.
unsigned long columns
number of columns in image
void propagate(const DcmQuantPixel &px, const DcmQuantPixel &mapped, long col)
propagates the Floyd-Steinberg error terms for one pixel.
objects of this class represent individual RGB pixels.
long * nextgerr
green error vector for next row. Points to an array of (columns + 2) entries.
long * nextberr
blue error vector for next row. Points to an array of (columns + 2) entries.
long * thisrerr
current red error vector. Points to an array of (columns + 2) entries.
~DcmQuantFloydSteinberg()
destructor
int fs_direction
boolean flag indicating in which direction (left to right/right to left) the FS distribution should b...
long * temperr
temporary pointer used for swapping error vectors
long * nextrerr
red error vector for next row. Points to an array of (columns + 2) entries.
DcmQuantComponent getBlue() const
returns the blue component
DcmQuantFloydSteinberg & operator=(const DcmQuantFloydSteinberg &src)
private undefined copy assignment operator
DcmQuantFloydSteinberg()
constructor
void assign(DcmQuantComponent r, DcmQuantComponent g, DcmQuantComponent b)
assigns new R, G and B values to this pixel
OFCondition initialize(unsigned long cols)
initializes the Floyd-Steinberg error vectors for an image with the given number of columns...
void adjust(DcmQuantPixel &px, long col, long maxval)
uses the Floyd-Steinberg error vectors to adjust the color of the current image pixel.
DcmQuantComponent getGreen() const
returns the green component
DcmQuantComponent getRed() const
returns the red component
void finishRow()
finishes error diffusion for one image row.
void nextCol(long &col) const
increases or decreases the column number depending on the direction flag.
this class implements Floyd-Steinberg error diffusion.
long * thisgerr
current green error vector. Points to an array of (columns + 2) entries.
long * thisberr
current blue error vector. Points to an array of (columns + 2) entries.
General purpose class for condition codes.