aboutsummaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorIllusionMan1212 <hisham.abourgheba@gmail.com>2025-01-31 14:34:05 +0200
committerJeroen van Rijn <Kelimion@users.noreply.github.com>2025-09-08 17:13:03 +0200
commit57a92b14cc1621efbf0eef61acf48b1b760917b1 (patch)
treeba4b3cb6ebe278625be9a0fbcdd0f1acce06fa48 /core
parent694593c5f27fd952b1c80917fa27d35023c290b6 (diff)
jpeg: support images that encode zero-based component ids
Diffstat (limited to 'core')
-rw-r--r--core/image/jpeg/jpeg.odin15
1 files changed, 12 insertions, 3 deletions
diff --git a/core/image/jpeg/jpeg.odin b/core/image/jpeg/jpeg.odin
index f675f90e7..d81b2a3ba 100644
--- a/core/image/jpeg/jpeg.odin
+++ b/core/image/jpeg/jpeg.odin
@@ -200,6 +200,7 @@ load_from_context :: proc(ctx: ^$C, options := Options{}, allocator := context.a
img.which = .JPEG
expect_EOI := false
+ zero_based_components := false
huffman: [Coefficient][4]HuffmanTable
quantization: [4]QuantizationTable
color_components: [Component]ColorComponent
@@ -520,12 +521,17 @@ load_from_context :: proc(ctx: ^$C, options := Options{}, allocator := context.a
for _ in 0..<components {
id := cast(Component)compress.read_u8(ctx) or_return
- // TODO: some images write zero-based IDs for the components, which violates the spec, but most (if not all)
- // decoders handle them just fine. Should we support that too?
+ if id == Component(0) {
+ zero_based_components = true
+ }
+
+ if zero_based_components {
+ id += Component(1)
+ }
+
// TODO: while others that use CMYK have these IDs 67, 77, 89, 75 which are CMYK in ASCII
// TODO: even more weird ids. 82, 71, 66 which is RGB in ASCII
if id < .Y || id > .Cr {
- fmt.println("Found unknown component ID:", id)
return img, .Image_Does_Not_Adhere_to_Spec
}
@@ -606,6 +612,9 @@ load_from_context :: proc(ctx: ^$C, options := Options{}, allocator := context.a
for _ in 0..<num_components {
component_id := cast(Component)compress.read_u8(ctx) or_return
+ if zero_based_components {
+ component_id += Component(1)
+ }
if component_id < .Y || component_id > .Cr {
return img, .Image_Does_Not_Adhere_to_Spec
}