OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimPngWriter.cpp
Go to the documentation of this file.
1 //----------------------------------------------------------------------------
2 //
3 // License: See top level LICENSE.txt file
4 //
5 // Author: David Burken
6 // Contributor: David A. Horner - http://dave.thehorners.com
7 //
8 // Description: OSSIM Portable Network Graphics (PNG) writer.
9 //
10 //----------------------------------------------------------------------------
11 // $Id: ossimPngWriter.cpp 22466 2013-10-24 18:23:51Z dburken $
12 
13 #include "ossimPngWriter.h"
16 #include <ossim/base/ossimTrace.h>
17 #include <ossim/base/ossimDpt.h>
18 #include <ossim/base/ossimEndian.h>
27 #include <zlib.h>
28 #include <cstdlib>
29 #include <ctime>
30 
32  "ossimPngWriter",
34 
35 static const char COMPRESSION_LEVEL_KW[] = "compression_level";
36 static const char ADD_ALPHA_CHANNEL_KW[] = "add_alpha_channel";
37 
38 //---
39 // For trace debugging (to enable at runtime do:
40 // your_app -T "ossimPngWriter:debug" your_app_args
41 //---
42 static ossimTrace traceDebug("ossimPngWriter:debug");
43 
44 //---
45 // For the "ident" program which will find all exanded $Id: ossimPngWriter.cpp 22466 2013-10-24 18:23:51Z dburken $ macros and print
46 // them.
47 //---
48 #if OSSIM_ID_ENABLED
49 static const char OSSIM_ID[] = "$Id: ossimPngWriter.cpp 22466 2013-10-24 18:23:51Z dburken $";
50 #endif
51 
54  theOutputStream(0),
55  theOwnsStreamFlag(false),
56  theCompressionLevel(Z_BEST_COMPRESSION),
57  theInterlaceSupport(PNG_INTERLACE_NONE),
58  theCompressionStratagy(Z_FILTERED),
59  thePngFilter(PNG_FILTER_NONE),
60  theGammaFlag(false),
61  theGamma(0.0),
62  theTimeFlag(true),
63  theAlphaChannelFlag(false),
64  theBackgroundFlag(false),
65  theBackgroundRed(0),
66  theBackgroundGreen(0),
67  theBackgroundBlue(0),
68  theBackgroundGray(0),
69  theTransparentFlag(false),
70  theTransparentRed(0),
71  theTransparentGreen(0),
72  theTransparentBlue(0),
73  theTransparentGray(0)
74 
75 {
76  if (traceDebug())
77  {
79  << "ossimPngWriter::ossimPngWriter entered" << std::endl;
80 #if OSSIM_ID_ENABLED
82  << "OSSIM_ID: "
83  << OSSIM_ID
84  << std::endl;
85 #endif
86  }
87 
88  // Since there is no internal geometry set the flag to write out one.
90 
91  theOutputImageType = "ossim_png";
92 }
93 
95 {
96  // This will flush stream and delete it if we own it.
97  close();
98 }
99 
101 {
102  return ossimString("ossim_png_writer");
103 }
104 
106 {
107  return ossimString("ossim png writer");
108 }
109 
111 {
112  return ossimString("ossimPngWriter");
113 }
114 
116 {
118  {
119  return false;
120  }
121 
122  //---
123  // Make sure we can open the file. Note only the master process is used for
124  // writing...
125  //---
127  {
128  if (!isOpen())
129  {
130  open();
131  }
132  }
133 
134  return writeStream();
135 }
136 
138 {
139  static const char MODULE[] = "ossimPngWriter::write";
140 
141  if (!theInputConnection) // Must have a sequencer...
142  {
143  if (traceDebug())
144  {
146  << MODULE << " DEBUG:\ntheInputConnection is NULL!" << endl;
147  }
148  return false;
149  }
150 
151  //---
152  // Make sure we have a stream. Note only the master process is used for
153  // writing...
154  //---
156  {
157  if (!theOutputStream)
158  {
160  << MODULE << " ERROR:"
161  << "\nNULL output stream!"
162  << "\nReturning from method." << std::endl;
163 
164  return false;
165  }
166  }
167 
168  // make sure we have a region of interest
170  {
173  }
174  else
175  {
177  }
178 
179  if(theAreaOfInterest.hasNans()) // Must have an area of interest...
180  {
181  if (traceDebug())
182  {
184  << MODULE << " ERROR: Area of interest has nans!"
185  << "Area of interest: "
187  << "\nReturning..." << endl;
188  }
189 
190  return false;
191  }
192 
193  // Get the number of bands. Must be one or three for this writer.
195  if (bands != 1 && bands != 3)
196  {
198  << MODULE << " Range Error:"
199  << "\nInvalid number of input bands! Must be one or three."
200  << "\nInput bands = " << bands
201  << "\nReturning from method." << endl;
202 
203  return false;
204  }
205 
206  //---
207  // PNG only supports unsigned 8 and 16 bit images, so scale if needed.
208  // Note: This needs to be done on all processes.
209  //---
211  if( ( (inputScalar != OSSIM_UINT8) &&
212  (inputScalar != OSSIM_UINT16) &&
213  (inputScalar != OSSIM_USHORT11) ) ||
214  ( (inputScalar != OSSIM_UINT8) && theScaleToEightBitFlag )
215  )
216  {
217  if (traceDebug())
218  {
220  << " WARNING:"
221  << "\nData is being scaled to 8 bit!"
222  << "\nOriginal scalar type: "
224  getEntryString(inputScalar).c_str()
225  << std::endl;
226  }
227 
228  //---
229  // Attach a scalar remapper to the end of the input chain. This will
230  // need to be unattached and deleted at the end of this.
231  //---
232  ossimImageSource* inputSource = new ossimScalarRemapper;
233  inputSource->connectMyInputTo(0, theInputConnection->getInput(0));
234  theInputConnection->connectMyInputTo(0, inputSource);
236  }
237 
239  setPercentComplete(0.0);
240 
242  {
244  bool swapFlag = doSwap(outputScalar);
245  ossim_int32 imageHeight
247  ossim_int32 imageWidth
251  ossim_int32 bytesPerPixel = ossim::scalarSizeInBytes(outputScalar);
252  ossim_int32 bytesPerRow = bands*imageWidth*bytesPerPixel;
253  ossim_int32 colorType = getColorType(bands);
254 
255  if ( bands == 1 )
256  {
258  }
259  else
260  if ( bands == 3 )
261  {
265  }
266 
267  if ( theAlphaChannelFlag == true )
268  {
269  bands += 1; // add in the alpha channel
270  bytesPerRow += imageWidth*bytesPerPixel;
271  }
272 
273  // Allocate a buffer (tile) to hold a row of bip-format tiles.
275  new ossimImageData(0,
276  outputScalar,
277  bands,
278  imageWidth,
279  tileHeight);
280  bipTile->initialize();
281 
282  //---
283  // Begin of png related stuff.
284  //---
285  png_structp pp = png_create_write_struct (PNG_LIBPNG_VER_STRING, 0, 0, 0);
286  png_infop info = png_create_info_struct (pp);
287 
288  if ( setjmp( png_jmpbuf(pp) ) )
289  {
291  << "Error writing image: " << theFilename.c_str()
292  << std::endl;
293  return false;
294  }
295 
296  //---
297  // Pass the static write and flush to libpng to allow us to use our
298  // stream instead of doing "png_init_io (pp, theOutputFilePtr);"
299  //---
300  png_set_write_fn( pp,
301  (png_voidp)theOutputStream,
302  (png_rw_ptr) &ossimPngWriter::pngWriteData,
303  (png_flush_ptr)&ossimPngWriter::pngFlush);
304 
305  // Set the compression level.
306  png_set_compression_level(pp, theCompressionLevel);
307 
308  //---
309  // Set the filtering.
310  // Note that palette images should usually not be filtered.
311  if (isLutEnabled())
312  {
313  png_set_filter(pp, PNG_FILTER_TYPE_BASE, PNG_FILTER_NONE);
314  png_set_compression_strategy(pp, Z_DEFAULT_STRATEGY);
315  }
316  else
317  {
318  // leave default filter selection alone
319  png_set_compression_strategy(pp, Z_FILTERED);
320  }
321 
322  if (traceDebug())
323  {
325  << MODULE << " DEBUG: "
326  << "\nInput scalar: "
328  getEntryString(inputScalar).c_str()
329  << "\nOutput scalar: "
331  getEntryString(outputScalar).c_str()
332  << "\nOutput Rect: " << theAreaOfInterest
333  << "\nSwap flag: " << swapFlag
334  << "\nbytesPerRow: " << bytesPerRow
335  << "\nimageWidth: " << imageWidth
336  << "\nimageHeight: " << imageHeight
337  << "\ngitDepth: " << getBitDepth(outputScalar)
338  << "\ngetColorType(bands): " << colorType
339  << endl;
340  }
341 
342  png_set_IHDR(pp,
343  info,
344  imageWidth,
345  imageHeight,
346  getBitDepth(outputScalar),
347  colorType,
349  PNG_COMPRESSION_TYPE_DEFAULT,
350  PNG_FILTER_TYPE_DEFAULT);
351 
352  // Set the palette png_set_PLTE() in writeOptionalChunks()
353  writeOptionalChunks(pp, info);
354 
355  png_write_info(pp, info);
356 
357  // png_set_packing(pp);
358 
359  // Write the image.
360  if(theInterlaceSupport) // interlaced...
361  {
362  // Requires reading whole image into memory...
364  << "Interlace support not implemented yet!"
365  << std::endl;
366  return false;
367  }
368  else // not interlaced...
369  {
373 
374  //---
375  // Loop through and grab a row of tiles and copy to the buffer.
376  // Then write the buffer to the png file.
377  // Get the next row of tiles ... until finished.
378  //---
379 
380  // Row loop, in line direction...
381  for (ossim_uint32 i=0; ( (i<maxY) && (!needsAborting()) ); ++i)
382  {
383  ossimIrect buf_rect = theAreaOfInterest;
384  buf_rect.set_uly(theAreaOfInterest.ul().y+i*tileHeight);
385  buf_rect.set_lry(buf_rect.ul().y + tileHeight - 1);
386 
387  bipTile->setImageRectangle(buf_rect);
388  void* bipBuf = bipTile->getBuf();
389 
390 
391  // Grab lines of data that span the entire width of the image.
393  if ( t.valid() )
394  {
395  if ( theAlphaChannelFlag )
396  {
397  t->computeAlphaChannel();
398  t->unloadTileToBipAlpha(bipBuf, buf_rect, buf_rect);
399  }
400  else
401  {
402  t->unloadTile( bipBuf, buf_rect, buf_rect, OSSIM_BIP);
403  }
404 
405  // Copy the buffer to the png file.
406  ossim_int32 lines_to_copy =
407  min( (buf_rect.lr().y-buf_rect.ul().y+1),
408  (theAreaOfInterest.lr().y-buf_rect.ul().y+1) );
409 
410  if (traceDebug())
411  {
413  << MODULE
414  << "buf_rect: " << buf_rect
415  << "lines_to_copy: " << lines_to_copy << endl;
416  }
417 
418  if(!needsAborting())
419  {
420  if(swapFlag)
421  {
422  ossimEndian endian;
423  endian.swap((ossim_uint16*)bipBuf,
424  imageWidth*lines_to_copy*bands);
425  }
426 
427  ossim_uint8* buf = (ossim_uint8*)bipBuf;
428  ossim_int32 buf_offset = 0;
429  for (ossim_int32 line=0; line<lines_to_copy; ++line)
430  {
431  png_bytep rowp = (png_bytep)&buf[buf_offset];
432  png_write_row(pp, rowp);
433  buf_offset += bytesPerRow;
434  }
435 
436  } // if ( !getProcessStatus() )
437 
438  double dPercentComplete = (100.0*(i+1)) / maxY;
439  setPercentComplete( dPercentComplete );
440 
441  } // if ( t.valid() )
442 
443  } // End of loop through tiles in the y direction.
444 
445  } // Not interlace write block.
446 
447  png_write_end(pp, 0);
448  png_destroy_write_struct(&pp, &info);
449 
450  close();
451 
452  } // End of if(theInputConnection->isMaster()) block.
453 
454  else // slave process
455  {
457  }
458 
459  if(needsAborting())
460  {
462  }
463  else
464  {
466  }
467 
468  return true;
469 }
470 
471 void ossimPngWriter::pngWriteData(png_structp png_ptr,
472  png_bytep data,
473  png_size_t length)
474 {
475  std::ostream* fp = (std::ostream*)png_get_io_ptr(png_ptr);
476 
477  fp->write((char*)data, length);
478 }
479 
480 void ossimPngWriter::pngFlush( png_structp png_ptr )
481 {
482  std::ostream* fp = (std::ostream*)png_get_io_ptr(png_ptr);
483  fp->flush();
484 }
485 
487  const char* prefix)const
488 {
489  kwl.add( prefix,
490  ADD_ALPHA_CHANNEL_KW,
492  true );
493 
494  return ossimImageFileWriter::saveState(kwl, prefix);
495 }
496 
498  const char* prefix)
499 {
500  const char* value;
501 
502  value = kwl.find(prefix, ADD_ALPHA_CHANNEL_KW);
503  if(value)
504  {
505  setAlphaChannelFlag( ossimString(value).toBool() );
506  }
507 
508  theOutputImageType = "png";
509 
510  return ossimImageFileWriter::loadState(kwl, prefix);
511 }
512 
514 {
515  if (theOutputStream)
516  {
517  return true;
518  }
519  return false;
520 }
521 
523 {
524  close();
525 
526  // Check for empty filenames.
527  if (theFilename.empty())
528  {
529  return false;
530  }
531 
532  // ossimOFStream* os = new ossimOFStream();
533  std::ofstream* os = new std::ofstream();
534  os->open(theFilename.c_str(), ios::out | ios::binary);
535  if(os->is_open())
536  {
537  theOutputStream = os;
538  theOwnsStreamFlag = true;
539  return true;
540  }
541  delete os;
542  os = 0;
543 
544  return false;
545 }
546 
548 {
549  if (theOutputStream)
550  {
551  theOutputStream->flush();
552 
553  if (theOwnsStreamFlag)
554  {
555  delete theOutputStream;
556  theOutputStream = 0;
557  theOwnsStreamFlag = false;
558  }
559  }
560 }
561 
562 void ossimPngWriter::getImageTypeList(std::vector<ossimString>& imageTypeList)const
563 {
564  imageTypeList.push_back(ossimString("ossim_png"));
565 }
566 
568 {
569  return ossimString("png");
570 }
571 
572 bool ossimPngWriter::hasImageType(const ossimString& imageType) const
573 {
574  if ( (imageType == "ossim_png") || (imageType == "image/png") )
575  {
576  return true;
577  }
578 
579  return false;
580 }
581 
583 {
584  if (!property)
585  {
586  return;
587  }
588 
589  if (property->getName() == COMPRESSION_LEVEL_KW)
590  {
591  setCompressionLevel(property->valueToString());
592  }
593  else
594  if (property->getName() == ADD_ALPHA_CHANNEL_KW)
595  {
596  setAlphaChannelFlag( property->valueToString().toBool() );
597  }
598  else
599  {
601  }
602 }
603 
605 {
606  if (name == COMPRESSION_LEVEL_KW)
607  {
608  ossimStringProperty* stringProp =
609  new ossimStringProperty(name,
611  false); // editable flag
612  stringProp->addConstraint(ossimString("z_no_compression"));
613  stringProp->addConstraint(ossimString("z_best_speed"));
614  stringProp->addConstraint(ossimString("z_best_compression"));
615  stringProp->addConstraint(ossimString("z_default_compression"));
616  return stringProp;
617  }
618  else if (name == ADD_ALPHA_CHANNEL_KW)
619  {
620  return new ossimBooleanProperty(ADD_ALPHA_CHANNEL_KW,
622  }
624 }
625 
626 void ossimPngWriter::getPropertyNames(std::vector<ossimString>& propertyNames)const
627 {
628  propertyNames.push_back(ossimString(COMPRESSION_LEVEL_KW));
629  propertyNames.push_back(ossimString(ADD_ALPHA_CHANNEL_KW));
631 }
632 
633 bool ossimPngWriter::doSwap(ossimScalarType outputScalar) const
634 {
635  bool result = false;
636  if (outputScalar != OSSIM_UINT8)
637  {
639  {
640  result = true;
641  }
642  }
643  return result;
644 }
645 
647 {
648  // Temp drb...
649  return false;
650 }
651 
652 void ossimPngWriter::writeOptionalChunks(png_structp pp, png_infop info)
653 {
654  //---
655  // NOTE:
656  // Per PNG spec
657  // Chunks with no explicit restrictions (``anywhere'') are nonetheless
658  // implicitly constrained to come after the PNG signature and IHDR
659  // chunk, before the IEND chunk, and not to fall between multiple
660  // IDAT chunks.
661  //---
662 
663  //---
664  // Write gamma chunk (gAMMA)
665  // Location: Before first IDAT and PLTE
666  // Multiple: no
667  //---
668  writeGammaChunk(pp, info);
669 
670  //---
671  // Write significant bits (sBIT)
672  // Location: before PLTE and first IDAT
673  // Multiple: no
674  //---
675  writeSignificantBits(pp, info);
676 
677  // Set the palette png_set_PLTE()
678 
679  //---
680  // Write transparent color chunk (tRNS)
681  // Location: After PLTE, before first IDAT.
682  // Multiple:
683  //---
684  writeTransparentColorChunk(pp, info);
685 
686  //---
687  // Write background color chunk (bKGD)
688  // Location: After PLTE, before first IDAT.
689  // Multiple: no
690  //---
691  writeBackgroundColorChunk(pp, info);
692 
693  //---
694  // Write time stamp chunk (tIME).
695  // Location: anywhere
696  // Multiple: no
697  //
698  //---
699  writeTimeStampChunk(pp, info);
700 
701  //---
702  // Write any text (tEXt, zTXt).
703  // Location: anywhere
704  // Multiple: yes
705  //---
706  writeLatinTextChunk(pp, info);
707 
708  //---
709  // Write any text (iTXt).
710  // Location: anywhere
711  // Multiple: yes
712  //---
713  writeInternationalTextChunk(pp, info);
714 
715  //---
716  // Write histogram (hIST)
717  // Location: after PLTE, before first IDAT
718  // Multiple: no
719  //---
720  writeHistogram(pp, info);
721 
722  //---
723  // Write suggested palette (sPLT)
724  // Location: before first IDAT
725  // Multiple: yes
726  //---
727  writeSuggestedPalette(pp, info);
728 
729  //---
730  // Write physical pixel dimensions (pHYs)
731  // Location: before first IDAT
732  // Multiple: no
733  //---
735 
736  //---
737  // Write physical scale (sCAL)
738  // Location: before first IDAT
739  // Multiple: no
740  //---
741  writePhysicalScale(pp, info);
742 
743  //---
744  // Write image offset (oFFs)
745  // Location: before first IDAT
746  // Multiple: no
747  //---
748  writeImageOffset(pp, info);
749 
750  //---
751  // Write pixel calibration (pCAL)
752  // Location: after PLTE, before first IDAT
753  // Multiple: no
754  //---
755  writePixelCalibration(pp, info);
756 
757  //---
758  // Write fractal parameters (fRAc)
759  // Location: anywhere
760  // Multiple: yes
761  //---
762  writeFractalParameters(pp, info);
763 }
764 
765 void ossimPngWriter::writeTransparentColorChunk(png_structp pp, png_infop info)
766 {
767  if (theTransparentFlag)
768  {
769  png_color_16 transparent;
770  transparent.red = (png_uint_16)theTransparentRed;
771  transparent.green = (png_uint_16)theTransparentGreen;
772  transparent.blue = (png_uint_16)theTransparentBlue;
773  transparent.gray = (png_uint_16)theTransparentGray;
774  png_set_tRNS( pp, info, NULL, 0, &transparent );
775  }
776 }
777 
778 void ossimPngWriter::writeBackgroundColorChunk(png_structp pp, png_infop info)
779 {
781  {
782  png_color_16 background;
783  background.red = theBackgroundRed;
784  background.green = theBackgroundGreen;
785  background.blue = theBackgroundBlue;
786  background.gray = theBackgroundGray;
787  png_set_bKGD( pp, info, &background );
788  }
789 }
790 
791 void ossimPngWriter::writeGammaChunk(png_structp pp, png_infop info)
792 {
793  if(theGammaFlag)
794  {
795  png_set_gAMA(pp, info, theGamma);
796  }
797 }
798 
800  png_infop info)
801 {
802  if(theTimeFlag)
803  {
804  png_time modtime;
805  time_t t;
806  time(&t);
807  png_convert_from_time_t(&modtime, t);
808  png_set_tIME(pp, info, &modtime);
809  }
810 }
811 
812 void ossimPngWriter::writeLatinTextChunk(png_structp /* pp */,
813  png_infop /* info */)
814 {}
815 
817  png_infop /* info */)
818 {}
819 
820 void ossimPngWriter::writeHistogram(png_structp /* pp */,
821  png_infop /* info */)
822 {}
823 
825  png_infop info)
826 {
827  // Must be called before PLTE and first IDAT. No multiple sBIT chunks.
829  {
831  if (max <= 65535)
832  {
833  ossim_uint16 max16 = static_cast<ossim_uint16>(max);
834  png_byte bits = 16;
835  ossim_uint16 s = 0xffff;
836  while ( (s != 0x0001) && (s >= max16) )
837  {
838  s = s >> 1;
839  if (s < max) break;
840  --bits;
841  }
842 
843  // destroyed by png_destroy_write_struct ??? (drb)
844  png_color_8* sig_bit = new png_color_8;
845  sig_bit->red = bits;
846  sig_bit->green = bits;
847  sig_bit->blue = bits;
848  sig_bit->gray = bits;
849  sig_bit->alpha = bits;
850  png_set_sBIT(pp, info, sig_bit);
851  }
852  }
853 }
854 
855 void ossimPngWriter::writeSuggestedPalette(png_structp /* pp */,
856  png_infop /* info */)
857 {}
858 
860  png_infop /* info */)
861 {}
862 
863 void ossimPngWriter::writePhysicalScale(png_structp /* pp */,
864  png_infop /* info */)
865 {}
866 
867 void ossimPngWriter::writeImageOffset(png_structp /* pp */,
868  png_infop /* info */)
869 {}
870 
871 void ossimPngWriter::writePixelCalibration(png_structp /* pp */,
872  png_infop /* info */)
873 {}
874 
875 void ossimPngWriter::writeFractalParameters(png_structp /* pp */,
876  png_infop /* info */)
877 {}
878 
880 {
881  //---
882  //
883  //---
884  ossim_int32 colorType = PNG_COLOR_TYPE_RGB;
885 
887  {
888  if(bands == 1)
889  {
890  colorType = PNG_COLOR_TYPE_GRAY_ALPHA;
891  }
892  else
893  {
894  colorType = PNG_COLOR_TYPE_RGB_ALPHA;
895  }
896  }
897  else
898  {
899  if (bands == 1)
900  {
901  colorType = PNG_COLOR_TYPE_GRAY;
902  }
903  }
904 
905  return colorType;
906 }
907 
909 {
910  // Can be 1, 2, 4, 8, or 16 bits/channel (from IHDR)
911  ossim_int32 bitDepth = 0;
912 
913  switch(outputScalar)
914  {
915  case OSSIM_UINT8:
916  bitDepth = 8;
917  break;
918  case OSSIM_SINT16:
919  case OSSIM_UINT16:
920  case OSSIM_USHORT11:
921  bitDepth = 16;
922  break;
923  default:
924  break;
925  }
926 
927  return bitDepth;
928 }
929 
931 {
932  ossimString result = ossimString("z_default_compression");
933 
934  switch (theCompressionLevel)
935  {
936  case Z_NO_COMPRESSION:
937  result = ossimString("z_no_compression");
938  break;
939 
940  case Z_BEST_SPEED:
941  result = ossimString("z_best_speed");
942  break;
943 
944  case Z_BEST_COMPRESSION:
945  result = ossimString("z_best_compression");
946  break;
947 
948  default:
949  break;
950  }
951  return result;
952 }
953 
955 {
956  bool status = true;
957 
958  ossimString s = level;
959  s.downcase();
960 
961  if(s == "z_no_compression")
962  {
963  theCompressionLevel = Z_NO_COMPRESSION;
964  }
965  else if(s == "z_best_speed")
966  {
967  theCompressionLevel = Z_BEST_SPEED;
968  }
969  else if(s == "z_best_compression")
970  {
971  theCompressionLevel = Z_BEST_COMPRESSION;
972  }
973  else if(s == "z_default_compression")
974  {
975  theCompressionLevel = Z_DEFAULT_COMPRESSION;
976  }
977  else
978  {
979  status = false;
980  }
981 
982  if (traceDebug())
983  {
985  << "DEBUG:"
986  << "\nossimPngWriter::setCompressionLevel DEBUG"
987  << "passed in level: " << level.c_str()
988  << "writer level: " << getCompressionLevel().c_str()
989  << endl;
990  }
991 
992  return status;
993 }
994 
996 {
997  return theAlphaChannelFlag;
998 }
999 
1001 {
1002  theAlphaChannelFlag = flag;
1003 }
1004 
1006 {
1008  {
1009  delete theOutputStream;
1010  }
1011  theOutputStream = &stream;
1012  theOwnsStreamFlag = false;
1013  return true;
1014 }
virtual ossimRefPtr< ossimImageData > getTile(const ossimIrect &rect, ossim_uint32 resLevel=0)
ossim_uint16 theTransparentGreen
void set_uly(ossim_int32 y)
Definition: ossimIrect.h:666
virtual void valueToString(ossimString &valueResult) const =0
RTTI_DEF1(ossimPngWriter, "ossimPngWriter", ossimImageFileWriter) static const char COMPRESSION_LEVEL_KW[]
ossim_uint16 theBackgroundBlue
void writeTransparentColorChunk(png_structp pp, png_infop info)
Write transparent color chunk (tRNS) Location: Multiple:
void writePhysicalScale(png_structp pp, png_infop info)
Write physical scale (sCAL) Location: before first IDAT Multiple: no.
bool theTimeFlag
Time support, either on or off.
void writeLatinTextChunk(png_structp pp, png_infop info)
Write any text (tEXt, zTXt).
virtual void computeAlphaChannel()
Computes the alpha channel.
virtual double getMaxPixelValue(ossim_uint32 band=0) const
Returns the max pixel of the band.
virtual void setImageRectangle(const ossimIrect &rect)
16 bit unsigned integer
virtual ossimString getLongName() const
Represents serializable keyword/value map.
ossim_int32 theInterlaceSupport
Interlace support: PNG_INTERLACE_ADAM7 PNG_INTERLACE_NONE.
virtual ossimString getClassName() const
virtual void setProperty(ossimRefPtr< ossimProperty > property)
Will set the property whose name matches the argument "property->getName()".
static const ossimErrorCode OSSIM_OK
virtual ossim_uint32 getNumberOfOutputBands() const
Returns the number of bands in a tile returned from this TileSource.
bool valid() const
Definition: ossimRefPtr.h:75
void writeBackgroundColorChunk(png_structp pp, png_infop info)
Write background color chunk (bKGD) Location: After PLTE, before first IDAT.
const char * find(const char *key) const
bool theBackgroundFlag
For background support.
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
ossimIrect theAreaOfInterest
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
saves the state of the object.
static ossimString toString(bool aValue)
Numeric to string methods.
void setAlphaChannelFlag(bool flag)
Set the writer to add an alpha channel to the output png image.
virtual void getImageTypeList(std::vector< ossimString > &imageTypeList) const
void getImageTypeList(std::vector<ossimString>& imageTypeList)const
void writeImageOffset(png_structp pp, png_infop info)
Write image offset (oFFs) Location: before first IDAT Multiple: no.
16 bit signed integer
const ossimIpt & ul() const
Definition: ossimIrect.h:274
OSSIM_DLL ossimByteOrder byteOrder()
Definition: ossimCommon.cpp:54
virtual bool writeStream()
Method to write the image to a stream.
virtual void close()
ossim_uint16 theTransparentGray
void addConstraint(const ossimString &value)
void writeFractalParameters(png_structp pp, png_infop info)
Write fractal parameters (fRAc) Location: anywhere Multiple: yes.
Pure virtual base class for image file writers.
unsigned short ossim_uint16
virtual ossimString getExtension() const
Returns a 3-letter extension from the image type descriptor (theOutputImageType) that can be used for...
virtual void getPropertyNames(std::vector< ossimString > &propertyNames) const
virtual void setProcessStatus(ossimProcessStatus processStatus)
bool setCompressionLevel(const ossimString &level)
Set the png compression level from a string.
ossim_uint16 theBackgroundGray
virtual void initialize()
Initialize the data buffer.
static void pngFlush(png_structp png_ptr)
Callback method for a flush.
ossimConnectableObject * getInput(ossim_uint32 index=0)
returns the object at the specified index.
double ossim_float64
void add(const char *prefix, const ossimKeywordlist &kwl, bool overwrite=true)
static ossimScalarTypeLut * instance()
Returns the static instance of an ossimScalarTypeLut object.
std::ostream * theOutputStream
virtual void getPropertyNames(std::vector< ossimString > &propertyNames) const
Pushes this&#39;s names onto the list of property names.
virtual void setAreaOfInterest(const ossimIrect &areaOfInterest)
void writeInternationalTextChunk(png_structp pp, png_infop info)
Write any text (iTXt).
virtual ossimScalarType getOutputScalarType() const
This will be used to query the output pixel type of the tile source.
void writeSuggestedPalette(png_structp pp, png_infop info)
Write suggested palette (sPLT) Location: before first IDAT Multiple: yes.
ossimRefPtr< ossimImageSourceSequencer > theInputConnection
ossim_uint16 theBackgroundRed
ossimString getCompressionLevel() const
Get the png compression level as a string.
virtual bool isOpen() const
ossim_int32 theCompressionLevel
Compression level from zlib.h: Z_NO_COMPRESSION 0 Z_BEST_SPEED 1 Z_BEST_COMPRESSION 9 Z_DEFAULT_COMPR...
bool isLutEnabled() const
unsigned int ossim_uint32
OSSIM_DLL ossim_uint32 scalarSizeInBytes(ossimScalarType scalarType)
const ossimIpt & lr() const
Definition: ossimIrect.h:276
static ossimString downcase(const ossimString &aString)
Definition: ossimString.cpp:48
void writePixelCalibration(png_structp pp, png_infop info)
Write pixel calibration (pCAL) Location: after PLTE, before first IDAT Multiple: no.
virtual void unloadTileToBipAlpha(void *dest, const ossimIrect &dest_rect, const ossimIrect &clip_rect) const
virtual void unloadTile(void *dest, const ossimIrect &dest_rect, ossimInterleaveType il_type) const
virtual ossim_int32 connectMyInputTo(ossimConnectableObject *inputObject, bool makeOutputConnection=true, bool createEventFlag=true)
Will try to connect this objects input to the passed in object.
virtual ossimRefPtr< ossimProperty > getProperty(const ossimString &name) const
bool theAlphaChannelFlag
For alpha channel support.
ossimScalarType
virtual bool writeFile()
Writes the file to disk or a stream.
virtual double getNullPixelValue(ossim_uint32 band=0) const
Each band has a null pixel associated with it.
return status
16 bit unsigned integer (11 bits used)
virtual ossim_uint32 getTileHeight() const
Returns the default processing tile height.
bool getAlphaChannelFlag(void) const
Retrieve the writer&#39;s setting for whether or not to add an alpha channel to the output png image...
bool hasImageType(const ossimString &imageType) const
bool hasImageType(const ossimString& imageType) const
bool theGammaFlag
For gamma support.
void writeHistogram(png_structp pp, png_infop info)
Write histogram (hIST) Location: after PLTE, before first IDAT Multiple: no.
virtual void setProperty(ossimRefPtr< ossimProperty > property)
void set_lry(ossim_int32 y)
Definition: ossimIrect.h:702
virtual ossimErrorCode getErrorStatus() const
ossim_int32 getColorType(ossim_int32 bands) const
Get the png color type.
#define max(a, b)
Definition: auxiliary.h:76
ossim_int32 y
Definition: ossimIpt.h:142
virtual void setWriteExternalGeometryFlag(bool flag)
void writeGammaChunk(png_structp pp, png_infop info)
Write gamm chunk (gAMMA) Location: Before PLTE, before first IDAT.
virtual const void * getBuf() const
ossim_float64 theGamma
bool theTransparentFlag
For transparent color support.
virtual ~ossimPngWriter()
virtual ossimString getShortName() const
void writeOptionalChunks(png_structp pp, png_infop info)
writes optionial chunks.
void writeTimeStampChunk(png_structp pp, png_infop info)
Write time stamp chunk (tIME).
virtual ossimRefPtr< ossimProperty > getProperty(const ossimString &name) const
const char * c_str() const
Returns a pointer to a null-terminated array of characters representing the string&#39;s contents...
Definition: ossimString.h:396
bool empty() const
Definition: ossimString.h:411
bool hasNans() const
Definition: ossimIrect.h:337
ossim_uint16 theTransparentBlue
const ossimIrect & getAreaOfInterest() const
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
Method to the load (recreate) the state of an object from a keyword list.
ossim_int32 x
Definition: ossimIpt.h:141
std::basic_ofstream< char > ofstream
Class for char output file streams.
Definition: ossimIosFwd.h:47
8 bit unsigned integer
ossim_uint16 theBackgroundGreen
virtual void setPercentComplete(double percentComplete)
virtual bool open()
void writeSignificantBits(png_structp pp, png_infop info)
Write significant bits (sBIT) Location: before PLTE and first IDAT Multiple: no.
ossim_uint16 theTransparentRed
void writePhysicalPixelDimensions(png_structp pp, png_infop info)
Write physical pixel dimensions (pHYs) Location: before first IDAT Multiple: no.
void swap(ossim_sint8 &)
Definition: ossimEndian.h:26
ossim_int32 getBitDepth(ossimScalarType outputScalar) const
unsigned char ossim_uint8
virtual bool setOutputStream(std::ostream &stream)
Sets the output stream to write to.
bool doSwap(ossimScalarType outputScalar) const
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)
ossim_int64 getNumberOfTilesVertical() const
std::basic_ostream< char > ostream
Base class for char output streams.
Definition: ossimIosFwd.h:23
const ossimString & getName() const
#define min(a, b)
Definition: auxiliary.h:75
int ossim_int32
static void pngWriteData(png_structp png_ptr, png_bytep data, png_size_t length)
Callback method for writing to stream.