From 2f59e0175eba5efc8c5f1360f3c87e3dc3c20b93 Mon Sep 17 00:00:00 2001 From: Jeroen van Rijn Date: Mon, 8 Sep 2025 17:44:58 +0200 Subject: [PATCH] Address some naming issues --- core/image/jpeg/jpeg.odin | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/core/image/jpeg/jpeg.odin b/core/image/jpeg/jpeg.odin index e67b104e3..6da601c89 100644 --- a/core/image/jpeg/jpeg.odin +++ b/core/image/jpeg/jpeg.odin @@ -31,15 +31,15 @@ Component :: enum u8 { Cr = 3, } -HuffmanTable :: struct { +Huffman_Table :: struct { symbols: [HUFFMAN_MAX_SYMBOLS]byte, codes: [HUFFMAN_MAX_SYMBOLS]u32, offsets: [HUFFMAN_MAX_BITS + 1]byte, } -QuantizationTable :: [COEFFICIENT_COUNT]u16be +Quantization_Table :: [COEFFICIENT_COUNT]u16be -ColorComponent :: struct { +Color_Component :: struct { dc_table_idx: u8, ac_table_idx: u8, quantization_table_idx: u8, @@ -143,7 +143,7 @@ load_from_bytes :: proc(data: []byte, options := Options{}, allocator := context } @(private="file") -get_symbol :: proc(ctx: ^$C, huffman_table: HuffmanTable) -> byte { +get_symbol :: proc(ctx: ^$C, huffman_table: Huffman_Table) -> byte { possible_code: u32 = 0 for i in 0.. image.MAX_DIMENSIONS { + if img.width == 0 || img.height == 0 { return img, .Invalid_Image_Dimensions } + if u128(img.width) * u128(img.height) > image.MAX_DIMENSIONS { + return img, .Image_Dimensions_Too_Large + } + // TODO: Some JPEGs use CMYK as the color model which means there will be 4 components if components != 1 && components != 3 { return img, .Invalid_Number_Of_Channels @@ -919,15 +923,15 @@ load_from_context :: proc(ctx: ^$C, options := Options{}, allocator := context.a for j := BLOCK_SIZE - 1; j >= 0; j -= 1 { for k := BLOCK_SIZE - 1; k >= 0; k -= 1 { i := j * BLOCK_SIZE + k - cbcrPixelRow := j / luma_v_sampling_factor + 4 * v - cbcrPixelColumn := k / luma_h_sampling_factor + 4 * h - cbcrPixel := cbcrPixelRow * BLOCK_SIZE + cbcrPixelColumn + cbcr_pixel_row := j / luma_v_sampling_factor + 4 * v + cbcr_pixel_column := k / luma_h_sampling_factor + 4 * h + cbcr_pixel := cbcr_pixel_row * BLOCK_SIZE + cbcr_pixel_column - r := cast(i16)math.clamp(cast(f32)y_blk[.Y][i] + 1.402 * cast(f32)cbcr_blk[.Cr][cbcrPixel] + 128, 0, 255) - g := cast(i16)math.clamp(cast(f32)y_blk[.Y][i] - 0.344 * cast(f32)cbcr_blk[.Cb][cbcrPixel] - 0.714 * cast(f32)cbcr_blk[.Cr][cbcrPixel] + 128, 0, 255) - b := cast(i16)math.clamp(cast(f32)y_blk[.Y][i] + 1.772 * cast(f32)cbcr_blk[.Cb][cbcrPixel] + 128, 0, 255) + r := cast(i16)math.clamp(cast(f32)y_blk[.Y][i] + 1.402 * cast(f32)cbcr_blk[.Cr][cbcr_pixel] + 128, 0, 255) + g := cast(i16)math.clamp(cast(f32)y_blk[.Y][i] - 0.344 * cast(f32)cbcr_blk[.Cb][cbcr_pixel] - 0.714 * cast(f32)cbcr_blk[.Cr][cbcr_pixel] + 128, 0, 255) + b := cast(i16)math.clamp(cast(f32)y_blk[.Y][i] + 1.772 * cast(f32)cbcr_blk[.Cb][cbcr_pixel] + 128, 0, 255) - y_blk[.Y][i] = r + y_blk[.Y][i] = r y_blk[.Cb][i] = g y_blk[.Cr][i] = b } @@ -1009,4 +1013,4 @@ destroy :: proc(img: ^Image) { @(init, private) _register :: proc "contextless" () { image.register(.JPEG, load_from_bytes, destroy) -} +} \ No newline at end of file