CGVIS Utils
Loading...
Searching...
No Matches
bmp.h File Reference

Minimal BMP I/O utilities and a region blit helper. More...

#include <fstream>
#include <iostream>
#include <exception>
#include <string>
#include <sstream>
#include "Vec2.h"
#include "Image.h"
Include dependency graph for bmp.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  BMP::BMPException
 Exception type thrown by BMP I/O helpers. More...

Namespaces

namespace  BMP

Functions

bool BMP::save (const std::string &filename, const Image &source, bool ignoreSize=false)
 Save an Image to a BMP file.
bool BMP::save (const std::string &filename, uint32_t w, uint32_t h, const std::vector< uint8_t > &data, uint8_t iComponentCount=3, bool ignoreSize=false)
 Save raw 8-bit component data to a BMP file.
bool BMP::save (const std::string &filename, uint32_t w, uint32_t h, const std::vector< float > &data, uint8_t iComponentCount=3, bool ignoreSize=false)
 Save raw floating-point component data to a BMP file.
Image BMP::load (const std::string &filename)
 Load a BMP file into an Image.
void BMP::blit (const Image &source, const Vec2ui &sourceStart, const Vec2ui &sourceEnd, Image &target, const Vec2ui &targetStart, bool skipChecks=false)
 Copy a rectangular region from source to target (blit).

Detailed Description

Minimal BMP I/O utilities and a region blit helper.

Provides functions to save images to 24/32-bit BMP, load BMP files into an Image, and copy a rectangular region between images. The save routines accept either an Image or raw component data (uint8_t or float).

  • Saving writes uncompressed Windows BMP (BITMAPINFOHEADER, 40-byte info header) and converts component order from RGB(A) to BMP's BGR(A).
  • Rows are padded to 4-byte boundaries as required by the BMP format.
  • The save overload taking floats maps values in [0,1) to bytes via $byte = \lfloor 255\,x \rfloor$.
  • Loading supports 8/16/24/32 bpp BMP. Component order is converted from BGR(A) to RGB(A). Top-down BMPs (negative height) are returned flipped to match the conventional top-left origin used by Image.