odin-blend2d

Odin bindings to Blend2D
Log | Files | Refs | README | LICENSE

format.odin (4394B)


      1 // This file is part of Blend2D project <https://blend2d.com>
      2 //
      3 // See blend2d.h or LICENSE.md for license and copyright information
      4 // SPDX-License-Identifier: Zlib
      5 package blend2d
      6 
      7 when ODIN_OS == .Windows {
      8 	foreign import lib "blend2d.lib"
      9 } else when ODIN_OS == .Darwin {
     10 	foreign import lib "libblend2d.a"
     11 } else when ODIN_OS == .Linux {
     12 	foreign import lib "libblend2d.a"
     13 }
     14 
     15 
     16 //! Pixel format.
     17 //!
     18 //! Compatibility Table
     19 //! -------------------
     20 //!
     21 //! ```
     22 //! +---------------------+---------------------+-----------------------------+
     23 //! | Blend2D Format      | Cairo Format        | QImage::Format              |
     24 //! +---------------------+---------------------+-----------------------------+
     25 //! | BL_FORMAT_PRGB32    | CAIRO_FORMAT_ARGB32 | Format_ARGB32_Premultiplied |
     26 //! | BL_FORMAT_XRGB32    | CAIRO_FORMAT_RGB24  | Format_RGB32                |
     27 //! | BL_FORMAT_A8        | CAIRO_FORMAT_A8     | n/a                         |
     28 //! +---------------------+---------------------+-----------------------------+
     29 //! ```
     30 Format :: enum u32 {
     31 	//! None or invalid pixel format.
     32 	NONE       = 0,
     33 
     34 	//! 32-bit premultiplied ARGB pixel format (8-bit components).
     35 	PRGB32     = 1,
     36 
     37 	//! 32-bit (X)RGB pixel format (8-bit components, alpha ignored).
     38 	XRGB32     = 2,
     39 
     40 	//! 8-bit alpha-only pixel format.
     41 	A8         = 3,
     42 
     43 	// Maximum value of `BLFormat`.
     44 	MAX_VALUE  = 3,
     45 	FORCE_UINT = 4294967295,
     46 }
     47 
     48 //! Pixel format flags.
     49 FormatFlags :: enum u32 {
     50 	//! No flags.
     51 	NO_FLAGS            = 0,
     52 
     53 	//! Pixel format provides RGB components.
     54 	FLAG_RGB            = 1,
     55 
     56 	//! Pixel format provides only alpha component.
     57 	FLAG_ALPHA          = 2,
     58 
     59 	//! A combination of `BL_FORMAT_FLAG_RGB | BL_FORMAT_FLAG_ALPHA`.
     60 	FLAG_RGBA           = 3,
     61 
     62 	//! Pixel format provides LUM component (and not RGB components).
     63 	FLAG_LUM            = 4,
     64 
     65 	//! A combination of `BL_FORMAT_FLAG_LUM | BL_FORMAT_FLAG_ALPHA`.
     66 	FLAG_LUMA           = 6,
     67 
     68 	//! Indexed pixel format the requires a palette (I/O only).
     69 	FLAG_INDEXED        = 16,
     70 
     71 	//! RGB components are premultiplied by alpha component.
     72 	FLAG_PREMULTIPLIED  = 256,
     73 
     74 	//! Pixel format doesn't use native byte-order (I/O only).
     75 	FLAG_BYTE_SWAP      = 512,
     76 
     77 	// The following flags are only informative. They are part of `bl_format_info[]`, but don't have to be passed to
     78 	// `BLPixelConverter` as they will always be calculated automatically.
     79 	
     80 	//! Pixel components are byte aligned (all 8bpp).
     81 	FLAG_BYTE_ALIGNED   = 65536,
     82 
     83 	//! Pixel has some undefined bits that represent no information.
     84 	//!
     85 	//! For example a 32-bit XRGB pixel has 8 undefined bits that are usually set to all ones so the format can be
     86 	//! interpreted as premultiplied RGB as well. There are other formats like 16_0555 where the bit has no information
     87 	//! and is usually set to zero. Blend2D doesn't rely on the content of such bits.
     88 	FLAG_UNDEFINED_BITS = 131072,
     89 
     90 	//! Convenience flag that contains either zero or `BL_FORMAT_FLAG_BYTE_SWAP` depending on host byte order. Little
     91 	//! endian hosts have this flag set to zero and big endian hosts to `BL_FORMAT_FLAG_BYTE_SWAP`.
     92 	//!
     93 	//! \note This is not a real flag that you can test, it's only provided for convenience to define little endian
     94 	//! pixel formats.
     95 	FLAG_LE             = 0,
     96 
     97 	//! Convenience flag that contains either zero or `BL_FORMAT_FLAG_BYTE_SWAP` depending on host byte order. Big
     98 	//! endian hosts have this flag set to zero and little endian hosts to `BL_FORMAT_FLAG_BYTE_SWAP`.
     99 	//!
    100 	//! \note This is not a real flag that you can test, it's only provided for convenience to define big endian
    101 	//! pixel formats.
    102 	FLAG_BE             = 512,
    103 	FLAG_FORCE_UINT     = 4294967295,
    104 }
    105 
    106 @(default_calling_convention="c", link_prefix="bl_")
    107 foreign lib {
    108 	//! \name BLFormat - C API
    109 	//! \{
    110 	format_info_query    :: proc(self: ^FormatInfo, format: Format) -> Result ---
    111 	format_info_sanitize :: proc(self: ^FormatInfo) -> Result ---
    112 }
    113 
    114 //! Provides a detailed information about a pixel format. Use \ref bl_format_info array to get an information of Blend2D
    115 //! native pixel formats.
    116 FormatInfo :: struct {
    117 	depth: u32,
    118 	flags: FormatFlags,
    119 
    120 	using _: struct #raw_union {
    121 		using _: struct {
    122 			sizes:  [4]u8,
    123 			shifts: [4]u8,
    124 		},
    125 
    126 		using _: struct {
    127 			r_size:  u8,
    128 			g_size:  u8,
    129 			b_size:  u8,
    130 			a_size:  u8,
    131 			r_shift: u8,
    132 			g_shift: u8,
    133 			b_shift: u8,
    134 			a_shift: u8,
    135 		},
    136 
    137 		palette: ^Rgba32,
    138 	},
    139 }
    140