Skip to content

Commit f81dfc6

Browse files
ilya-fedinjohn-preston
authored andcommitted
Apply jpegli fix for jpegs made on iPhone
1 parent b35735c commit f81dfc6

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed

libjxl.patch

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
diff --git a/lib/jpegli/decode.cc b/lib/jpegli/decode.cc
2+
index bf57115a..8747fc7f 100644
3+
--- a/lib/jpegli/decode.cc
4+
+++ b/lib/jpegli/decode.cc
5+
@@ -54,6 +54,7 @@ void InitializeImage(j_decompress_ptr cinfo) {
6+
m->found_soi_ = false;
7+
m->found_dri_ = false;
8+
m->found_sof_ = false;
9+
+ m->found_sos_ = false;
10+
m->found_eoi_ = false;
11+
m->icc_index_ = 0;
12+
m->icc_total_ = 0;
13+
@@ -243,6 +244,9 @@ void PrepareForScan(j_decompress_ptr cinfo) {
14+
// Copy quantization tables into comp_info.
15+
for (int i = 0; i < cinfo->comps_in_scan; ++i) {
16+
jpeg_component_info* comp = cinfo->cur_comp_info[i];
17+
+ if (cinfo->quant_tbl_ptrs[comp->quant_tbl_no] == nullptr) {
18+
+ JPEGLI_ERROR("Quantization table with index %u not found", comp->quant_tbl_no);
19+
+ }
20+
if (comp->quant_table == nullptr) {
21+
comp->quant_table = Allocate<JQUANT_TBL>(cinfo, 1, JPOOL_IMAGE);
22+
memcpy(comp->quant_table, cinfo->quant_tbl_ptrs[comp->quant_tbl_no],
23+
diff --git a/lib/jpegli/decode_internal.h b/lib/jpegli/decode_internal.h
24+
index ed7baa39..4a06e582 100644
25+
--- a/lib/jpegli/decode_internal.h
26+
+++ b/lib/jpegli/decode_internal.h
27+
@@ -57,6 +57,7 @@ struct jpeg_decomp_master {
28+
bool found_soi_;
29+
bool found_dri_;
30+
bool found_sof_;
31+
+ bool found_sos_;
32+
bool found_eoi_;
33+
size_t icc_index_;
34+
size_t icc_total_;
35+
diff --git a/lib/jpegli/decode_marker.cc b/lib/jpegli/decode_marker.cc
36+
index 6ef2dd4d..eca3596a 100644
37+
--- a/lib/jpegli/decode_marker.cc
38+
+++ b/lib/jpegli/decode_marker.cc
39+
@@ -104,9 +104,6 @@ void ProcessSOF(j_decompress_ptr cinfo, const uint8_t* data, size_t len) {
40+
int quant_tbl_idx = ReadUint8(data, &pos);
41+
JPEG_VERIFY_INPUT(quant_tbl_idx, 0, NUM_QUANT_TBLS - 1);
42+
comp->quant_tbl_no = quant_tbl_idx;
43+
- if (cinfo->quant_tbl_ptrs[quant_tbl_idx] == nullptr) {
44+
- JPEGLI_ERROR("Quantization table with index %u not found", quant_tbl_idx);
45+
- }
46+
comp->quant_table = nullptr; // will be allocated after SOS marker
47+
}
48+
JPEG_VERIFY_MARKER_END();
49+
@@ -169,6 +166,7 @@ void ProcessSOS(j_decompress_ptr cinfo, const uint8_t* data, size_t len) {
50+
if (!m->found_sof_) {
51+
JPEGLI_ERROR("Unexpected SOS marker.");
52+
}
53+
+ m->found_sos_ = true;
54+
size_t pos = 2;
55+
JPEG_VERIFY_LEN(1);
56+
cinfo->comps_in_scan = ReadUint8(data, &pos);
57+
@@ -339,7 +337,7 @@ void ProcessDHT(j_decompress_ptr cinfo, const uint8_t* data, size_t len) {
58+
59+
void ProcessDQT(j_decompress_ptr cinfo, const uint8_t* data, size_t len) {
60+
jpeg_decomp_master* m = cinfo->master;
61+
- if (m->found_sof_) {
62+
+ if (m->found_sos_) {
63+
JPEGLI_ERROR("Updating quant tables between scans is not supported.");
64+
}
65+
size_t pos = 2;

0 commit comments

Comments
 (0)