Skip to content

Commit

Permalink
Fixed conversions between image types.
Browse files Browse the repository at this point in the history
Conversions between floating-point image types now preserves HDR values,
or values outside the range 0 and 1.

Converting to grayscale types may now optionally perform the grayscale
conversion or keep the red channel only. Added separate Gray16 type to
differentiate between a normalized 16-bit value and unnormalized integer
type. Data from FreeImage uses Gray16 format, as it treats UInt16 as a
normalized grayscale type.

Added unit tests to verify conversion between various formats, ensuring
that HDR values are properly preserved and grayscale conversions work.

Verify that resizing filters preserves HDR values, both with the FreeImage
and fallback logic.
  • Loading branch information
akb825 committed Nov 4, 2024
1 parent 8c73532 commit 1bad97f
Show file tree
Hide file tree
Showing 4 changed files with 526 additions and 76 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ if (CUTTLEFISH_OUTPUT_DIR)
endif()

set(CUTTLEFISH_MAJOR_VERSION 2)
set(CUTTLEFISH_MINOR_VERSION 7)
set(CUTTLEFISH_PATCH_VERSION 5)
set(CUTTLEFISH_MINOR_VERSION 8)
set(CUTTLEFISH_PATCH_VERSION 0)
set(CUTTLEFISH_VERSION ${CUTTLEFISH_MAJOR_VERSION}.${CUTTLEFISH_MINOR_VERSION}.${CUTTLEFISH_PATCH_VERSION})

set(CUTTLEFISH_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
Expand Down
19 changes: 12 additions & 7 deletions lib/include/cuttlefish/Image.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2017-2022 Aaron Barany
* Copyright 2017-2024 Aaron Barany
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -55,6 +55,7 @@ class CUTTLEFISH_EXPORT Image
{
Invalid, ///< Invalid format, used for errors.
Gray8, ///< 8-bit grayscale.
Gray16, ///< 16-bit grayscale.
RGB5, ///< 6-bit per channel RGB.
RGB565, ///< 5, 6, and 5 bits per channel RGB.
RGB8, ///< 8-bit per channel RGB.
Expand Down Expand Up @@ -363,20 +364,24 @@ class CUTTLEFISH_EXPORT Image
/**
* @brief Sets a pixel as a floating point value.
* @remark This will work with any image format.
* @remark Conversion to grayscale will be automatic for Format::Gray8.
* @param x The X coordinate of the image.
* @param y The Y coordinate of the image.
* @param color The color of the pixel.
* @param convertGrayscale True to convert to grayscale for grayscale image types
* (Gray8, Gray16, Float, Double), false to take the red channel as-is.
* @return False if the pixel is out of range.
*/
bool setPixel(unsigned int x, unsigned int y, const ColorRGBAd& color);
bool setPixel(unsigned int x, unsigned int y, const ColorRGBAd& color,
bool convertGrayscale = true);

/**
* @brief Converts the image to another pixel format.
* @param format The new pixel format.
* @param dstFormat The new pixel format.
* @param convertGrayscale True to convert to grayscale for grayscale image types
* (Gray8, Gray16, Float, Double), false to take the red channel as-is.
* @return The converted image.
*/
Image convert(Format format) const;
Image convert(Format dstFormat, bool convertGrayscale = true) const;

/**
* @brief Resizes an image.
Expand Down Expand Up @@ -446,11 +451,11 @@ class CUTTLEFISH_EXPORT Image
* @brief Creates a normal map from the R channel of the image.
* @param options The options to use for computing the normal map.
* @param height The height for the image.
* @param format The format of the final image.
* @param dstFormat The format of the final image.
* @return The normal map image.
*/
Image createNormalMap(NormalOptions options = NormalOptions::Default, double height = 1.0,
Format format = Format::RGBF);
Format dstFormat = Format::RGBF);

private:
struct Impl;
Expand Down
Loading

0 comments on commit 1bad97f

Please sign in to comment.