[trunk] fixed a bug that was preventing image with per channel alpha to decode properly (fixes issue 414)
This commit is contained in:
parent
0a6eaaa605
commit
03a410e03d
|
@ -1124,31 +1124,47 @@ void opj_jp2_apply_cdef(opj_image_t *image, opj_jp2_color_t *color)
|
||||||
{
|
{
|
||||||
/* WATCH: acn = asoc - 1 ! */
|
/* WATCH: acn = asoc - 1 ! */
|
||||||
asoc = info[i].asoc;
|
asoc = info[i].asoc;
|
||||||
|
cn = info[i].cn;
|
||||||
|
|
||||||
|
if( cn >= image->numcomps)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "cn=%d, numcomps=%d\n", cn, image->numcomps);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if(asoc == 0 || asoc == 65535)
|
if(asoc == 0 || asoc == 65535)
|
||||||
{
|
{
|
||||||
if (i < image->numcomps)
|
image->comps[cn].alpha = info[i].typ;
|
||||||
image->comps[i].alpha = info[i].typ;
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
cn = info[i].cn;
|
|
||||||
acn = (OPJ_UINT16)(asoc - 1);
|
acn = (OPJ_UINT16)(asoc - 1);
|
||||||
if( cn >= image->numcomps || acn >= image->numcomps )
|
if( acn >= image->numcomps )
|
||||||
{
|
{
|
||||||
fprintf(stderr, "cn=%d, acn=%d, numcomps=%d\n", cn, acn, image->numcomps);
|
fprintf(stderr, "acn=%d, numcomps=%d\n", acn, image->numcomps);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(cn != acn)
|
/* Swap only if color channel */
|
||||||
|
if((cn != acn) && (info[i].typ == 0))
|
||||||
{
|
{
|
||||||
opj_image_comp_t saved;
|
opj_image_comp_t saved;
|
||||||
|
OPJ_UINT16 j;
|
||||||
|
|
||||||
memcpy(&saved, &image->comps[cn], sizeof(opj_image_comp_t));
|
memcpy(&saved, &image->comps[cn], sizeof(opj_image_comp_t));
|
||||||
memcpy(&image->comps[cn], &image->comps[acn], sizeof(opj_image_comp_t));
|
memcpy(&image->comps[cn], &image->comps[acn], sizeof(opj_image_comp_t));
|
||||||
memcpy(&image->comps[acn], &saved, sizeof(opj_image_comp_t));
|
memcpy(&image->comps[acn], &saved, sizeof(opj_image_comp_t));
|
||||||
|
|
||||||
info[i].asoc = (OPJ_UINT16)(cn + 1);
|
/* Swap channels in following channel definitions, don't bother with j <= i that are already processed */
|
||||||
info[acn].asoc = (OPJ_UINT16)(info[acn].cn + 1);
|
for (j = i + 1; j < n ; ++j)
|
||||||
|
{
|
||||||
|
if (info[j].cn == cn) {
|
||||||
|
info[j].cn = acn;
|
||||||
|
}
|
||||||
|
else if (info[j].cn == acn) {
|
||||||
|
info[j].cn = cn;
|
||||||
|
}
|
||||||
|
/* asoc is related to color index. Do not update. */
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
image->comps[cn].alpha = info[i].typ;
|
image->comps[cn].alpha = info[i].typ;
|
||||||
|
|
Loading…
Reference in New Issue