Skip to content

Commit

Permalink
Merge branch 'main' into protected
Browse files Browse the repository at this point in the history
  • Loading branch information
snacks02 authored Jul 25, 2024
2 parents 6b82150 + 41e7d66 commit bf66cbc
Show file tree
Hide file tree
Showing 17 changed files with 149 additions and 152 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ jobs:
- run: >
apk add
crystal
git-lfs
libjpeg-turbo
libjpeg-turbo-dev
libspng
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
<picture>
<source
media="(prefers-color-scheme: dark)"
srcset="https://raw.githubusercontent.com/phenopolis/pluto-logo/main/logo-white.png"
srcset="https://media.githubusercontent.com/media/phenopolis/pluto/media/logo-white.png"
/>
<img
alt="logo"
src="https://raw.githubusercontent.com/phenopolis/pluto-logo/main/logo-black.png"
src="https://media.githubusercontent.com/media/phenopolis/pluto/media/logo-black.png"
width="720px"
/>
</picture>
Expand Down
4 changes: 3 additions & 1 deletion shard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ version: 1.0.1
dependencies:
stumpy_core:
github: stumpycr/stumpy_core
version: ~> 1.9

development_dependencies:
ameba:
github: crystal-ameba/ameba
version: ~> 1.6.1
pluto_samples:
github: phenopolis/pluto-samples
github: phenopolis/pluto
branch: samples
stumpy_png:
github: stumpycr/stumpy_png

Expand Down
4 changes: 2 additions & 2 deletions spec/pluto/operation/crop_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ describe Pluto::Operation::Crop do
it "checks image width boundaries" do
image = ga_sample

expect_raises(Exception, "Crop dimensions extend 1 pixels beyond width of the image (640)") do
expect_raises(Pluto::Exception, "Crop dimensions extend 1 pixels beyond width of the image (640)") do
image.crop(0, 0, image.width + 1, image.height)
end
end

it "checks image height boundaries" do
image = ga_sample

expect_raises(Exception, "Crop dimensions extend 1 pixels beyond height of the image (480)") do
expect_raises(Pluto::Exception, "Crop dimensions extend 1 pixels beyond height of the image (480)") do
image.crop(0, 0, image.width, image.height + 1)
end
end
Expand Down
4 changes: 2 additions & 2 deletions spec/pluto/operation/horizontal_blur_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ describe Pluto::Operation::HorizontalBlur do
end

it "doesn't cause arithmetic overload" do
with_sample("problem_images/28_arithmetic_overflow_in_blur.jpeg") do |io|
with_sample("problematic_images/28_arithmetic_overflow_in_blur.jpeg") do |io|
image = Pluto::ImageRGBA.from_jpeg(io)
expect_digest image.horizontal_blur(10), "d1e2b9363a2e7a36e738599cda8dab844a828b15"
end
end

it "doesn't cause arithmetic overload again" do
with_sample("problem_images/46_arithmetic_overflow_in_blur_again.jpeg") do |io|
with_sample("problematic_images/46_arithmetic_overflow_in_blur_again.jpeg") do |io|
image = Pluto::ImageRGBA.from_jpeg(io)
expect_digest image.horizontal_blur(5), "a6ce6aeb78bc3cc6cff8e39f932b3e778b127950"
end
Expand Down
2 changes: 1 addition & 1 deletion spec/pluto/operation/rotation_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ describe Pluto::Operation::Rotation do
it "checks padding and radius" do
image = ga_sample

expect_raises(Exception, "Can't pad image and limit rotation by radius") do
expect_raises(Pluto::Exception, "Can't pad image and limit rotation by radius") do
image.rotation(0, padding: true, radius: 1)
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/pluto/operation/vertical_blur_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe Pluto::Operation::VerticalBlur do
end

it "doesn't cause arithmetic overload" do
with_sample("problem_images/28_arithmetic_overflow_in_blur.jpeg") do |io|
with_sample("problematic_images/28_arithmetic_overflow_in_blur.jpeg") do |io|
image = Pluto::ImageRGBA.from_jpeg(io)
expect_digest image.vertical_blur(10), "00e2c8a20e4554242bca3e0acf841028a2922fe6"
end
Expand Down
92 changes: 45 additions & 47 deletions src/pluto/format/binding/lib_jpeg_turbo.cr
Original file line number Diff line number Diff line change
@@ -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
136 changes: 67 additions & 69 deletions src/pluto/format/binding/lib_spng.cr
Original file line number Diff line number Diff line change
@@ -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
24 changes: 11 additions & 13 deletions src/pluto/format/binding/lib_webp.cr
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion src/pluto/format/jpeg.cr
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ module Pluto::Format::JPEG
message = String.new(Format::Binding::LibJPEGTurbo.get_error_str(handle))
error_code = Format::Binding::LibJPEGTurbo.get_error_code(handle).to_i

raise ::Pluto::Exception.new(message, error_code) unless code == 0
raise Exception.new(message, error_code) unless code == 0
end
end

Expand Down
Loading

0 comments on commit bf66cbc

Please sign in to comment.