#pragma region CPL License
/*
Nuclex Native Framework
Copyright (C) 2002-2021 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_PIXELS_STORAGE_JPEG_JPEGBITMAPCODEC_H
#define NUCLEX_PIXELS_STORAGE_JPEG_JPEGBITMAPCODEC_H
#include "Nuclex/Pixels/Config.h"
#if defined(NUCLEX_PIXELS_HAVE_LIBJPEG)
#include "Nuclex/Pixels/Storage/BitmapCodec.h"
namespace Nuclex { namespace Pixels { namespace Storage { namespace Jpeg {
// ------------------------------------------------------------------------------------------- //
/// Loads and saves images in the popular JPEG file format
class JpegBitmapCodec : public BitmapCodec {
/// Initializes a new JPEG bitmap codec
public: JpegBitmapCodec();
/// Frees all resources owned by the instance
public: virtual ~JpegBitmapCodec() = default;
/// Gives the name of the file format implemented by this codec
/// The name of the file format this codec implements
public: const std::string &GetName() const override { return this->name; }
/// Provides commonly used file extensions for this codec
/// The commonly used file extensions in order of preference
public: const std::vector &GetFileExtensions() const override {
return this->knownFileExtensions;
}
/// Checks if the codec is able to load the specified file
/// Source data that will be checked for loadbility
/// Optional file extension the loaded data had
/// True if the codec is able to load the specified file
public: bool CanLoad(
const VirtualFile &source, const std::string &extensionHint = std::string()
) const override;
/// Checks if the codec is able to save bitmaps to storage
/// True if the codec supports saving bitmaps
public: bool CanSave() const override;
/// Tries to read informations for a bitmap
/// Source data from which the informations should be extracted
/// Optional file extension the loaded data had
/// Informations about the bitmap, if the codec is able to load it
public: std::optional TryReadInfo(
const VirtualFile &source, const std::string &extensionHint = std::string()
) const override;
/// Tries to load the specified file as a bitmap
/// Source data the bitmap will be loaded from
/// Optional file extension the loaded data had
///
/// The bitmap loaded from the specified file data or an empty value if the file format
/// is not supported by the codec
///
public: virtual std::optional TryLoad(
const VirtualFile &source, const std::string &extensionHint = std::string()
) const override;
/// Tries to load the specified file into an exciting bitmap
///
/// Bitmap matching the exact dimensions of the file to be loaded
///
/// Source data the bitmap will be loaded from
/// Optional file extension the loaded data had
/// True if the codec was able to load the bitmap, false otherwise
public: bool TryReload(
Bitmap &exactlyFittingBitmap,
const VirtualFile &source, const std::string &extensionHint = std::string()
) const override;
/// Saves the specified bitmap into a file
/// Bitmap that will be saved into a file
/// File into which the bitmap will be saved
///
/// How much effort (CPU time) should be put into reducing the size of the image.
///
///
/// How much image quality should be prioritized over achieving small file sizes.
///
public: void Save(
const Bitmap &bitmap, VirtualFile &target,
float compressionEffortHint = 0.75f, float outputQualityHint = 0.95f
) const override;
/// Human-readable name of the file format this codec implements
private: std::string name;
/// File extensions this file format is known to use
private: std::vector knownFileExtensions;
};
// ------------------------------------------------------------------------------------------- //
}}}} // namespace Nuclex::Pixels::Storage::Jpeg
#endif // defined(NUCLEX_PIXELS_HAVE_LIBJPEG)
#endif // NUCLEX_PIXELS_STORAGE_JPEG_JPEGBITMAPCODEC_H