Skip to content

Commit

Permalink
Added Image::save() function.
Browse files Browse the repository at this point in the history
Saves the image to a file with a format based on the extension. This is
intended to be used for the most common use cases, such as debugging or
outputting the result of a transformation as a viewable image rather than
a texture. The default values are used for settings such as compression.
The raw image data should be extracted and passed to a dedicated image
library if more fine-tuned control is required.

Incremented version number to 2.3.0.
  • Loading branch information
akb825 committed Sep 25, 2020
1 parent 41bbf74 commit c9754b0
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ if (CUTTLEFISH_OUTPUT_DIR)
endif()

set(CUTTLEFISH_MAJOR_VERSION 2)
set(CUTTLEFISH_MINOR_VERSION 1)
set(CUTTLEFISH_MINOR_VERSION 3)
set(CUTTLEFISH_PATCH_VERSION 0)
set(CUTTLEFISH_VERSION ${CUTTLEFISH_MAJOR_VERSION}.${CUTTLEFISH_MINOR_VERSION}.${CUTTLEFISH_PATCH_VERSION})

Expand Down
14 changes: 14 additions & 0 deletions lib/include/cuttlefish/Image.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,20 @@ class CUTTLEFISH_EXPORT Image
bool load(const std::uint8_t* data, std::size_t size,
ColorSpace colorSpace = ColorSpace::Linear);

/**
* @brief Saves an image to a file.
*
* Nearly all image file formats, such as png, jpeg, etc., are supported. This will use the
* default parameters for settings like compression, and is intended for the most common use
* cases. For more intricate use cases where finer levels of control are needed, you will need
* to extract the raw image data and use a dedicated image library.
*
* @remark You should ensure that the image's pixel format is supported by the file format.
* @param fileName The name of the file to save.
* @return False if the image couldn't be saved.
*/
bool save(const char* fileName);

/**
* @brief Initializes an empty image.
* @param format The pixel format.
Expand Down
12 changes: 12 additions & 0 deletions lib/src/Image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,18 @@ bool Image::load(const std::uint8_t* data, std::size_t size, ColorSpace colorSpa
return m_impl != nullptr;
}

bool Image::save(const char* fileName)
{
if (!m_impl)
return false;

FREE_IMAGE_FORMAT format = FreeImage_GetFIFFromFilename(fileName);
if (format == FIF_UNKNOWN)
return false;

return FreeImage_Save(format, m_impl->image, fileName) != false;
}

bool Image::initialize(Format format, unsigned int width, unsigned int height,
ColorSpace colorSpace)
{
Expand Down
1 change: 0 additions & 1 deletion lib/test/ImageTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -787,7 +787,6 @@ TEST(NormalMapTest, CreateNormalMap)
}
}


normalMap = image.createNormalMap(false, 2.5);
EXPECT_TRUE(normalMap.isValid());
for (unsigned int y = 0; y < image.height(); ++y)
Expand Down

0 comments on commit c9754b0

Please sign in to comment.