1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 05:37:43 +00:00

LibGfx/JPEG: Use more explicit types and add a bunch of const

This commit is contained in:
Lucas CHOLLET 2023-04-21 20:28:18 -04:00 committed by Andreas Kling
parent 83b87a5ade
commit 0d3b62cbb7

View file

@ -1076,27 +1076,25 @@ static ErrorOr<void> read_start_of_frame(Stream& stream, JPEGLoadingContext& con
static ErrorOr<void> read_quantization_table(Stream& stream, JPEGLoadingContext& context) static ErrorOr<void> read_quantization_table(Stream& stream, JPEGLoadingContext& context)
{ {
i32 bytes_to_read = TRY(stream.read_value<BigEndian<u16>>()) - 2; u16 bytes_to_read = TRY(stream.read_value<BigEndian<u16>>()) - 2;
while (bytes_to_read > 0) { while (bytes_to_read > 0) {
u8 info_byte = TRY(stream.read_value<u8>()); u8 const info_byte = TRY(stream.read_value<u8>());
u8 element_unit_hint = info_byte >> 4; u8 const element_unit_hint = info_byte >> 4;
if (element_unit_hint > 1) { if (element_unit_hint > 1) {
dbgln_if(JPEG_DEBUG, "Unsupported unit hint in quantization table: {}!", element_unit_hint); dbgln_if(JPEG_DEBUG, "Unsupported unit hint in quantization table: {}!", element_unit_hint);
return Error::from_string_literal("Unsupported unit hint in quantization table"); return Error::from_string_literal("Unsupported unit hint in quantization table");
} }
u8 table_id = info_byte & 0x0F; u8 const table_id = info_byte & 0x0F;
if (table_id > 1) { if (table_id > 1) {
dbgln_if(JPEG_DEBUG, "Unsupported quantization table id: {}!", table_id); dbgln_if(JPEG_DEBUG, "Unsupported quantization table id: {}!", table_id);
return Error::from_string_literal("Unsupported quantization table id"); return Error::from_string_literal("Unsupported quantization table id");
} }
u32* table = table_id == 0 ? context.luma_table : context.chroma_table; u32* const table = table_id == 0 ? context.luma_table : context.chroma_table;
for (int i = 0; i < 64; i++) { for (int i = 0; i < 64; i++) {
if (element_unit_hint == 0) { if (element_unit_hint == 0)
u8 tmp = TRY(stream.read_value<u8>()); table[zigzag_map[i]] = TRY(stream.read_value<u8>());
table[zigzag_map[i]] = tmp; else
} else {
table[zigzag_map[i]] = TRY(stream.read_value<BigEndian<u16>>()); table[zigzag_map[i]] = TRY(stream.read_value<BigEndian<u16>>());
}
} }
bytes_to_read -= 1 + (element_unit_hint == 0 ? 64 : 128); bytes_to_read -= 1 + (element_unit_hint == 0 ? 64 : 128);