annotate OrthancFramework/Sources/Images/PngWriter.cpp @ 5236:5e0db9eac1f8 db-protobuf

integration mainline->db-protobuf
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 04 Apr 2023 21:43:37 +0200
parents 0ea402b4d901
children 48b8dae6dc77
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
59
c996319e90bc renaming in Core
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
1900
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1612
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
1288
6e7e5ed91c2d upgrade to year 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 824
diff changeset
4 * Department, University Hospital of Liege, Belgium
5185
0ea402b4d901 upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5054
diff changeset
5 * Copyright (C) 2017-2023 Osimis S.A., Belgium
0ea402b4d901 upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5054
diff changeset
6 * Copyright (C) 2021-2023 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 *
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * This program is free software: you can redistribute it and/or
4119
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
9 * modify it under the terms of the GNU Lesser General Public License
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
10 * as published by the Free Software Foundation, either version 3 of
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
11 * the License, or (at your option) any later version.
136
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 59
diff changeset
12 *
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * This program is distributed in the hope that it will be useful, but
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
4119
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
16 * Lesser General Public License for more details.
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 *
4119
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
18 * You should have received a copy of the GNU Lesser General Public
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
19 * License along with this program. If not, see
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
20 * <http://www.gnu.org/licenses/>.
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 **/
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23
824
a811bdf8b8eb precompiled headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 800
diff changeset
24 #include "../PrecompiledHeaders.h"
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 #include "PngWriter.h"
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 #include <vector>
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 #include <stdint.h>
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 #include <png.h>
454
6f47a4262618 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 453
diff changeset
30 #include "../OrthancException.h"
6f47a4262618 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 453
diff changeset
31 #include "../ChunkedBuffer.h"
6f47a4262618 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 453
diff changeset
32 #include "../Toolbox.h"
2171
35febe19e874 improved support for sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2170
diff changeset
33
35febe19e874 improved support for sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2170
diff changeset
34 #if ORTHANC_SANDBOXED == 0
35febe19e874 improved support for sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2170
diff changeset
35 # include "../SystemToolbox.h"
35febe19e874 improved support for sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2170
diff changeset
36 #endif
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 // http://www.libpng.org/pub/png/libpng-1.2.5-manual.html#section-4
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 // http://zarb.org/~gc/html/libpng.html
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 /*
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 void write_row_callback(png_ptr, png_uint_32 row, int pass)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 }*/
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 /* bool isError_;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 // http://www.libpng.org/pub/png/book/chapter14.html#png.ch14.div.2
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 static void ErrorHandler(png_structp png, png_const_charp message)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 printf("** [%s]\n", message);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 PngWriter* that = (PngWriter*) png_get_error_ptr(png);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 that->isError_ = true;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 printf("** %d\n", (int)that);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 //((PngWriter*) payload)->isError_ = true;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 static void WarningHandler(png_structp png, png_const_charp message)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 {
4642
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
66 printf("++ %d\n", (int)message);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 }*/
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69
59
c996319e90bc renaming in Core
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
70 namespace Orthanc
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 {
4642
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
72 /**
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
73 * The "png_" structure cannot be safely reused if the bpp changes
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
74 * between successive invocations. This can lead to "Invalid reads"
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
75 * reported by valgrind if writing a 16bpp image, then a 8bpp image
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
76 * using the same "PngWriter" object. Starting with Orthanc 1.9.3,
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
77 * we recreate a new "png_" context each time a PNG image must be
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
78 * written so as to prevent such invalid reads.
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
79 **/
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
80 class PngWriter::Context : public boost::noncopyable
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 {
4642
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
82 private:
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 png_structp png_;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 png_infop info_;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 // Filled by Prepare()
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 std::vector<uint8_t*> rows_;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 int bitDepth_;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 int colorType_;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90
4642
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
91 public:
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
92 Context() :
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
93 png_(NULL),
4657
e8967149d87a cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4642
diff changeset
94 info_(NULL),
e8967149d87a cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4642
diff changeset
95 bitDepth_(0), // Dummy initialization
e8967149d87a cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4642
diff changeset
96 colorType_(0) // Dummy initialization
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 {
4642
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
98 png_ = png_create_write_struct
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
99 (PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); //this, ErrorHandler, WarningHandler);
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
100 if (!png_)
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101 {
4642
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
102 throw OrthancException(ErrorCode_NotEnoughMemory);
639
51892be15618 fix for big endian architectures
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 465
diff changeset
103 }
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104
4642
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
105 info_ = png_create_info_struct(png_);
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
106 if (!info_)
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
107 {
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
108 png_destroy_write_struct(&png_, NULL);
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
109 throw OrthancException(ErrorCode_NotEnoughMemory);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112
4642
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
113
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
114 ~Context()
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
115 {
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
116 if (info_)
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
117 {
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
118 png_destroy_info_struct(png_, &info_);
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
119 }
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
120
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
121 if (png_)
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
122 {
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
123 png_destroy_write_struct(&png_, NULL);
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
124 }
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
125 }
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
126
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
127
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
128 png_structp GetObject() const
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
129 {
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
130 return png_;
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
131 }
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
132
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
133
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
134 void Prepare(unsigned int width,
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
135 unsigned int height,
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
136 unsigned int pitch,
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
137 PixelFormat format,
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
138 const void* buffer)
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
139 {
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
140 rows_.resize(height);
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
141 for (unsigned int y = 0; y < height; y++)
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
142 {
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
143 rows_[y] = const_cast<uint8_t*>(reinterpret_cast<const uint8_t*>(buffer)) + y * pitch;
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
144 }
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
145
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
146 switch (format)
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
147 {
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
148 case PixelFormat_RGB24:
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
149 bitDepth_ = 8;
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
150 colorType_ = PNG_COLOR_TYPE_RGB;
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
151 break;
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
152
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
153 case PixelFormat_RGBA32:
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
154 bitDepth_ = 8;
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
155 colorType_ = PNG_COLOR_TYPE_RGBA;
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
156 break;
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
157
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
158 case PixelFormat_Grayscale8:
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
159 bitDepth_ = 8;
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
160 colorType_ = PNG_COLOR_TYPE_GRAY;
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
161 break;
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
162
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
163 case PixelFormat_Grayscale16:
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
164 case PixelFormat_SignedGrayscale16:
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
165 bitDepth_ = 16;
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
166 colorType_ = PNG_COLOR_TYPE_GRAY;
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
167 break;
5054
255b02c68908 Added support for RGBA64 images in tools/create-dicom and /preview (Contribution from James Manners - Pliny)
Alain Mazy <am@osimis.io>
parents: 4870
diff changeset
168
255b02c68908 Added support for RGBA64 images in tools/create-dicom and /preview (Contribution from James Manners - Pliny)
Alain Mazy <am@osimis.io>
parents: 4870
diff changeset
169 case PixelFormat_RGBA64:
255b02c68908 Added support for RGBA64 images in tools/create-dicom and /preview (Contribution from James Manners - Pliny)
Alain Mazy <am@osimis.io>
parents: 4870
diff changeset
170 bitDepth_ = 16;
255b02c68908 Added support for RGBA64 images in tools/create-dicom and /preview (Contribution from James Manners - Pliny)
Alain Mazy <am@osimis.io>
parents: 4870
diff changeset
171 colorType_ = PNG_COLOR_TYPE_RGBA;
255b02c68908 Added support for RGBA64 images in tools/create-dicom and /preview (Contribution from James Manners - Pliny)
Alain Mazy <am@osimis.io>
parents: 4870
diff changeset
172 break;
4642
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
173
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
174 default:
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
175 throw OrthancException(ErrorCode_NotImplemented);
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
176 }
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
177 }
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
178
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
179
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
180 void Compress(unsigned int width,
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
181 unsigned int height,
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
182 unsigned int pitch,
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
183 PixelFormat format)
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
184 {
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
185 png_set_IHDR(png_, info_, width, height,
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
186 bitDepth_, colorType_, PNG_INTERLACE_NONE,
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
187 PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
188
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
189 png_write_info(png_, info_);
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
190
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
191 if (height > 0)
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
192 {
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
193 switch (format)
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
194 {
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
195 case PixelFormat_Grayscale16:
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
196 case PixelFormat_SignedGrayscale16:
5054
255b02c68908 Added support for RGBA64 images in tools/create-dicom and /preview (Contribution from James Manners - Pliny)
Alain Mazy <am@osimis.io>
parents: 4870
diff changeset
197 case PixelFormat_RGBA64:
4642
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
198 {
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
199 int transforms = 0;
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
200 if (Toolbox::DetectEndianness() == Endianness_Little)
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
201 {
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
202 transforms = PNG_TRANSFORM_SWAP_ENDIAN;
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
203 }
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
204
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
205 png_set_rows(png_, info_, &rows_[0]);
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
206 png_write_png(png_, info_, transforms, NULL);
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
207
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
208 break;
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
209 }
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
210
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
211 default:
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
212 png_write_image(png_, &rows_[0]);
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
213 }
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
214 }
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
215
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
216 png_write_end(png_, NULL);
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
217 }
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
218 };
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
219
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
220
2170
baf8dd89b4e0 improved support for sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2143
diff changeset
221 #if ORTHANC_SANDBOXED == 0
1916
5bcf721bde4f IImageWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
222 void PngWriter::WriteToFileInternal(const std::string& filename,
5bcf721bde4f IImageWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
223 unsigned int width,
5bcf721bde4f IImageWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
224 unsigned int height,
5bcf721bde4f IImageWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
225 unsigned int pitch,
5bcf721bde4f IImageWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
226 PixelFormat format,
5bcf721bde4f IImageWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
227 const void* buffer)
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
228 {
4642
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
229 Context context;
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
230
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
231 context.Prepare(width, height, pitch, format, buffer);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
232
2140
aa4b8895cd23 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2017
diff changeset
233 FILE* fp = SystemToolbox::OpenFile(filename, FileMode_WriteBinary);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
234 if (!fp)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
235 {
59
c996319e90bc renaming in Core
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
236 throw OrthancException(ErrorCode_CannotWriteFile);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
237 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
238
4642
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
239 png_init_io(context.GetObject(), fp);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
240
4642
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
241 if (setjmp(png_jmpbuf(context.GetObject())))
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
242 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
243 // Error during writing PNG
59
c996319e90bc renaming in Core
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
244 throw OrthancException(ErrorCode_CannotWriteFile);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
245 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
246
4642
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
247 context.Compress(width, height, pitch, format);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
248
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
249 fclose(fp);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
250 }
2170
baf8dd89b4e0 improved support for sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2143
diff changeset
251 #endif
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
252
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
253
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
254 static void MemoryCallback(png_structp png_ptr,
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
255 png_bytep data,
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
256 png_size_t size)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
257 {
656
08eca5d86aad fixes to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 639
diff changeset
258 ChunkedBuffer* buffer = reinterpret_cast<ChunkedBuffer*>(png_get_io_ptr(png_ptr));
3402
cf31b5bacce3 removing unneeded casts
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
259 buffer->AddChunk(data, size);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
260 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
261
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
262
1916
5bcf721bde4f IImageWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
263 void PngWriter::WriteToMemoryInternal(std::string& png,
5bcf721bde4f IImageWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
264 unsigned int width,
5bcf721bde4f IImageWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
265 unsigned int height,
5bcf721bde4f IImageWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
266 unsigned int pitch,
5bcf721bde4f IImageWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
267 PixelFormat format,
5bcf721bde4f IImageWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
268 const void* buffer)
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
269 {
4642
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
270 Context context;
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
271
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
272 ChunkedBuffer chunks;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
273
4642
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
274 context.Prepare(width, height, pitch, format, buffer);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
275
4642
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
276 if (setjmp(png_jmpbuf(context.GetObject())))
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
277 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
278 // Error during writing PNG
59
c996319e90bc renaming in Core
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
279 throw OrthancException(ErrorCode_InternalError);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
280 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
281
4642
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
282 png_set_write_fn(context.GetObject(), &chunks, MemoryCallback, NULL);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
283
4642
69bbb4bd35cb PngWriter recreates a new libpng context for each encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
284 context.Compress(width, height, pitch, format);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
285
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
286 chunks.Flatten(png);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
287 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
288 }