odin-blend2d

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

image.odin (4784B)


      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 import "core:c"
      8 
      9 when ODIN_OS == .Windows {
     10 	foreign import lib "blend2d.lib"
     11 } else when ODIN_OS == .Darwin {
     12 	foreign import lib "libblend2d.a"
     13 } else when ODIN_OS == .Linux {
     14 	foreign import lib "libblend2d.a"
     15 }
     16 
     17 
     18 //! Flags used by `BLImageInfo`.
     19 ImageInfoFlags :: enum u32 {
     20 	//! No flags.
     21 	NO_FLAGS    = 0,
     22 
     23 	//! Progressive mode.
     24 	PROGRESSIVE = 1,
     25 	FORCE_UINT  = 4294967295,
     26 }
     27 
     28 //! Filter type used by `BLImage::scale()`.
     29 ImageScaleFilter :: enum u32 {
     30 	//! No filter or uninitialized.
     31 	NONE       = 0,
     32 
     33 	//! Nearest neighbor filter (radius 1.0).
     34 	NEAREST    = 1,
     35 
     36 	//! Bilinear filter (radius 1.0).
     37 	BILINEAR   = 2,
     38 
     39 	//! Bicubic filter (radius 2.0).
     40 	BICUBIC    = 3,
     41 
     42 	//! Lanczos filter (radius 2.0).
     43 	LANCZOS    = 4,
     44 
     45 	//! Maximum value of `BLImageScaleFilter`.
     46 	MAX_VALUE  = 4,
     47 	FORCE_UINT = 4294967295,
     48 }
     49 
     50 //! Data that describes a raster image. Used by \ref BLImage.
     51 ImageData :: struct {
     52 	//! Pixel data, starting at the top left corner of the image.
     53 	//!
     54 	//! \note If the stride is negative the image data would start at the bottom.
     55 	pixel_data: rawptr,
     56 
     57 	//! Stride (in bytes) of image data (positive when image data starts at top-left, negative when it starts at
     58 	//! bottom-left).
     59 	stride: c.intptr_t,
     60 
     61 	//! Size of the image.
     62 	size: SizeI,
     63 
     64 	//! Pixel format, see \ref BLFormat.
     65 	format: u32,
     66 	flags:  u32,
     67 }
     68 
     69 //! Image information provided by image codecs.
     70 ImageInfo :: struct {
     71 	//! Image size.
     72 	size: SizeI,
     73 
     74 	//! Pixel density per one meter, can contain fractions.
     75 	density: Size,
     76 
     77 	//! Image flags.
     78 	flags: u32,
     79 
     80 	//! Image depth.
     81 	depth: u16,
     82 
     83 	//! Number of planes.
     84 	plane_count: u16,
     85 
     86 	//! Number of frames (0 = unknown/unspecified).
     87 	frame_count: u64,
     88 
     89 	//! Number of animation repeats (0 == infinite).
     90 	repeat_count: u32,
     91 
     92 	//! Reserved for future use.
     93 	reserved: [3]u32,
     94 
     95 	//! Image format (as understood by codec).
     96 	format: [16]i8,
     97 
     98 	//! Image compression (as understood by codec).
     99 	compression: [16]i8,
    100 }
    101 
    102 //! 2D raster image [C API].
    103 ImageCore :: struct {
    104 	_d: ObjectDetail,
    105 }
    106 
    107 //! \cond INTERNAL
    108 //! 2D raster image [C API Impl].
    109 ImageImpl :: struct {
    110 	//! Pixel data.
    111 	pixel_data: rawptr,
    112 
    113 	//! Image stride.
    114 	stride: c.intptr_t,
    115 
    116 	//! Image size.
    117 	size: SizeI,
    118 
    119 	//! Image format.
    120 	format: u8,
    121 
    122 	//! Image flags.
    123 	flags: u8,
    124 
    125 	//! Image depth (in bits).
    126 	depth: u16,
    127 
    128 	//! Reserved for future use, must be zero.
    129 	reserved: [4]u8,
    130 }
    131 
    132 @(default_calling_convention="c", link_prefix="bl_")
    133 foreign lib {
    134 	//! \endcond
    135 	image_init              :: proc(self: ^ImageCore) -> Result ---
    136 	image_init_move         :: proc(self: ^ImageCore, other: ^ImageCore) -> Result ---
    137 	image_init_weak         :: proc(self: ^ImageCore, other: ^ImageCore) -> Result ---
    138 	image_init_as           :: proc(self: ^ImageCore, w: i32, h: i32, format: Format) -> Result ---
    139 	image_init_as_from_data :: proc(self: ^ImageCore, w: i32, h: i32, format: Format, pixel_data: rawptr, stride: c.intptr_t, access_flags: DataAccessFlags, destroy_func: DestroyExternalDataFunc, user_data: rawptr) -> Result ---
    140 	image_destroy           :: proc(self: ^ImageCore) -> Result ---
    141 	image_reset             :: proc(self: ^ImageCore) -> Result ---
    142 	image_assign_move       :: proc(self: ^ImageCore, other: ^ImageCore) -> Result ---
    143 	image_assign_weak       :: proc(self: ^ImageCore, other: ^ImageCore) -> Result ---
    144 	image_assign_deep       :: proc(self: ^ImageCore, other: ^ImageCore) -> Result ---
    145 	image_create            :: proc(self: ^ImageCore, w: i32, h: i32, format: Format) -> Result ---
    146 	image_create_from_data  :: proc(self: ^ImageCore, w: i32, h: i32, format: Format, pixel_data: rawptr, stride: c.intptr_t, access_flags: DataAccessFlags, destroy_func: DestroyExternalDataFunc, user_data: rawptr) -> Result ---
    147 	image_get_data          :: proc(self: ^ImageCore, data_out: ^ImageData) -> Result ---
    148 	image_make_mutable      :: proc(self: ^ImageCore, data_out: ^ImageData) -> Result ---
    149 	image_convert           :: proc(self: ^ImageCore, format: Format) -> Result ---
    150 	image_equals            :: proc(a: ^ImageCore, b: ^ImageCore) -> i32 ---
    151 	image_scale             :: proc(dst: ^ImageCore, src: ^ImageCore, size: ^SizeI, filter: ImageScaleFilter) -> Result ---
    152 	image_read_from_file    :: proc(self: ^ImageCore, file_name: cstring, codecs: ^ArrayCore) -> Result ---
    153 	image_read_from_data    :: proc(self: ^ImageCore, data: rawptr, size: c.size_t, codecs: ^ArrayCore) -> Result ---
    154 	image_write_to_file     :: proc(self: ^ImageCore, file_name: cstring, codec: ^ImageCodecCore) -> Result ---
    155 	image_write_to_data     :: proc(self: ^ImageCore, dst: ^ArrayCore, codec: ^ImageCodecCore) -> Result ---
    156 }
    157