odin-blend2d

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

pixelconverter.odin (3353B)


      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 //! Pixel converter function.
     19 PixelConverterFunc :: proc "c" (self: ^PixelConverterCore, dst_data: ^u8, dst_stride: c.intptr_t, src_data: ^u8, src_stride: c.intptr_t, w: u32, h: u32, options: ^PixelConverterOptions) -> Result
     20 
     21 //! Flags used by `BLPixelConverter::create()` function.
     22 PixelConverterCreateFlags :: enum u32 {
     23 	//! No flags.
     24 	NO_FLAGS               = 0,
     25 
     26 	//! Specifies that the source palette in `BLFormatInfo` doesn't have to by copied by `BLPixelConverter`. The caller
     27 	//! must ensure that the palette would stay valid until the pixel converter is destroyed.
     28 	FLAG_DONT_COPY_PALETTE = 1,
     29 
     30 	//! Specifies that the source palette in `BLFormatInfo` is alterable and the pixel converter can modify it when
     31 	//! preparing the conversion. The modification can be irreversible so only use this flag when you are sure that
     32 	//! the palette passed to `BLPixelConverter::create()` won't be needed outside of pixel conversion.
     33 	//!
     34 	//! \note The flag `BL_PIXEL_CONVERTER_CREATE_FLAG_DONT_COPY_PALETTE` must be set as well, otherwise this flag would
     35 	//! be ignored.
     36 	FLAG_ALTERABLE_PALETTE = 2,
     37 
     38 	//! When there is no built-in conversion between the given pixel formats it's possible to use an intermediate format
     39 	//! that is used during conversion. In such case the base pixel converter creates two more converters that are then
     40 	//! used internally.
     41 	//!
     42 	//! This option disables such feature - creating a pixel converter would fail with `BL_ERROR_NOT_IMPLEMENTED` error
     43 	//! if direct conversion is not possible.
     44 	FLAG_NO_MULTI_STEP     = 4,
     45 	FLAG_FORCE_UINT        = 4294967295,
     46 }
     47 
     48 //! Pixel conversion options.
     49 PixelConverterOptions :: struct {
     50 	origin: PointI,
     51 	gap:    c.size_t,
     52 }
     53 
     54 //! Pixel converter [C API].
     55 PixelConverterCore :: struct {
     56 	using _: struct #raw_union {
     57 		using _: struct {
     58 			//! Converter function.
     59 			convert_func: PixelConverterFunc,
     60 
     61 			//! Internal flags used by the converter - non-zero value means initialized.
     62 			internal_flags: u8,
     63 		},
     64 
     65 		//! Internal data not exposed to users, aligned to sizeof(void*).
     66 		data: [80]u8,
     67 	},
     68 }
     69 
     70 @(default_calling_convention="c", link_prefix="bl_")
     71 foreign lib {
     72 	pixel_converter_init      :: proc(self: ^PixelConverterCore) -> Result ---
     73 	pixel_converter_init_weak :: proc(self: ^PixelConverterCore, other: ^PixelConverterCore) -> Result ---
     74 	pixel_converter_destroy   :: proc(self: ^PixelConverterCore) -> Result ---
     75 	pixel_converter_reset     :: proc(self: ^PixelConverterCore) -> Result ---
     76 	pixel_converter_assign    :: proc(self: ^PixelConverterCore, other: ^PixelConverterCore) -> Result ---
     77 	pixel_converter_create    :: proc(self: ^PixelConverterCore, dst_info: ^FormatInfo, src_info: ^FormatInfo, create_flags: PixelConverterCreateFlags) -> Result ---
     78 	pixel_converter_convert   :: proc(self: ^PixelConverterCore, dst_data: rawptr, dst_stride: c.intptr_t, src_data: rawptr, src_stride: c.intptr_t, w: u32, h: u32, options: ^PixelConverterOptions) -> Result ---
     79 }
     80