Skip to content

Commit 41e7d66

Browse files
authored
Single-line lib definitions (#76)
1 parent 6fe5326 commit 41e7d66

File tree

3 files changed

+123
-129
lines changed

3 files changed

+123
-129
lines changed
+45-47
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,52 @@
1-
module Pluto::Format::Binding
2-
@[Link(ldflags: "-lturbojpeg")]
3-
lib LibJPEGTurbo
4-
alias Handle = Void*
1+
@[Link(ldflags: "-lturbojpeg")]
2+
lib Pluto::Format::Binding::LibJPEGTurbo
3+
alias Handle = Void*
54

6-
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
7-
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
8-
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
9-
fun destroy = tjDestroy(handle : Handle) : LibC::Int
10-
fun free = tjFree(buffer : UInt8*) : Void
11-
fun get_error_code = tjGetErrorCode(handle : Handle) : ErrorCode
12-
fun get_error_str = tjGetErrorStr2(handle : Handle) : UInt8*
13-
fun init_compress = tjInitCompress : Handle
14-
fun init_decompress = tjInitDecompress : Handle
5+
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
6+
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
7+
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
8+
fun destroy = tjDestroy(handle : Handle) : LibC::Int
9+
fun free = tjFree(buffer : UInt8*) : Void
10+
fun get_error_code = tjGetErrorCode(handle : Handle) : ErrorCode
11+
fun get_error_str = tjGetErrorStr2(handle : Handle) : UInt8*
12+
fun init_compress = tjInitCompress : Handle
13+
fun init_decompress = tjInitDecompress : Handle
1514

16-
enum Colorspace
17-
RGB = 0
18-
YCbCr = 1
19-
Gray = 2
20-
CMYK = 3
21-
YCCK = 4
22-
end
15+
enum Colorspace
16+
RGB = 0
17+
YCbCr = 1
18+
Gray = 2
19+
CMYK = 3
20+
YCCK = 4
21+
end
2322

24-
enum PixelFormat
25-
RGB = 0
26-
BGR = 1
27-
RGBX = 2
28-
BGRX = 3
29-
XBGR = 4
30-
XRGB = 5
31-
GRAY = 6
32-
RGBA = 7
33-
BGRA = 8
34-
ABGR = 9
35-
ARGB = 10
36-
CMYK = 11
37-
Unknown = -1
38-
end
23+
enum PixelFormat
24+
RGB = 0
25+
BGR = 1
26+
RGBX = 2
27+
BGRX = 3
28+
XBGR = 4
29+
XRGB = 5
30+
GRAY = 6
31+
RGBA = 7
32+
BGRA = 8
33+
ABGR = 9
34+
ARGB = 10
35+
CMYK = 11
36+
Unknown = -1
37+
end
3938

40-
enum Subsampling
41-
S444 = 0
42-
S422 = 1
43-
S420 = 2
44-
Gray = 3
45-
S440 = 4
46-
S411 = 5
47-
end
39+
enum Subsampling
40+
S444 = 0
41+
S422 = 1
42+
S420 = 2
43+
Gray = 3
44+
S440 = 4
45+
S411 = 5
46+
end
4847

49-
enum ErrorCode
50-
Warning = 1
51-
Fatal = 2
52-
end
48+
enum ErrorCode
49+
Warning = 1
50+
Fatal = 2
5351
end
5452
end

src/pluto/format/binding/lib_spng.cr

+67-69
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,76 @@
1-
module Pluto::Format::Binding
2-
@[Link(ldflags: "-lspng")]
3-
lib LibSPNG
4-
fun ctx_free = spng_ctx_free(ctx : Void*)
5-
fun ctx_new = spng_ctx_new(flags : CtxFlags) : Void*
6-
fun decode_image = spng_decode_image(ctx : Void*, out : Void*, len : LibC::SizeT, fmt : Format, flags : DecodeFlags) : LibC::Int
7-
fun decoded_image_size = spng_decoded_image_size(ctx : Void*, fmt : Format, len : LibC::SizeT*) : LibC::Int
8-
fun encode_chunks = spng_encode_chunks(ctx : Void*) : LibC::Int
9-
fun encode_image = spng_encode_image(ctx : Void*, img : Void*, len : LibC::SizeT, fmt : Format, flags : EncodeFlags) : LibC::Int
10-
fun get_ihdr = spng_get_ihdr(ctx : Void*, ihdr : IHDR*) : LibC::Int
11-
fun get_png_buffer = spng_get_png_buffer(ctx : Void*, len : LibC::SizeT*, error : LibC::Int*) : UInt8*
12-
fun set_ihdr = spng_set_ihdr(ctx : Void*, ihdr : IHDR*) : LibC::Int
13-
fun set_option = spng_set_option(ctx : Void*, option : Option, value : LibC::Int) : LibC::Int
14-
fun set_png_buffer = spng_set_png_buffer(ctx : Void*, buf : Void*, size : LibC::SizeT) : LibC::Int
1+
@[Link(ldflags: "-lspng")]
2+
lib Pluto::Format::Binding::LibSPNG
3+
fun ctx_free = spng_ctx_free(ctx : Void*)
4+
fun ctx_new = spng_ctx_new(flags : CtxFlags) : Void*
5+
fun decode_image = spng_decode_image(ctx : Void*, out : Void*, len : LibC::SizeT, fmt : Format, flags : DecodeFlags) : LibC::Int
6+
fun decoded_image_size = spng_decoded_image_size(ctx : Void*, fmt : Format, len : LibC::SizeT*) : LibC::Int
7+
fun encode_chunks = spng_encode_chunks(ctx : Void*) : LibC::Int
8+
fun encode_image = spng_encode_image(ctx : Void*, img : Void*, len : LibC::SizeT, fmt : Format, flags : EncodeFlags) : LibC::Int
9+
fun get_ihdr = spng_get_ihdr(ctx : Void*, ihdr : IHDR*) : LibC::Int
10+
fun get_png_buffer = spng_get_png_buffer(ctx : Void*, len : LibC::SizeT*, error : LibC::Int*) : UInt8*
11+
fun set_ihdr = spng_set_ihdr(ctx : Void*, ihdr : IHDR*) : LibC::Int
12+
fun set_option = spng_set_option(ctx : Void*, option : Option, value : LibC::Int) : LibC::Int
13+
fun set_png_buffer = spng_set_png_buffer(ctx : Void*, buf : Void*, size : LibC::SizeT) : LibC::Int
1514

16-
enum ColorType : UInt8
17-
Grayscale = 0
18-
TrueColor = 2
19-
Indexed = 3
20-
GrayscaleAlpha = 4
21-
TrueColorAlpha = 6
22-
end
15+
enum ColorType : UInt8
16+
Grayscale = 0
17+
TrueColor = 2
18+
Indexed = 3
19+
GrayscaleAlpha = 4
20+
TrueColorAlpha = 6
21+
end
2322

24-
enum CtxFlags
25-
None = 0
26-
IgnoreAdler32 = 1
27-
Encoder = 2
28-
end
23+
enum CtxFlags
24+
None = 0
25+
IgnoreAdler32 = 1
26+
Encoder = 2
27+
end
2928

30-
enum DecodeFlags
31-
None = 0
32-
TRNS = 1
33-
Gamma = 2
34-
Progressive = 256
35-
end
29+
enum DecodeFlags
30+
None = 0
31+
TRNS = 1
32+
Gamma = 2
33+
Progressive = 256
34+
end
3635

37-
enum EncodeFlags
38-
Progressive = 1
39-
Finalize = 2
40-
end
36+
enum EncodeFlags
37+
Progressive = 1
38+
Finalize = 2
39+
end
4140

42-
enum Format
43-
RGBA8 = 1
44-
RGBA16 = 2
45-
RGB8 = 4
46-
GA8 = 16
47-
GA16 = 32
48-
G8 = 64
49-
PNG = 256
50-
Raw = 512
51-
end
41+
enum Format
42+
RGBA8 = 1
43+
RGBA16 = 2
44+
RGB8 = 4
45+
GA8 = 16
46+
GA16 = 32
47+
G8 = 64
48+
PNG = 256
49+
Raw = 512
50+
end
5251

53-
enum Option
54-
KeepUnknownChunks = 1
55-
ImgCompressionLevel = 2
56-
ImgWindowBits = 3
57-
ImgMemLevel = 4
58-
ImgCompressionStrategy = 5
59-
TextCompressionLevel = 6
60-
TextWindowBits = 7
61-
TextMemLevel = 8
62-
TextCompressionStrategy = 9
63-
FilterChoice = 10
64-
ChunkCountLimit = 11
65-
EncodeToBuffer = 12
66-
end
52+
enum Option
53+
KeepUnknownChunks = 1
54+
ImgCompressionLevel = 2
55+
ImgWindowBits = 3
56+
ImgMemLevel = 4
57+
ImgCompressionStrategy = 5
58+
TextCompressionLevel = 6
59+
TextWindowBits = 7
60+
TextMemLevel = 8
61+
TextCompressionStrategy = 9
62+
FilterChoice = 10
63+
ChunkCountLimit = 11
64+
EncodeToBuffer = 12
65+
end
6766

68-
struct IHDR
69-
width : UInt32
70-
height : UInt32
71-
bit_depth : UInt8
72-
color_type : ColorType
73-
compression_method : UInt8
74-
filter_method : UInt8
75-
interlace_method : UInt8
76-
end
67+
struct IHDR
68+
width : UInt32
69+
height : UInt32
70+
bit_depth : UInt8
71+
color_type : ColorType
72+
compression_method : UInt8
73+
filter_method : UInt8
74+
interlace_method : UInt8
7775
end
7876
end

src/pluto/format/binding/lib_webp.cr

+11-13
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
1-
module Pluto::Format::Binding
2-
{% if flag?(:legacy_webp) %}
3-
@[Link(ldflags: "-lwebp")]
4-
{% else %}
5-
@[Link(ldflags: "-lwebp -lsharpyuv")]
6-
{% end %}
7-
lib LibWebP
8-
fun decode_rgba = WebPDecodeRGBA(data : UInt8*, data_size : LibC::SizeT, width : LibC::Int*, height : LibC::Int*) : UInt8*
9-
fun encode_lossless_rgba = WebPEncodeLosslessRGBA(rgba : UInt8*, width : LibC::Int, height : LibC::Int, stride : LibC::Int, output : UInt8**) : LibC::SizeT
10-
fun encode_rgba = WebPEncodeRGBA(rgba : UInt8*, width : LibC::Int, height : LibC::Int, stride : LibC::Int, quality_factor : LibC::Float, output : UInt8**) : LibC::SizeT
11-
fun free = WebPFree(ptr : Void*)
12-
fun get_info = WebPGetInfo(data : UInt8*, data_size : LibC::SizeT, width : LibC::Int*, height : LibC::Int*) : LibC::Int
13-
end
1+
{% if flag?(:legacy_webp) %}
2+
@[Link(ldflags: "-lwebp")]
3+
{% else %}
4+
@[Link(ldflags: "-lwebp -lsharpyuv")]
5+
{% end %}
6+
lib Pluto::Format::Binding::LibWebP
7+
fun decode_rgba = WebPDecodeRGBA(data : UInt8*, data_size : LibC::SizeT, width : LibC::Int*, height : LibC::Int*) : UInt8*
8+
fun encode_lossless_rgba = WebPEncodeLosslessRGBA(rgba : UInt8*, width : LibC::Int, height : LibC::Int, stride : LibC::Int, output : UInt8**) : LibC::SizeT
9+
fun encode_rgba = WebPEncodeRGBA(rgba : UInt8*, width : LibC::Int, height : LibC::Int, stride : LibC::Int, quality_factor : LibC::Float, output : UInt8**) : LibC::SizeT
10+
fun free = WebPFree(ptr : Void*)
11+
fun get_info = WebPGetInfo(data : UInt8*, data_size : LibC::SizeT, width : LibC::Int*, height : LibC::Int*) : LibC::Int
1412
end

0 commit comments

Comments
 (0)