1diff --git a/third_party/libopenjpeg20/jp2.c b/third_party/libopenjpeg20/jp2.c
2index 47f83a1..6e910a9 100644
3--- a/third_party/libopenjpeg20/jp2.c
4+++ b/third_party/libopenjpeg20/jp2.c
5@@ -902,7 +902,7 @@ static OPJ_BOOL opj_jp2_check_color(opj_image_t *image, opj_jp2_color_t *color,
6 				opj_event_msg(p_manager, EVT_ERROR, "Invalid component/palette index for direct mapping %d.\n", pcol);
7 				is_sane = OPJ_FALSE;
8 			}
9-			else if (pcol_usage[pcol] && cmap[i].mtyp == 1) {
10+			else if (pcol_usage[pcol] && cmap[i].mtyp != 0) {
11 				opj_event_msg(p_manager, EVT_ERROR, "Component %d is mapped twice.\n", pcol);
12 				is_sane = OPJ_FALSE;
13 			}
14@@ -982,8 +982,8 @@ static void opj_jp2_apply_pclr(opj_image_t *image, opj_jp2_color_t *color)
15       assert( pcol == 0 );
16       new_comps[i] = old_comps[cmp];
17     } else {
18-      assert( i == pcol );
19-      new_comps[pcol] = old_comps[cmp];
20+      assert( i == pcol ); // probably wrong?
21+      new_comps[i] = old_comps[cmp];
22     }
23
24 		/* Palette mapping: */
25@@ -1007,11 +1007,11 @@ static void opj_jp2_apply_pclr(opj_image_t *image, opj_jp2_color_t *color)
26 		cmp = cmap[i].cmp; pcol = cmap[i].pcol;
27 		src = old_comps[cmp].data;
28     assert( src );
29-		max = new_comps[pcol].w * new_comps[pcol].h;
30+		max = new_comps[i].w * new_comps[i].h;
31
32 		/* Direct use: */
33     if(cmap[i].mtyp == 0) {
34-      assert( cmp == 0 );
35+      assert( cmp == 0 ); // probably wrong.
36       dst = new_comps[i].data;
37       assert( dst );
38       for(j = 0; j < max; ++j) {
39@@ -1019,8 +1019,8 @@ static void opj_jp2_apply_pclr(opj_image_t *image, opj_jp2_color_t *color)
40       }
41     }
42     else {
43-      assert( i == pcol );
44-      dst = new_comps[pcol].data;
45+      assert( i == pcol ); // probably wrong?
46+      dst = new_comps[i].data;
47       assert( dst );
48       for(j = 0; j < max; ++j) {
49         /* The index */
50