comparison UnitTestsSources/ImageTests.cpp @ 1604:1f5d6a2f9638

JpegReader
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 01 Sep 2015 14:57:13 +0200
parents 292bce3f54ed
children adc6a5704cdb
comparison
equal deleted inserted replaced
1603:905b4db3092b 1604:1f5d6a2f9638
35 35
36 #include <stdint.h> 36 #include <stdint.h>
37 #include "../Core/ImageFormats/ImageBuffer.h" 37 #include "../Core/ImageFormats/ImageBuffer.h"
38 #include "../Core/ImageFormats/PngReader.h" 38 #include "../Core/ImageFormats/PngReader.h"
39 #include "../Core/ImageFormats/PngWriter.h" 39 #include "../Core/ImageFormats/PngWriter.h"
40 #include "../Core/ImageFormats/JpegReader.h"
40 #include "../Core/ImageFormats/JpegWriter.h" 41 #include "../Core/ImageFormats/JpegWriter.h"
41 #include "../Core/Toolbox.h" 42 #include "../Core/Toolbox.h"
42 #include "../Core/Uuid.h" 43 #include "../Core/Uuid.h"
43 44
44 45
190 191
191 192
192 193
193 TEST(JpegWriter, Basic) 194 TEST(JpegWriter, Basic)
194 { 195 {
195 Orthanc::ImageBuffer img(16, 16, Orthanc::PixelFormat_Grayscale8);
196 Orthanc::ImageAccessor accessor = img.GetAccessor();
197 for (unsigned int y = 0, value = 0; y < img.GetHeight(); y++)
198 {
199 uint8_t* p = reinterpret_cast<uint8_t*>(accessor.GetRow(y));
200 for (unsigned int x = 0; x < img.GetWidth(); x++, p++)
201 {
202 *p = value++;
203 }
204 }
205
206 Orthanc::JpegWriter w;
207 w.WriteToFile("UnitTestsResults/hello.jpg", accessor);
208
209 std::string s; 196 std::string s;
210 w.WriteToMemory(s, accessor); 197
211 Orthanc::Toolbox::WriteFile(s, "UnitTestsResults/hello2.jpg"); 198 {
212 } 199 Orthanc::ImageBuffer img(16, 16, Orthanc::PixelFormat_Grayscale8);
200 Orthanc::ImageAccessor accessor = img.GetAccessor();
201 for (unsigned int y = 0, value = 0; y < img.GetHeight(); y++)
202 {
203 uint8_t* p = reinterpret_cast<uint8_t*>(accessor.GetRow(y));
204 for (unsigned int x = 0; x < img.GetWidth(); x++, p++)
205 {
206 *p = value++;
207 }
208 }
209
210 Orthanc::JpegWriter w;
211 w.WriteToFile("UnitTestsResults/hello.jpg", accessor);
212
213 w.WriteToMemory(s, accessor);
214 Orthanc::Toolbox::WriteFile(s, "UnitTestsResults/hello2.jpg");
215
216 std::string t;
217 Orthanc::Toolbox::ReadFile(t, "UnitTestsResults/hello.jpg");
218 ASSERT_EQ(s.size(), t.size());
219 ASSERT_EQ(0, memcmp(s.c_str(), t.c_str(), s.size()));
220 }
221
222 {
223 Orthanc::JpegReader r1, r2;
224 r1.ReadFromFile("UnitTestsResults/hello.jpg");
225 ASSERT_EQ(16, r1.GetWidth());
226 ASSERT_EQ(16, r1.GetHeight());
227
228 r2.ReadFromMemory(s);
229 ASSERT_EQ(16, r2.GetWidth());
230 ASSERT_EQ(16, r2.GetHeight());
231
232 for (unsigned int y = 0; y < r1.GetHeight(); y++)
233 {
234 const uint8_t* p1 = reinterpret_cast<const uint8_t*>(r1.GetConstRow(y));
235 const uint8_t* p2 = reinterpret_cast<const uint8_t*>(r2.GetConstRow(y));
236 for (unsigned int x = 0; x < r1.GetWidth(); x++)
237 {
238 ASSERT_EQ(*p1, *p2);
239 }
240 }
241 }
242 }