From 41e7d66835fe6c21d7e21b08b23c380ed454adf2 Mon Sep 17 00:00:00 2001 From: Andrei Zhigalkin <41530422+snacks02@users.noreply.github.com> Date: Thu, 25 Jul 2024 19:51:09 +0500 Subject: [PATCH] Single-line `lib` definitions (#76) --- src/pluto/format/binding/lib_jpeg_turbo.cr | 92 +++++++------- src/pluto/format/binding/lib_spng.cr | 136 ++++++++++----------- src/pluto/format/binding/lib_webp.cr | 24 ++-- 3 files changed, 123 insertions(+), 129 deletions(-) diff --git a/src/pluto/format/binding/lib_jpeg_turbo.cr b/src/pluto/format/binding/lib_jpeg_turbo.cr index b1ce316..c9231a3 100644 --- a/src/pluto/format/binding/lib_jpeg_turbo.cr +++ b/src/pluto/format/binding/lib_jpeg_turbo.cr @@ -1,54 +1,52 @@ -module Pluto::Format::Binding - @[Link(ldflags: "-lturbojpeg")] - lib LibJPEGTurbo - alias Handle = Void* +@[Link(ldflags: "-lturbojpeg")] +lib Pluto::Format::Binding::LibJPEGTurbo + alias Handle = Void* - fun compress2 = tjCompress2(handle : Handle, src_buf : UInt8*, width : LibC::Int, pitch : LibC::Int, height : LibC::Int, pixel_format : PixelFormat, jpeg_buf : UInt8**, jpeg_size : LibC::ULong*, jpeg_subsamp : Subsampling, jpeg_qual : LibC::Int, flags : LibC::Int) : LibC::Int - fun decompress_header3 = tjDecompressHeader3(handle : Handle, jpeg_buf : UInt8*, jpeg_size : LibC::ULong, width : LibC::Int*, height : LibC::Int*, jpeg_subsamp : Subsampling*, jpeg_colorspace : Colorspace*) : LibC::Int - fun decompress2 = tjDecompress2(handle : Handle, jpeg_buf : UInt8*, jpeg_size : LibC::ULong, dst_buf : UInt8*, width : LibC::Int, pitch : LibC::Int, height : LibC::Int, pixel_format : PixelFormat, flags : LibC::Int) : LibC::Int - fun destroy = tjDestroy(handle : Handle) : LibC::Int - fun free = tjFree(buffer : UInt8*) : Void - fun get_error_code = tjGetErrorCode(handle : Handle) : ErrorCode - fun get_error_str = tjGetErrorStr2(handle : Handle) : UInt8* - fun init_compress = tjInitCompress : Handle - fun init_decompress = tjInitDecompress : Handle + fun compress2 = tjCompress2(handle : Handle, src_buf : UInt8*, width : LibC::Int, pitch : LibC::Int, height : LibC::Int, pixel_format : PixelFormat, jpeg_buf : UInt8**, jpeg_size : LibC::ULong*, jpeg_subsamp : Subsampling, jpeg_qual : LibC::Int, flags : LibC::Int) : LibC::Int + fun decompress_header3 = tjDecompressHeader3(handle : Handle, jpeg_buf : UInt8*, jpeg_size : LibC::ULong, width : LibC::Int*, height : LibC::Int*, jpeg_subsamp : Subsampling*, jpeg_colorspace : Colorspace*) : LibC::Int + fun decompress2 = tjDecompress2(handle : Handle, jpeg_buf : UInt8*, jpeg_size : LibC::ULong, dst_buf : UInt8*, width : LibC::Int, pitch : LibC::Int, height : LibC::Int, pixel_format : PixelFormat, flags : LibC::Int) : LibC::Int + fun destroy = tjDestroy(handle : Handle) : LibC::Int + fun free = tjFree(buffer : UInt8*) : Void + fun get_error_code = tjGetErrorCode(handle : Handle) : ErrorCode + fun get_error_str = tjGetErrorStr2(handle : Handle) : UInt8* + fun init_compress = tjInitCompress : Handle + fun init_decompress = tjInitDecompress : Handle - enum Colorspace - RGB = 0 - YCbCr = 1 - Gray = 2 - CMYK = 3 - YCCK = 4 - end + enum Colorspace + RGB = 0 + YCbCr = 1 + Gray = 2 + CMYK = 3 + YCCK = 4 + end - enum PixelFormat - RGB = 0 - BGR = 1 - RGBX = 2 - BGRX = 3 - XBGR = 4 - XRGB = 5 - GRAY = 6 - RGBA = 7 - BGRA = 8 - ABGR = 9 - ARGB = 10 - CMYK = 11 - Unknown = -1 - end + enum PixelFormat + RGB = 0 + BGR = 1 + RGBX = 2 + BGRX = 3 + XBGR = 4 + XRGB = 5 + GRAY = 6 + RGBA = 7 + BGRA = 8 + ABGR = 9 + ARGB = 10 + CMYK = 11 + Unknown = -1 + end - enum Subsampling - S444 = 0 - S422 = 1 - S420 = 2 - Gray = 3 - S440 = 4 - S411 = 5 - end + enum Subsampling + S444 = 0 + S422 = 1 + S420 = 2 + Gray = 3 + S440 = 4 + S411 = 5 + end - enum ErrorCode - Warning = 1 - Fatal = 2 - end + enum ErrorCode + Warning = 1 + Fatal = 2 end end diff --git a/src/pluto/format/binding/lib_spng.cr b/src/pluto/format/binding/lib_spng.cr index cf0a86c..7c58d57 100644 --- a/src/pluto/format/binding/lib_spng.cr +++ b/src/pluto/format/binding/lib_spng.cr @@ -1,78 +1,76 @@ -module Pluto::Format::Binding - @[Link(ldflags: "-lspng")] - lib LibSPNG - fun ctx_free = spng_ctx_free(ctx : Void*) - fun ctx_new = spng_ctx_new(flags : CtxFlags) : Void* - fun decode_image = spng_decode_image(ctx : Void*, out : Void*, len : LibC::SizeT, fmt : Format, flags : DecodeFlags) : LibC::Int - fun decoded_image_size = spng_decoded_image_size(ctx : Void*, fmt : Format, len : LibC::SizeT*) : LibC::Int - fun encode_chunks = spng_encode_chunks(ctx : Void*) : LibC::Int - fun encode_image = spng_encode_image(ctx : Void*, img : Void*, len : LibC::SizeT, fmt : Format, flags : EncodeFlags) : LibC::Int - fun get_ihdr = spng_get_ihdr(ctx : Void*, ihdr : IHDR*) : LibC::Int - fun get_png_buffer = spng_get_png_buffer(ctx : Void*, len : LibC::SizeT*, error : LibC::Int*) : UInt8* - fun set_ihdr = spng_set_ihdr(ctx : Void*, ihdr : IHDR*) : LibC::Int - fun set_option = spng_set_option(ctx : Void*, option : Option, value : LibC::Int) : LibC::Int - fun set_png_buffer = spng_set_png_buffer(ctx : Void*, buf : Void*, size : LibC::SizeT) : LibC::Int +@[Link(ldflags: "-lspng")] +lib Pluto::Format::Binding::LibSPNG + fun ctx_free = spng_ctx_free(ctx : Void*) + fun ctx_new = spng_ctx_new(flags : CtxFlags) : Void* + fun decode_image = spng_decode_image(ctx : Void*, out : Void*, len : LibC::SizeT, fmt : Format, flags : DecodeFlags) : LibC::Int + fun decoded_image_size = spng_decoded_image_size(ctx : Void*, fmt : Format, len : LibC::SizeT*) : LibC::Int + fun encode_chunks = spng_encode_chunks(ctx : Void*) : LibC::Int + fun encode_image = spng_encode_image(ctx : Void*, img : Void*, len : LibC::SizeT, fmt : Format, flags : EncodeFlags) : LibC::Int + fun get_ihdr = spng_get_ihdr(ctx : Void*, ihdr : IHDR*) : LibC::Int + fun get_png_buffer = spng_get_png_buffer(ctx : Void*, len : LibC::SizeT*, error : LibC::Int*) : UInt8* + fun set_ihdr = spng_set_ihdr(ctx : Void*, ihdr : IHDR*) : LibC::Int + fun set_option = spng_set_option(ctx : Void*, option : Option, value : LibC::Int) : LibC::Int + fun set_png_buffer = spng_set_png_buffer(ctx : Void*, buf : Void*, size : LibC::SizeT) : LibC::Int - enum ColorType : UInt8 - Grayscale = 0 - TrueColor = 2 - Indexed = 3 - GrayscaleAlpha = 4 - TrueColorAlpha = 6 - end + enum ColorType : UInt8 + Grayscale = 0 + TrueColor = 2 + Indexed = 3 + GrayscaleAlpha = 4 + TrueColorAlpha = 6 + end - enum CtxFlags - None = 0 - IgnoreAdler32 = 1 - Encoder = 2 - end + enum CtxFlags + None = 0 + IgnoreAdler32 = 1 + Encoder = 2 + end - enum DecodeFlags - None = 0 - TRNS = 1 - Gamma = 2 - Progressive = 256 - end + enum DecodeFlags + None = 0 + TRNS = 1 + Gamma = 2 + Progressive = 256 + end - enum EncodeFlags - Progressive = 1 - Finalize = 2 - end + enum EncodeFlags + Progressive = 1 + Finalize = 2 + end - enum Format - RGBA8 = 1 - RGBA16 = 2 - RGB8 = 4 - GA8 = 16 - GA16 = 32 - G8 = 64 - PNG = 256 - Raw = 512 - end + enum Format + RGBA8 = 1 + RGBA16 = 2 + RGB8 = 4 + GA8 = 16 + GA16 = 32 + G8 = 64 + PNG = 256 + Raw = 512 + end - enum Option - KeepUnknownChunks = 1 - ImgCompressionLevel = 2 - ImgWindowBits = 3 - ImgMemLevel = 4 - ImgCompressionStrategy = 5 - TextCompressionLevel = 6 - TextWindowBits = 7 - TextMemLevel = 8 - TextCompressionStrategy = 9 - FilterChoice = 10 - ChunkCountLimit = 11 - EncodeToBuffer = 12 - end + enum Option + KeepUnknownChunks = 1 + ImgCompressionLevel = 2 + ImgWindowBits = 3 + ImgMemLevel = 4 + ImgCompressionStrategy = 5 + TextCompressionLevel = 6 + TextWindowBits = 7 + TextMemLevel = 8 + TextCompressionStrategy = 9 + FilterChoice = 10 + ChunkCountLimit = 11 + EncodeToBuffer = 12 + end - struct IHDR - width : UInt32 - height : UInt32 - bit_depth : UInt8 - color_type : ColorType - compression_method : UInt8 - filter_method : UInt8 - interlace_method : UInt8 - end + struct IHDR + width : UInt32 + height : UInt32 + bit_depth : UInt8 + color_type : ColorType + compression_method : UInt8 + filter_method : UInt8 + interlace_method : UInt8 end end diff --git a/src/pluto/format/binding/lib_webp.cr b/src/pluto/format/binding/lib_webp.cr index 17c3125..bc7e5db 100644 --- a/src/pluto/format/binding/lib_webp.cr +++ b/src/pluto/format/binding/lib_webp.cr @@ -1,14 +1,12 @@ -module Pluto::Format::Binding - {% if flag?(:legacy_webp) %} - @[Link(ldflags: "-lwebp")] - {% else %} - @[Link(ldflags: "-lwebp -lsharpyuv")] - {% end %} - lib LibWebP - fun decode_rgba = WebPDecodeRGBA(data : UInt8*, data_size : LibC::SizeT, width : LibC::Int*, height : LibC::Int*) : UInt8* - fun encode_lossless_rgba = WebPEncodeLosslessRGBA(rgba : UInt8*, width : LibC::Int, height : LibC::Int, stride : LibC::Int, output : UInt8**) : LibC::SizeT - fun encode_rgba = WebPEncodeRGBA(rgba : UInt8*, width : LibC::Int, height : LibC::Int, stride : LibC::Int, quality_factor : LibC::Float, output : UInt8**) : LibC::SizeT - fun free = WebPFree(ptr : Void*) - fun get_info = WebPGetInfo(data : UInt8*, data_size : LibC::SizeT, width : LibC::Int*, height : LibC::Int*) : LibC::Int - end +{% if flag?(:legacy_webp) %} + @[Link(ldflags: "-lwebp")] +{% else %} + @[Link(ldflags: "-lwebp -lsharpyuv")] +{% end %} +lib Pluto::Format::Binding::LibWebP + fun decode_rgba = WebPDecodeRGBA(data : UInt8*, data_size : LibC::SizeT, width : LibC::Int*, height : LibC::Int*) : UInt8* + fun encode_lossless_rgba = WebPEncodeLosslessRGBA(rgba : UInt8*, width : LibC::Int, height : LibC::Int, stride : LibC::Int, output : UInt8**) : LibC::SizeT + fun encode_rgba = WebPEncodeRGBA(rgba : UInt8*, width : LibC::Int, height : LibC::Int, stride : LibC::Int, quality_factor : LibC::Float, output : UInt8**) : LibC::SizeT + fun free = WebPFree(ptr : Void*) + fun get_info = WebPGetInfo(data : UInt8*, data_size : LibC::SizeT, width : LibC::Int*, height : LibC::Int*) : LibC::Int end