The problem is in generation of component data in WriteJP2Image function. After each pixel is generated pointer to next pixel is incremented by one,
Code: Select all
for (x=0; x < (ssize_t) image->columns; x++)
{
for (i=0; i < (ssize_t) channels; i++)
{
double
scale;
register int
*q;
scale=(double) ((1UL << jp2_image->comps[i].prec)-1)/QuantumRange;
q=jp2_image->comps[i].data+(y/jp2_image->comps[i].dy*
image->columns/jp2_image->comps[i].dx+x/jp2_image->comps[i].dx);
switch (i)
{
case 0:
{
if (jp2_colorspace == OPJ_CLRSPC_GRAY)
{
*q=(int) (scale*GetPixelLuma(image,p));
break;
}
*q=(int) (scale*GetPixelRed(image,p));
break;
}
case 1:
{
if (jp2_colorspace == OPJ_CLRSPC_GRAY)
{
*q=(int) (scale*GetPixelAlpha(image,p));
break;
}
*q=(int) (scale*GetPixelGreen(image,p));
break;
}
case 2:
{
*q=(int) (scale*GetPixelBlue(image,p));
break;
}
case 3:
{
*q=(int) (scale*GetPixelAlpha(image,p));
break;
}
}
}
p++;
}
Code: Select all
for (x=0; x < (ssize_t) image->columns; x++)
{
for (i=0; i < (ssize_t) channels; i++)
{
double
scale;
register int
*q;
scale=(double) ((1UL << jp2_image->comps[i].prec)-1)/QuantumRange;
q=jp2_image->comps[i].data+(y/jp2_image->comps[i].dy*
image->columns/jp2_image->comps[i].dx+x/jp2_image->comps[i].dx);
switch (i)
{
case 0:
{
if (jp2_colorspace == OPJ_CLRSPC_GRAY)
{
*q=(int) (scale*GetPixelLuma(image,p));
break;
}
*q=(int) (scale*GetPixelRed(image,p));
break;
}
case 1:
{
if (jp2_colorspace == OPJ_CLRSPC_GRAY)
{
*q=(int) (scale*GetPixelAlpha(image,p));
break;
}
*q=(int) (scale*GetPixelGreen(image,p));
break;
}
case 2:
{
*q=(int) (scale*GetPixelBlue(image,p));
break;
}
case 3:
{
*q=(int) (scale*GetPixelAlpha(image,p));
break;
}
}
}
p += channels;
}