Ticket #19408: patch-jdmarker.c

File patch-jdmarker.c, 1.9 KB (added by master@…, 15 years ago)
Line 
1--- jdmarker.c.org      1998-02-21 23:24:50.000000000 +0300
2+++ jdmarker.2005-12-28 23:48:32.000000000 +0300
3@@ -278,8 +278,27 @@
4   
5   for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
6        ci++, compptr++) {
7+    int component_id;
8+    int j;
9     compptr->component_index = ci;
10-    INPUT_BYTE(cinfo, compptr->component_id, return FALSE);
11+    INPUT_BYTE(cinfo, component_id, return FALSE);
12+    for (j = 0; j < ci; j++) {
13+      /* Check to see whether component id has already been seen
14+        (in violation of the spec, but unfortunately seen in some
15+        files). If so, create "fake" component id equal to the
16+        max id seen so far + 1. */
17+      if (cinfo->comp_info[j].component_id == component_id) {
18+       int max_id = cinfo->comp_info[0].component_id;
19+       int k;
20+       for (k = 1; k < ci; k++) {
21+         int k_id = cinfo->comp_info[k].component_id;
22+         if (k_id > max_id) max_id = k_id;
23+       }
24+       component_id = max_id + 1;
25+       break;
26+      }
27+    }
28+    compptr->component_id = component_id;
29     INPUT_BYTE(cinfo, c, return FALSE);
30     compptr->h_samp_factor = (c >> 4) & 15;
31     compptr->v_samp_factor = (c     ) & 15;
32@@ -323,9 +342,25 @@
33   /* Collect the component-spec parameters */
34 
35   for (i = 0; i < n; i++) {
36+    int j;
37     INPUT_BYTE(cinfo, cc, return FALSE);
38     INPUT_BYTE(cinfo, c, return FALSE);
39-   
40+
41+    /* Detect the case where component id's are not unique, and, if so,
42+       create a fake component id using the same logic as in get_sof. */
43+    for (j = 0; j < i; j++) {
44+      if (cc == cinfo->cur_comp_info[j]->component_id) {
45+       int k;
46+       int max_id = cinfo->cur_comp_info[0]->component_id;
47+       for (k = 1; k < i; k++) {
48+         int k_id = cinfo->cur_comp_info[k]->component_id;
49+         if (k_id > max_id) max_id = k_id;
50+       }
51+       cc = max_id + 1;
52+       break;
53+      }
54+    }
55+
56     for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
57         ci++, compptr++) {
58       if (cc == compptr->component_id)