comparison Framework/ImageToolbox.cpp @ 170:cea9a4701fce

Support of grayscale images
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 02 Aug 2019 15:31:19 +0200
parents 605247fc8758
children e3cbf890b588
comparison
equal deleted inserted replaced
169:de783db2a7c3 170:cea9a4701fce
324 source.GetFormat() != Orthanc::PixelFormat_RGBA32) // 16bpp is not supported (*) 324 source.GetFormat() != Orthanc::PixelFormat_RGBA32) // 16bpp is not supported (*)
325 { 325 {
326 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); 326 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented);
327 } 327 }
328 328
329 unsigned int channelsCount = source.GetBytesPerPixel(); // OK tx (*) 329 const unsigned int bytesPerPixel = source.GetBytesPerPixel(); // Corresponds to the number of channels tx (*)
330 330
331 std::auto_ptr<Orthanc::ImageAccessor> result(Allocate(source.GetFormat(), 331 std::auto_ptr<Orthanc::ImageAccessor> target(Allocate(source.GetFormat(),
332 source.GetWidth() / 2, 332 source.GetWidth() / 2,
333 source.GetHeight() / 2)); 333 source.GetHeight() / 2));
334 334
335 unsigned int bytesPerPixel = source.GetBytesPerPixel(); 335 for (unsigned int y = 0; y < target->GetHeight(); y++)
336 336 {
337 for (unsigned int y = 0; y < source.GetHeight() / 2; y++) 337 uint8_t* q = reinterpret_cast<uint8_t*>(target->GetRow(y));
338 { 338
339 uint8_t* q = reinterpret_cast<uint8_t*>(result->GetRow(y)); 339 for (unsigned int x = 0; x < target->GetWidth(); x++, q += bytesPerPixel)
340 340 {
341 for (unsigned int x = 0; x < source.GetWidth() / 2; x++, q += 3) 341 for (unsigned int c = 0; c < bytesPerPixel; c++)
342 {
343 for (unsigned int c = 0; c < channelsCount; c++)
344 { 342 {
345 if (smooth) 343 if (smooth)
346 { 344 {
347 q[c] = SmoothPixelValue(source, 2 * x, 2 * y, c, bytesPerPixel); 345 q[c] = SmoothPixelValue(source, 2 * x, 2 * y, c, bytesPerPixel);
348 } 346 }
352 } 350 }
353 } 351 }
354 } 352 }
355 } 353 }
356 354
357 return result.release(); 355 return target.release();
358 } 356 }
359 357
360 358
361 Orthanc::ImageAccessor* Clone(const Orthanc::ImageAccessor& accessor) 359 Orthanc::ImageAccessor* Clone(const Orthanc::ImageAccessor& accessor)
362 { 360 {