Zig 0.17.0-dev (Split by item)

This is an example of documentation generated by ZigDoc, an alternative to Zig's built-in Auto Doc feature. See also examples in other modes/formats. The project being documented here (as the example) is the Zig library itself.

BitmapInfo

bmp.BitmapInfo
pub const BitmapInfo = struct

File

Code

pub const BitmapInfo = struct {
    dib_header_size: u32,
    /// Contains the interpreted number of colors in the palette (e.g.
    /// if the field's value is zero and the bit depth is <= 8, this
    /// will contain the maximum number of colors for the bit depth
    /// rather than the field's value directly).
    colors_in_palette: u32,
    bytes_per_color_palette_element: u8,
    pixel_data_offset: u32,
    compression: Compression,

    pub fn getExpectedPaletteByteLen(self: *const BitmapInfo) u64 {
        return @as(u64, self.colors_in_palette) * self.bytes_per_color_palette_element;
    }

    pub fn getActualPaletteByteLen(self: *const BitmapInfo) u64 {
        return self.getByteLenBetweenHeadersAndPixels() - self.getBitmasksByteLen();
    }

    pub fn getByteLenBetweenHeadersAndPixels(self: *const BitmapInfo) u64 {
        return @as(u64, self.pixel_data_offset) - self.dib_header_size - file_header_len;
    }

    pub fn getBitmasksByteLen(self: *const BitmapInfo) u8 {
        // Only BITMAPINFOHEADER (3.1) has trailing bytes for the BITFIELDS
        // The 2.0 format doesn't have a compression field and 4.0+ has dedicated
        // fields for the masks in the header.
        const dib_version = BitmapHeader.Version.get(self.dib_header_size);
        return switch (dib_version) {
            .@"nt3.1" => switch (self.compression) {
                .BI_BITFIELDS => 12,
                .BI_ALPHABITFIELDS => 16,
                else => 0,
            },
            else => 0,
        };
    }

    pub fn getMissingPaletteByteLen(self: *const BitmapInfo) u64 {
        if (self.getActualPaletteByteLen() >= self.getExpectedPaletteByteLen()) return 0;
        return self.getExpectedPaletteByteLen() - self.getActualPaletteByteLen();
    }

    /// Returns the full byte len of the DIB header + optional bitmasks + color palette
    pub fn getExpectedByteLenBeforePixelData(self: *const BitmapInfo) u64 {
        return @as(u64, self.dib_header_size) + self.getBitmasksByteLen() + self.getExpectedPaletteByteLen();
    }

    /// Returns the full expected byte len
    pub fn getExpectedByteLen(self: *const BitmapInfo, file_size: u64) u64 {
        return self.getExpectedByteLenBeforePixelData() + self.getPixelDataLen(file_size);
    }

    pub fn getPixelDataLen(self: *const BitmapInfo, file_size: u64) u64 {
        return file_size - self.pixel_data_offset;
    }
}