#pragma region CPL License
/*
Nuclex Native Framework
Copyright (C) 2002-2013 Nuclex Development Labs
This library is free software; you can redistribute it and/or
modify it under the terms of the IBM Common Public License as
published by the IBM Corporation; either version 1.0 of the
License, or (at your option) any later version.
This library 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
IBM Common Public License for more details.
You should have received a copy of the IBM Common Public
License along with this library
*/
#pragma endregion // CPL License
#ifndef NUCLEX_GRAPHICS_HELPERS_PIXELFORMATCONVERTER_H
#error This file must be included through PixelFormatConverter.h
#endif
namespace Nuclex { namespace Graphics { namespace Rasterization {
// ------------------------------------------------------------------------------------------- //
/// Converts pixels from one pixel format to another
template<>
class PixelFormatConverter {
/// Data type used by the input pixel format
public: typedef std::uint8_t InputType;
/// Data type used by the output pixel format
public: typedef std::uint8_t OutputType;
///
/// Converts a pixel from the input pixel format into the output pixel format
///
/// Pixel that will be converted
/// The pixel in the output pixel format
public: static OutputType ConvertPixel(InputType pixel) { return pixel; }
};
// ------------------------------------------------------------------------------------------- //
/// Converts pixels from one pixel format to another
template<>
class PixelFormatConverter {
/// Data type used by the input pixel format
public: typedef std::uint8_t InputType;
/// Data type used by the output pixel format
public: typedef std::uint16_t OutputType;
///
/// Converts a pixel from the input pixel format into the output pixel format
///
/// Pixel that will be converted
/// The pixel in the output pixel format
public: static OutputType ConvertPixel(InputType pixel) {
return 0x7F7F & (
(static_cast(pixel) >> 1) |
(static_cast(pixel) << 7)
);
}
};
// ------------------------------------------------------------------------------------------- //
/// Converts pixels from one pixel format to another
template<>
class PixelFormatConverter {
/// Data type used by the input pixel format
public: typedef std::uint8_t InputType;
/// Data type used by the output pixel format
public: typedef std::uint16_t OutputType;
///
/// Converts a pixel from the input pixel format into the output pixel format
///
/// Pixel that will be converted
/// The pixel in the output pixel format
public: static OutputType ConvertPixel(InputType pixel) {
return (
((static_cast(pixel) << 8) & 0xF800) |
((static_cast(pixel) << 3) & 0x07E0) |
(static_cast(pixel) >> 3)
);
}
};
// ------------------------------------------------------------------------------------------- //
/// Converts pixels from one pixel format to another
template<>
class PixelFormatConverter {
/// Data type used by the input pixel format
public: typedef std::uint8_t InputType;
/// Data type used by the output pixel format
public: typedef std::uint16_t OutputType;
///
/// Converts a pixel from the input pixel format into the output pixel format
///
/// Pixel that will be converted
/// The pixel in the output pixel format
public: static OutputType ConvertPixel(InputType pixel) {
return (
((static_cast(pixel) << 8) & 0xF000) |
((static_cast(pixel) << 4) & 0x0F00) |
(static_cast(pixel) & 0x00F0) |
0x000F
);
}
};
// ------------------------------------------------------------------------------------------- //
/// Converts pixels from one pixel format to another
template<>
class PixelFormatConverter {
/// Data type used by the input pixel format
public: typedef std::uint8_t InputType;
/// Data type used by the output pixel format
public: typedef std::uint32_t OutputType;
///
/// Converts a pixel from the input pixel format into the output pixel format
///
/// Pixel that will be converted
/// The pixel in the output pixel format
public: static OutputType ConvertPixel(InputType pixel) {
return (
(static_cast(pixel) << 24) |
(static_cast(pixel) << 16) |
(static_cast(pixel) << 8) |
0x000000FF
);
}
};
// ------------------------------------------------------------------------------------------- //
/// Converts pixels from one pixel format to another
template<>
class PixelFormatConverter {
/// Data type used by the input pixel format
public: typedef std::uint8_t InputType;
/// Data type used by the output pixel format
public: typedef std::uint32_t OutputType;
///
/// Converts a pixel from the input pixel format into the output pixel format
///
/// Pixel that will be converted
/// The pixel in the output pixel format
public: static OutputType ConvertPixel(InputType pixel) {
return 0x7F7F7F7F & (
(static_cast(pixel) << 23) |
(static_cast(pixel) << 15) |
(static_cast(pixel) << 7) |
0x0000007F
);
}
};
// ------------------------------------------------------------------------------------------- //
/// Converts pixels from one pixel format to another
template<>
class PixelFormatConverter {
// static_assert(false, "Compressed pixel formats need to be handled separately");
};
// ------------------------------------------------------------------------------------------- //
/// Converts pixels from one pixel format to another
template<>
class PixelFormatConverter {
// static_assert(false, "Compressed pixel formats need to be handled separately");
};
// ------------------------------------------------------------------------------------------- //
/// Converts pixels from one pixel format to another
template<>
class PixelFormatConverter {
// static_assert(false, "Compressed pixel formats need to be handled separately");
};
// ------------------------------------------------------------------------------------------- //
/// Converts pixels from one pixel format to another
template<>
class PixelFormatConverter {
/// Data type used by the input pixel format
public: typedef std::uint8_t InputType;
/// Data type used by the output pixel format
public: typedef std::uint8_t OutputType;
///
/// Converts a pixel from the input pixel format into the output pixel format
///
/// The pixel in the output pixel format
public: static OutputType ConvertPixel(InputType) { return 0xFF; }
};
// ------------------------------------------------------------------------------------------- //
/// Converts pixels from one pixel format to another
template<>
class PixelFormatConverter {
/// Data type used by the input pixel format
public: typedef std::uint8_t InputType;
/// Data type used by the output pixel format
public: typedef std::uint16_t OutputType;
///
/// Converts a pixel from the input pixel format into the output pixel format
///
/// Pixel that will be converted
/// The pixel in the output pixel format
public: static OutputType ConvertPixel(InputType pixel) {
return (
(static_cast(pixel) << 8) |
static_cast(pixel)
);
}
};
// ------------------------------------------------------------------------------------------- //
/// Converts pixels from one pixel format to another
template<>
class PixelFormatConverter {
/// Data type used by the input pixel format
public: typedef std::uint8_t InputType;
/// Data type used by the output pixel format
public: typedef std::uint32_t OutputType;
///
/// Converts a pixel from the input pixel format into the output pixel format
///
/// Pixel that will be converted
/// The pixel in the output pixel format
public: static OutputType ConvertPixel(InputType pixel) {
std::uint16_t intensity = (
(static_cast(pixel) << 8) |
static_cast(pixel)
);
return (
(static_cast(intensity) << 16) |
intensity
);
}
};
// ------------------------------------------------------------------------------------------- //
/// Converts pixels from one pixel format to another
template<>
class PixelFormatConverter {
/// Data type used by the input pixel format
public: typedef std::uint8_t InputType;
/// Data type used by the output pixel format
public: typedef std::uint32_t OutputType;
///
/// Converts a pixel from the input pixel format into the output pixel format
///
/// Pixel that will be converted
/// The pixel in the output pixel format
public: static OutputType ConvertPixel(InputType pixel) {
std::uint16_t intensity = Half::FromNormalizedByte(pixel);
return (
(static_cast(intensity) << 16) |
intensity
);
}
};
// ------------------------------------------------------------------------------------------- //
/// Converts pixels from one pixel format to another
template<>
class PixelFormatConverter {
/// Data type used by the input pixel format
public: typedef std::uint8_t InputType;
/// Data type used by the output pixel format
public: typedef std::uint32_t OutputType;
///
/// Converts a pixel from the input pixel format into the output pixel format
///
/// Pixel that will be converted
/// The pixel in the output pixel format
public: static OutputType ConvertPixel(InputType pixel) {
float result = static_cast(pixel) / 255.0f;
return *reinterpret_cast(&result);
}
};
// ------------------------------------------------------------------------------------------- //
/// Converts pixels from one pixel format to another
template<>
class PixelFormatConverter<
PixelFormat::R8_Unsigned, PixelFormat::Modern_R16_G16_B16_A16_Unsigned
> {
/// Data type used by the input pixel format
public: typedef std::uint8_t InputType;
/// Data type used by the output pixel format
public: typedef std::uint64_t OutputType;
///
/// Converts a pixel from the input pixel format into the output pixel format
///
/// Pixel that will be converted
/// The pixel in the output pixel format
public: static OutputType ConvertPixel(InputType pixel) {
std::uint16_t intensity = (
(static_cast(pixel) << 8) |
static_cast(pixel)
);
return (
(static_cast(intensity) << 48) |
(static_cast(intensity) << 32) |
(static_cast(intensity) << 16) |
0x000000000000FFFF
);
}
};
// ------------------------------------------------------------------------------------------- //
/// Converts pixels from one pixel format to another
template<>
class PixelFormatConverter<
PixelFormat::R8_Unsigned, PixelFormat::Modern_R16_G16_B16_A16_Float
> {
/// Data type used by the input pixel format
public: typedef std::uint8_t InputType;
/// Data type used by the output pixel format
public: typedef std::uint64_t OutputType;
///
/// Converts a pixel from the input pixel format into the output pixel format
///
/// Pixel that will be converted
/// The pixel in the output pixel format
public: static OutputType ConvertPixel(InputType pixel) {
std::uint16_t intensity = Half::FromNormalizedByte(pixel);
return (
(static_cast(intensity) << 48) |
(static_cast(intensity) << 32) |
(static_cast(intensity) << 16) |
static_cast(Half::One)
);
}
};
// ------------------------------------------------------------------------------------------- //
}}} // namespace Nuclex::Graphics::Rasterization