Mercurial > hg > orthanc
view Core/Images/PixelTraits.h @ 2487:be1dbb1dcdd6
PixelTraits and ImageTraits
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 13 Mar 2018 16:29:20 +0100 |
parents | |
children | e91bab2d8c75 |
line wrap: on
line source
/** * Orthanc - A Lightweight, RESTful DICOM Store * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics * Department, University Hospital of Liege, Belgium * Copyright (C) 2017-2018 Osimis S.A., Belgium * * This program is free software: you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * In addition, as a special exception, the copyright holders of this * program give permission to link the code of its release with the * OpenSSL project's "OpenSSL" library (or with modified versions of it * that use the same license as the "OpenSSL" library), and distribute * the linked executables. You must obey the GNU General Public License * in all respects for all of the code used other than "OpenSSL". If you * modify file(s) with this exception, you may extend this exception to * your version of the file(s), but you are not obligated to do so. If * you do not wish to do so, delete this exception statement from your * version. If you delete this exception statement from all source files * in the program, then also delete it here. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. **/ #pragma once #include "../Enumerations.h" namespace Orthanc { template <PixelFormat Format> struct PixelTraits; template <> struct PixelTraits<PixelFormat_Grayscale8> { typedef uint8_t PixelType; ORTHANC_FORCE_INLINE static PixelFormat GetPixelFormat() { return PixelFormat_Grayscale8; } ORTHANC_FORCE_INLINE static void SetZero(PixelType& target) { target = 0; } ORTHANC_FORCE_INLINE static void Copy(PixelType& target, const PixelType& source) { target = source; } ORTHANC_FORCE_INLINE static float PixelToFloat(const PixelType& source) { return static_cast<float>(source); } ORTHANC_FORCE_INLINE static void FloatToPixel(PixelType& target, float value) { target = static_cast<uint8_t>(value); } ORTHANC_FORCE_INLINE static bool IsEqual(const PixelType& a, const PixelType& b) { return a == b; } }; template <> struct PixelTraits<PixelFormat_Grayscale16> { typedef uint16_t PixelType; ORTHANC_FORCE_INLINE static PixelFormat GetPixelFormat() { return PixelFormat_Grayscale16; } ORTHANC_FORCE_INLINE static void SetZero(PixelType& target) { target = 0; } ORTHANC_FORCE_INLINE static void Copy(PixelType& target, const PixelType& source) { target = source; } ORTHANC_FORCE_INLINE static float PixelToFloat(const PixelType& source) { return static_cast<float>(source); } ORTHANC_FORCE_INLINE static void FloatToPixel(PixelType& target, float value) { target = static_cast<uint16_t>(value); } ORTHANC_FORCE_INLINE static bool IsEqual(const PixelType& a, const PixelType& b) { return a == b; } }; template <> struct PixelTraits<PixelFormat_SignedGrayscale16> { typedef int16_t PixelType; ORTHANC_FORCE_INLINE static PixelFormat GetPixelFormat() { return PixelFormat_SignedGrayscale16; } ORTHANC_FORCE_INLINE static void SetZero(PixelType& target) { target = 0; } ORTHANC_FORCE_INLINE static void Copy(PixelType& target, const PixelType& source) { target = source; } ORTHANC_FORCE_INLINE static float PixelToFloat(const PixelType& source) { return static_cast<float>(source); } ORTHANC_FORCE_INLINE static void FloatToPixel(PixelType& target, float value) { target = static_cast<int16_t>(value); } ORTHANC_FORCE_INLINE static bool IsEqual(const PixelType& a, const PixelType& b) { return a == b; } }; template <> struct PixelTraits<PixelFormat_RGB24> { struct PixelType { uint8_t red_; uint8_t green_; uint8_t blue_; }; ORTHANC_FORCE_INLINE static PixelFormat GetPixelFormat() { return PixelFormat_RGB24; } ORTHANC_FORCE_INLINE static void SetZero(PixelType& target) { target.red_ = 0; target.green_ = 0; target.blue_ = 0; } ORTHANC_FORCE_INLINE static void Copy(PixelType& target, const PixelType& source) { target.red_ = source.red_; target.green_ = source.green_; target.blue_ = source.blue_; } ORTHANC_FORCE_INLINE static bool IsEqual(const PixelType& a, const PixelType& b) { return (a.red_ == b.red_ && a.green_ == b.green_ && a.blue_ == b.blue_); } }; template <> struct PixelTraits<PixelFormat_BGRA32> { struct PixelType { uint8_t blue_; uint8_t green_; uint8_t red_; uint8_t alpha_; }; ORTHANC_FORCE_INLINE static PixelFormat GetPixelFormat() { return PixelFormat_BGRA32; } ORTHANC_FORCE_INLINE static void SetZero(PixelType& target) { target.blue_ = 0; target.green_ = 0; target.red_ = 0; target.alpha_ = 0; } ORTHANC_FORCE_INLINE static void Copy(PixelType& target, const PixelType& source) { target.blue_ = source.blue_; target.green_ = source.green_; target.red_ = source.red_; target.alpha_ = source.alpha_; } ORTHANC_FORCE_INLINE static bool IsEqual(const PixelType& a, const PixelType& b) { return (a.blue_ == b.blue_ && a.green_ == b.green_ && a.red_ == b.red_ && a.alpha_ == b.alpha_); } }; }