#include "PngWriter.h" #include "PngElements.h" #include "Image.h" #include "File.h" #include "BufferBitStream.h" #include "OutputBitStream.h" #include "ImageBitStream.h" #include "Lz77Encoder.h" #include PngWriter::PngWriter() { } PngWriter::~PngWriter() { } std::unique_ptr PngWriter::Create() { return std::make_unique(); } void PngWriter::setPath(const Path& path) { mPath = path; } void PngWriter::writeSignature() { mOutStream->writeByte(Png::getHighBitCheck()); for (auto byte : Png::getSignature()) { mOutStream->writeByte(byte); } } void PngWriter::writeHeader() { writeSignature(); } void PngWriter::write(const std::unique_ptr >& image) { if (!mPath.empty()) { mWorkingFile = std::make_unique(mPath); mWorkingFile->Open(true); mOutStream = std::make_unique(mWorkingFile->GetOutHandle()); } else { mOutStream = std::make_unique(); } mWorkingImage = image.get(); mInStream = std::make_unique(image.get()); writeHeader(); //mImpl->write(image); //auto fp = fopen(mPath.c_str(), "wb"); //auto png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, nullptr, nullptr, nullptr); //auto info_ptr = png_create_info_struct(png_ptr); //if (setjmp(png_jmpbuf(png_ptr))) //{ // return; //} //png_init_io(png_ptr, fp); //if (setjmp(png_jmpbuf(png_ptr))) //{ // return; //} //auto color_type = PNG_COLOR_TYPE_RGB; //png_set_IHDR(png_ptr, info_ptr, image->GetWidth(), image->GetHeight(), // image->GetBitDepth(), color_type, PNG_INTERLACE_NONE, // PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE); //png_write_info(png_ptr, info_ptr); //if (setjmp(png_jmpbuf(png_ptr))) //{ // return; //} //png_bytep* row_pointers = (png_bytep*)malloc(sizeof(png_bytep) * image->GetHeight()); //auto row_size = image->GetBytesPerRow(); //for(unsigned jdx=0;jdxGetHeight();jdx++) //{ // row_pointers[jdx]=(png_byte*)malloc(sizeof(png_byte)*row_size); // for(unsigned idx=0;idxGetByte(idx, jdx); // } //} //png_write_image(png_ptr, row_pointers); //if (setjmp(png_jmpbuf(png_ptr))) //{ // return; //} //png_write_end(png_ptr, nullptr); //for (unsigned y=0; yGetHeight(); y++) //{ // free(row_pointers[y]); //} //free(row_pointers); //fclose(fp); //return; if (mWorkingFile) { mWorkingFile->Close(); } }