Class Bitmap

Synopsis

#include <Source/Falcor/Utils/Image/Bitmap.h>

class dlldecl Bitmap : public std::enable_shared_from_this<Bitmap>

Description

A class representing a memory bitmap

Inheritance

Ancestors: std::enable_shared_from_this< Bitmap >

Methods

Bitmap overload
createCreate from memory.
createFromFileCreate a new object from file.
getDataGet a pointer to the bitmap's data store
getFileDialogFiltersGet the file dialog filter vec for images.
getFileExtFromResourceFormatGet a file extension from a resource format
getFormatGet the data format
getFormatFromFileExtensionGet the file format flags for the image extension
getHeightGet the height of the bitmap
getRowPitchGet the row pitch in bytes
getSizeGet the data size in bytes
getWidthGet the width of the bitmap
saveImageStore a memory buffer to a file.
saveImageDialogOpen dialog to save image to a file

Source

Lines 36-144 in Source/Falcor/Utils/Image/Bitmap.h.

class dlldecl Bitmap : public std::enable_shared_from_this<Bitmap>
{
public:
    enum class ExportFlags : uint32_t
    {
        None = 0u,              //< Default
        ExportAlpha = 1u << 0,  //< Save alpha channel as well
        Lossy = 1u << 1,        //< Try to store in a lossy format
        Uncompressed = 1u << 2, //< Prefer faster load to a more compact file size
    };
    enum class FileFormat
    {
        PngFile,    //< PNG file for lossless compressed 8-bits images with optional alpha
        JpegFile,   //< JPEG file for lossy compressed 8-bits images without alpha
        TgaFile,    //< TGA file for lossless uncompressed 8-bits images with optional alpha
        BmpFile,    //< BMP file for lossless uncompressed 8-bits images with optional alpha
        PfmFile,    //< PFM file for floating point HDR images with 32-bit float per channel
        ExrFile,    //< EXR file for floating point HDR images with 16-bit float per channel
        DdsFile,    //< DDS file for storing GPU resource formats, including block compressed formats
                    //< See ImageIO. TODO: Remove(?) Bitmap IO implementation when ImageIO supports other formats
    };
    using UniquePtr = std::unique_ptr<Bitmap>;
    using UniqueConstPtr = std::unique_ptr<const Bitmap>;
    /** Create from memory.
        \param[in] width Width in pixels.
        \param[in] height Height in pixels
        \param[in] format Resource format.
        \param[in] pData Pointer to data. Data will be copied internally during creation and does not need to be managed by the caller.
        \return A new bitmap object.
    */
    static UniqueConstPtr create(uint32_t width, uint32_t height, ResourceFormat format, const uint8_t* pData);
    /** Create a new object from file.
        \param[in] filename Filename, including a path. If the file can't be found relative to the current directory, Falcor will search for it in the common directories.
        \param[in] isTopDown Control the memory layout of the image. If true, the top-left pixel is the first pixel in the buffer, otherwise the bottom-left pixel is first.
        \return If loading was successful, a new object. Otherwise, nullptr.
    */
    static UniqueConstPtr createFromFile(const std::string& filename, bool isTopDown);
    /** Store a memory buffer to a file.
        \param[in] filename Output filename. Can include a path - absolute or relative to the executable directory.
        \param[in] width The width of the image.
        \param[in] height The height of the image.
        \param[in] fileFormat The destination file format. See FileFormat enum above.
        \param[in] exportFlags The flags to export the file. See ExportFlags above.
        \param[in] ResourceFormat the format of the resource data
        \param[in] isTopDown Control the memory layout of the image. If true, the top-left pixel will be stored first, otherwise the bottom-left pixel will be stored first
        \param[in] pData Pointer to the buffer containing the image
    */
    static void saveImage(const std::string& filename, uint32_t width, uint32_t height, FileFormat fileFormat, ExportFlags exportFlags, ResourceFormat resourceFormat, bool isTopDown, void* pData);
    /**  Open dialog to save image to a file
        \param[in] pTexture Texture to save to file
    */
    static void saveImageDialog(Texture* pTexture);
    /** Get a pointer to the bitmap's data store
    */
    uint8_t* getData() const { return mpData.get(); }
    /** Get the width of the bitmap
    */
    uint32_t getWidth() const { return mWidth; }
    /** Get the height of the bitmap
    */
    uint32_t getHeight() const { return mHeight; }
    /** Get the data format
    */
    ResourceFormat getFormat() const { return mFormat; }
    /** Get the row pitch in bytes. For compressed formats this corresponds to one row of blocks, not pixels.
    */
    uint32_t getRowPitch() const { return mRowPitch; }
    /** Get the data size in bytes
    */
    uint32_t getSize() const { return mSize; }
    /** Get the file dialog filter vec for images.
        \param[in] format If set to ResourceFormat::Unknown, will return all the supported image file formats. If set to something else, will only return file types which support this format.
    */
    static FileDialogFilterVec getFileDialogFilters(ResourceFormat format = ResourceFormat::Unknown);
    /** Get a file extension from a resource format
    */
    static std::string getFileExtFromResourceFormat(ResourceFormat format);
    /** Get the file format flags for the image extension
        \param[in] ext The image file extension to get the 
    */
    static FileFormat getFormatFromFileExtension(const std::string& ext);
protected:
    Bitmap() = default;
    Bitmap(uint32_t width, uint32_t height, ResourceFormat format);
    Bitmap(uint32_t width, uint32_t height, ResourceFormat format, const uint8_t* pData);
    std::unique_ptr<uint8_t[]> mpData;
    uint32_t mWidth = 0;
    uint32_t mHeight = 0;
    uint32_t mRowPitch = 0;
    uint32_t mSize = 0;
    ResourceFormat mFormat = ResourceFormat::Unknown;
};





Add Discussion as Guest

Log in