27 const std::uint16_t xResolution,
28 const std::uint16_t yResolution,
29 const std::string& pngOutFileName ) :
30 pFileName( pngOutFileName ),
37 xTranslationFactor( 0.0 ),
38 yTranslationFactor( 0.0 ),
48 this->translateAllPixels();
49 this->renderAllPixels();
51 this->deallocatePngImageSpace();
57 const std::uint8_t red,
58 const std::uint8_t green,
59 const std::uint8_t blue )
62 this->pxlLst.push_back( std::make_tuple(
82 this->pngRowPointers =
84 for( std::uint16_t i = 0; i < this->yRes; ++i )
85 this->pngRowPointers[i] =
86 new std::uint8_t[(3 * (this->xRes + 1))];
91 for( std::uint16_t i = 0; i < this->yRes; ++i )
92 delete[]( this->pngRowPointers[i] );
93 delete[]( this->pngRowPointers );
98 ::FILE* pngOutFile( fopen( this->pFileName.c_str(),
"wb" ) );
100 this->pngStructPtr = png_create_write_struct(
101 PNG_LIBPNG_VER_STRING, NULL, NULL, NULL );
103 this->pngInfoPtr = png_create_info_struct( this->pngStructPtr );
105 png_init_io( this->pngStructPtr, pngOutFile );
107 if ( setjmp( png_jmpbuf( this->pngStructPtr ) ) )
111 png_set_IHDR( this->pngStructPtr,
118 PNG_COMPRESSION_TYPE_BASE,
119 PNG_FILTER_TYPE_BASE );
121 png_write_info( this->pngStructPtr, this->pngInfoPtr );
123 if ( setjmp( png_jmpbuf( this->pngStructPtr ) ) )
127 png_write_image( this->pngStructPtr,
128 reinterpret_cast<png_byte**>( this->pngRowPointers ) );
130 if( setjmp(png_jmpbuf( this->pngStructPtr ) ) )
134 png_write_end( this->pngStructPtr, NULL );
136 fclose( pngOutFile );
142 const long double curX( std::get<0>(p) );
143 const long double curY( std::get<1>(p) );
144 if( this->xMin > curX )
146 if( this->xMax < curX )
148 if( this->yMin > curY )
150 if( this->yMax < curY )
157 this->pxlLst.begin(),
162 std::placeholders::_1 ) );
168 std::get<0>(p) = this->xTranslationFactor * (std::get<0>(p) - this->xMin);
169 std::get<1>(p) = this->yTranslationFactor * (std::get<1>(p) - this->yMin);
174 this->xTranslationFactor =
175 static_cast<long double>( this->xRes ) / (this->xMax - this->xMin);
176 this->yTranslationFactor =
177 static_cast<long double>( this->yRes ) / (this->yMax - this->yMin);
179 this->pxlLst.begin(),
184 std::placeholders::_1 ) );
189 const std::list<png::pngFactory::pixelType>::const_iterator
190 end( this->pxlLst.end() );
192 std::list<png::pngFactory::pixelType>::const_iterator i;
193 for( i = this->pxlLst.begin();
197 const int x( static_cast<int>( std::get<0>(*i) ) );
198 const int y( static_cast<int>( std::get<1>(*i) ) );
200 if( (x < this->xRes) && (y < this->yRes) &&
201 (x >= 0) && (y >= 0) )
204 pix( &(this->pngRowPointers[y][3*x]) );
205 *pix = std::get<2>(*i);
207 *pix = std::get<3>(*i);
209 *pix = std::get<4>(*i);
void translatePixel(png::pngFactory::pixelType &p) const
This method maps a single pixel from the user specified coordinate plane to pixel space...
std::tuple< long double, long double, std::uint8_t, std::uint8_t, std::uint8_t > pixelType
This type is used to define variables that hold single pixels.
~pngFactory()
The class destructor.
void renderAllPixels(void)
This method renders all pixels.
std::list< png::pngFactory::pixelType > pxlLst
This attribute holds all caller specified pixels.
void updateMinMax(const png::pngFactory::pixelType &p)
This method is called to update the minimums and maximums, as tracked by this instance.
void writePngFile(void)
This method writes the PNG image out to disk.
const std::uint16_t getXRes(void) const
This method returns to the caller the horizontal resolution of the image.
void translateAllPixels(void)
This method maps all pixels from the user specified coordinate plane to pixel space.
std::uint8_t * pngRowPtrType
This type is used to access rows in the PNG image.
void findMinMax(void)
This method is called to determine the minimums and maximums, as tracked by this instance.
void deallocatePngImageSpace(void)
This method deallocates the PNG image space.
void addPixel(const long double x, const long double y, const std::uint8_t red, const std::uint8_t green, const std::uint8_t blue)
This method is called to add a pixel to the PNG image.
const std::uint16_t getYRes(void) const
This method returns to the caller the vertical resolution of the image.
void allocatePngImageSpace(void)
This method allocates space from the heap to hold the PNG image.