1 /** 2 * Orthanc - A Lightweight, RESTful DICOM Store 3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics 4 * Department, University Hospital of Liege, Belgium 5 * Copyright (C) 2017-2021 Osimis S.A., Belgium 6 * 7 * This program is free software: you can redistribute it and/or 8 * modify it under the terms of the GNU Lesser General Public License 9 * as published by the Free Software Foundation, either version 3 of 10 * the License, or (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, but 13 * WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 * Lesser General Public License for more details. 16 * 17 * You should have received a copy of the GNU Lesser General Public 18 * License along with this program. If not, see 19 * <http://www.gnu.org/licenses/>. 20 **/ 21 22 23 #pragma once 24 25 #include "ImageAccessor.h" 26 #include "PixelTraits.h" 27 28 #include <cassert> 29 30 namespace Orthanc 31 { 32 template <PixelFormat Format> 33 struct ImageTraits 34 { 35 typedef ::Orthanc::PixelTraits<Format> PixelTraits; 36 typedef typename PixelTraits::PixelType PixelType; 37 GetPixelFormatImageTraits38 static PixelFormat GetPixelFormat() 39 { 40 return Format; 41 } 42 GetPixelImageTraits43 static void GetPixel(PixelType& target, 44 const ImageAccessor& image, 45 unsigned int x, 46 unsigned int y) 47 { 48 assert(x < image.GetWidth() && y < image.GetHeight()); 49 PixelTraits::Copy(target, image.GetPixelUnchecked<PixelType>(x, y)); 50 } 51 SetPixelImageTraits52 static void SetPixel(ImageAccessor& image, 53 const PixelType& value, 54 unsigned int x, 55 unsigned int y) 56 { 57 assert(x < image.GetWidth() && y < image.GetHeight()); 58 PixelTraits::Copy(image.GetPixelUnchecked<PixelType>(x, y), value); 59 } 60 GetFloatPixelImageTraits61 static float GetFloatPixel(const ImageAccessor& image, 62 unsigned int x, 63 unsigned int y) 64 { 65 assert(x < image.GetWidth() && y < image.GetHeight()); 66 return PixelTraits::PixelToFloat(image.GetPixelUnchecked<PixelType>(x, y)); 67 } 68 SetFloatPixelImageTraits69 static void SetFloatPixel(ImageAccessor& image, 70 float value, 71 unsigned int x, 72 unsigned int y) 73 { 74 assert(x < image.GetWidth() && y < image.GetHeight()); 75 PixelTraits::FloatToPixel(image.GetPixelUnchecked<PixelType>(x, y), value); 76 } 77 }; 78 } 79