Skip to content

Commit

Permalink
Changes in gray-scale 10/12/16bit conversions.
Browse files Browse the repository at this point in the history
  • Loading branch information
novomesk committed Jul 22, 2020
1 parent 20d00e6 commit da279e9
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 40 deletions.
87 changes: 53 additions & 34 deletions src/file-avif-load.c
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,7 @@ GimpImage * load_image ( GFile *file,
const uint16_t *alpha16_src;
const uint16_t *gray16_src;
uint16_t tmpval16,tmp16_alpha;
int tmp_pixelval;

if ( loadlinear )
{
Expand Down Expand Up @@ -502,37 +503,50 @@ GimpImage * load_image ( GFile *file,
alpha16_src = ( const uint16_t * ) ( y * avif->alphaRowBytes + avif->alphaPlane );
for ( x = 0; x < grayimg_width; x++ )
{
if ( avif->depth == 10 ) //10 bit depth
{
tmpval16 = ( *gray16_src ) << 6;
tmp16_alpha = ( *alpha16_src ) << 6;
}
else //12 bit depth
{
tmpval16 = ( *gray16_src ) << 4;
tmp16_alpha = ( *alpha16_src ) << 4;
}
tmpval16 = *gray16_src;
tmp16_alpha = *alpha16_src;
gray16_src++;
alpha16_src++;

if ( avif->yuvRange == AVIF_RANGE_FULL )
if ( avif->depth == 10 ) //10 bit depth
{
*gray16_pixel = tmpval16;
if ( avif->yuvRange == AVIF_RANGE_LIMITED )
{
tmpval16 = avifLimitedToFullY ( 10, tmpval16 );
}

if ( avif->alphaRange == AVIF_RANGE_LIMITED )
{
tmp16_alpha = avifLimitedToFullY ( 10, tmp16_alpha );
}

tmp_pixelval = ( int ) ( ( ( float ) tmpval16 / 1023.0f ) * 65535.0f + 0.5f );
*gray16_pixel = CLAMP ( tmp_pixelval, 0, 65535 );
gray16_pixel++;

tmp_pixelval = ( int ) ( ( ( float ) tmp16_alpha / 1023.0f ) * 65535.0f + 0.5f );
*gray16_pixel = CLAMP ( tmp_pixelval, 0, 65535 );
}
else
else //12 bit depth
{
*gray16_pixel = avifLimitedToFullY ( 16, tmpval16 );
if ( avif->yuvRange == AVIF_RANGE_LIMITED )
{
tmpval16 = avifLimitedToFullY ( 12, tmpval16 );
}

if ( avif->alphaRange == AVIF_RANGE_LIMITED )
{
tmp16_alpha = avifLimitedToFullY ( 12, tmp16_alpha );
}

tmp_pixelval = ( int ) ( ( ( float ) tmpval16 / 4095.0f ) * 65535.0f + 0.5f );
*gray16_pixel = CLAMP ( tmp_pixelval, 0, 65535 );
gray16_pixel++;

tmp_pixelval = ( int ) ( ( ( float ) tmp16_alpha / 4095.0f ) * 65535.0f + 0.5f );
*gray16_pixel = CLAMP ( tmp_pixelval, 0, 65535 );
}
gray16_pixel++;

if ( avif->alphaRange == AVIF_RANGE_FULL )
{
*gray16_pixel = tmp16_alpha;
}
else
{
*gray16_pixel = avifLimitedToFullY ( 16, tmp16_alpha );
}
gray16_pixel++;
}
}
Expand All @@ -552,24 +566,29 @@ GimpImage * load_image ( GFile *file,
gray16_src = ( const uint16_t * ) ( y * avif->yuvRowBytes[0] + avif->yuvPlanes[0] );
for ( x = 0; x < grayimg_width; x++ )
{
tmpval16 = *gray16_src;
gray16_src++;

if ( avif->depth == 10 ) //10 bit depth
{
tmpval16 = ( *gray16_src ) << 6;
if ( avif->yuvRange == AVIF_RANGE_LIMITED )
{
tmpval16 = avifLimitedToFullY ( 10, tmpval16 );
}

tmp_pixelval = ( int ) ( ( ( float ) tmpval16 / 1023.0f ) * 65535.0f + 0.5f );
}
else //12 bit depth
{
tmpval16 = ( *gray16_src ) << 4;
}
gray16_src++;
if ( avif->yuvRange == AVIF_RANGE_LIMITED )
{
tmpval16 = avifLimitedToFullY ( 12, tmpval16 );
}

if ( avif->yuvRange == AVIF_RANGE_FULL )
{
*gray16_pixel = tmpval16;
}
else
{
*gray16_pixel = avifLimitedToFullY ( 16, tmpval16 );
tmp_pixelval = ( int ) ( ( ( float ) tmpval16 / 4095.0f ) * 65535.0f + 0.5f );
}

*gray16_pixel = CLAMP ( tmp_pixelval, 0, 65535 );
gray16_pixel++;

}
Expand Down
19 changes: 13 additions & 6 deletions src/file-avif-save.c
Original file line number Diff line number Diff line change
Expand Up @@ -774,6 +774,7 @@ gboolean save_layer ( GFile *file,
{
const uint16_t *graypixels_src = ( const uint16_t* ) pixels;
uint16_t *graypixels_dest;
int tmp_pixelval;

if ( save_alpha )
{
Expand All @@ -787,11 +788,13 @@ gboolean save_layer ( GFile *file,
alpha_dest = ( uint16_t* ) ( j * avif->alphaRowBytes + avif->alphaPlane );
for ( i = 0; i < drawable_width; ++i )
{
*graypixels_dest = ( *graypixels_src ) >> 6;
tmp_pixelval = ( int ) ( ( ( float ) ( *graypixels_src ) / 65535.0f ) * 1023.0f + 0.5f );
*graypixels_dest = CLAMP ( tmp_pixelval, 0, 1023 );
graypixels_dest++;
graypixels_src++;

*alpha_dest = ( *graypixels_src ) >> 6;
tmp_pixelval = ( int ) ( ( ( float ) ( *graypixels_src ) / 65535.0f ) * 1023.0f + 0.5f );
*alpha_dest = CLAMP ( tmp_pixelval, 0, 1023 );
alpha_dest++;
graypixels_src++;
}
Expand All @@ -805,11 +808,13 @@ gboolean save_layer ( GFile *file,
alpha_dest = ( uint16_t* ) ( j * avif->alphaRowBytes + avif->alphaPlane );
for ( i = 0; i < drawable_width; ++i )
{
*graypixels_dest = ( *graypixels_src ) >> 4;
tmp_pixelval = ( int ) ( ( ( float ) ( *graypixels_src ) / 65535.0f ) * 4095.0f + 0.5f );
*graypixels_dest = CLAMP ( tmp_pixelval, 0, 4095 );
graypixels_dest++;
graypixels_src++;

*alpha_dest = ( *graypixels_src ) >> 4;
tmp_pixelval = ( int ) ( ( ( float ) ( *graypixels_src ) / 65535.0f ) * 4095.0f + 0.5f );
*alpha_dest = CLAMP ( tmp_pixelval, 0, 4095 );
alpha_dest++;
graypixels_src++;
}
Expand All @@ -825,7 +830,8 @@ gboolean save_layer ( GFile *file,
graypixels_dest = ( uint16_t* ) ( j * avif->yuvRowBytes[0] + avif->yuvPlanes[0] );
for ( i = 0; i < drawable_width; ++i )
{
*graypixels_dest = ( *graypixels_src ) >> 6;
tmp_pixelval = ( int ) ( ( ( float ) ( *graypixels_src ) / 65535.0f ) * 1023.0f + 0.5f );
*graypixels_dest = CLAMP ( tmp_pixelval, 0, 1023 );
graypixels_dest++;
graypixels_src++;
}
Expand All @@ -838,7 +844,8 @@ gboolean save_layer ( GFile *file,
graypixels_dest = ( uint16_t* ) ( j * avif->yuvRowBytes[0] + avif->yuvPlanes[0] );
for ( i = 0; i < drawable_width; ++i )
{
*graypixels_dest = ( *graypixels_src ) >> 4;
tmp_pixelval = ( int ) ( ( ( float ) ( *graypixels_src ) / 65535.0f ) * 4095.0f + 0.5f );
*graypixels_dest = CLAMP ( tmp_pixelval, 0, 4095 );
graypixels_dest++;
graypixels_src++;
}
Expand Down

0 comments on commit da279e9

Please sign in to comment.