comparison Core/PngWriter.cpp @ 50:a15e90e5d6fc

rename in code
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 05 Sep 2012 15:50:12 +0200
parents 3959d33612cc
children c996319e90bc
comparison
equal deleted inserted replaced
49:e1a3ae0dadf3 50:a15e90e5d6fc
1 /** 1 /**
2 * Palantir - A Lightweight, RESTful DICOM Store 2 * Palanthir - A Lightweight, RESTful DICOM Store
3 * Copyright (C) 2012 Medical Physics Department, CHU of Liege, 3 * Copyright (C) 2012 Medical Physics Department, CHU of Liege,
4 * Belgium 4 * Belgium
5 * 5 *
6 * This program is free software: you can redistribute it and/or 6 * This program is free software: you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as 7 * modify it under the terms of the GNU General Public License as
21 #include "PngWriter.h" 21 #include "PngWriter.h"
22 22
23 #include <vector> 23 #include <vector>
24 #include <stdint.h> 24 #include <stdint.h>
25 #include <png.h> 25 #include <png.h>
26 #include "PalantirException.h" 26 #include "PalanthirException.h"
27 #include "ChunkedBuffer.h" 27 #include "ChunkedBuffer.h"
28 28
29 29
30 // http://www.libpng.org/pub/png/libpng-1.2.5-manual.html#section-4 30 // http://www.libpng.org/pub/png/libpng-1.2.5-manual.html#section-4
31 // http://zarb.org/~gc/html/libpng.html 31 // http://zarb.org/~gc/html/libpng.html
56 { 56 {
57 printf("++ %d\n", (int)message); 57 printf("++ %d\n", (int)message);
58 }*/ 58 }*/
59 59
60 60
61 namespace Palantir 61 namespace Palanthir
62 { 62 {
63 struct PngWriter::PImpl 63 struct PngWriter::PImpl
64 { 64 {
65 png_structp png_; 65 png_structp png_;
66 png_infop info_; 66 png_infop info_;
80 80
81 pimpl_->png_ = png_create_write_struct 81 pimpl_->png_ = png_create_write_struct
82 (PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); //this, ErrorHandler, WarningHandler); 82 (PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); //this, ErrorHandler, WarningHandler);
83 if (!pimpl_->png_) 83 if (!pimpl_->png_)
84 { 84 {
85 throw PalantirException(ErrorCode_NotEnoughMemory); 85 throw PalanthirException(ErrorCode_NotEnoughMemory);
86 } 86 }
87 87
88 pimpl_->info_ = png_create_info_struct(pimpl_->png_); 88 pimpl_->info_ = png_create_info_struct(pimpl_->png_);
89 if (!pimpl_->info_) 89 if (!pimpl_->info_)
90 { 90 {
91 png_destroy_write_struct(&pimpl_->png_, NULL); 91 png_destroy_write_struct(&pimpl_->png_, NULL);
92 throw PalantirException(ErrorCode_NotEnoughMemory); 92 throw PalanthirException(ErrorCode_NotEnoughMemory);
93 } 93 }
94 } 94 }
95 95
96 PngWriter::~PngWriter() 96 PngWriter::~PngWriter()
97 { 97 {
131 pimpl_->bitDepth_ = 16; 131 pimpl_->bitDepth_ = 16;
132 pimpl_->colorType_ = PNG_COLOR_TYPE_GRAY; 132 pimpl_->colorType_ = PNG_COLOR_TYPE_GRAY;
133 break; 133 break;
134 134
135 default: 135 default:
136 throw PalantirException(ErrorCode_NotImplemented); 136 throw PalanthirException(ErrorCode_NotImplemented);
137 } 137 }
138 } 138 }
139 139
140 140
141 void PngWriter::Compress(unsigned int width, 141 void PngWriter::Compress(unsigned int width,
178 Prepare(width, height, pitch, format, buffer); 178 Prepare(width, height, pitch, format, buffer);
179 179
180 FILE* fp = fopen(filename, "wb"); 180 FILE* fp = fopen(filename, "wb");
181 if (!fp) 181 if (!fp)
182 { 182 {
183 throw PalantirException(ErrorCode_CannotWriteFile); 183 throw PalanthirException(ErrorCode_CannotWriteFile);
184 } 184 }
185 185
186 png_init_io(pimpl_->png_, fp); 186 png_init_io(pimpl_->png_, fp);
187 187
188 if (setjmp(png_jmpbuf(pimpl_->png_))) 188 if (setjmp(png_jmpbuf(pimpl_->png_)))
189 { 189 {
190 // Error during writing PNG 190 // Error during writing PNG
191 throw PalantirException(ErrorCode_CannotWriteFile); 191 throw PalanthirException(ErrorCode_CannotWriteFile);
192 } 192 }
193 193
194 Compress(width, height, pitch, format); 194 Compress(width, height, pitch, format);
195 195
196 fclose(fp); 196 fclose(fp);
221 Prepare(width, height, pitch, format, buffer); 221 Prepare(width, height, pitch, format, buffer);
222 222
223 if (setjmp(png_jmpbuf(pimpl_->png_))) 223 if (setjmp(png_jmpbuf(pimpl_->png_)))
224 { 224 {
225 // Error during writing PNG 225 // Error during writing PNG
226 throw PalantirException(ErrorCode_InternalError); 226 throw PalanthirException(ErrorCode_InternalError);
227 } 227 }
228 228
229 png_set_write_fn(pimpl_->png_, &chunks, MemoryCallback, NULL); 229 png_set_write_fn(pimpl_->png_, &chunks, MemoryCallback, NULL);
230 230
231 Compress(width, height, pitch, format); 231 Compress(width, height, pitch, format);