|
|
|
@ -1607,6 +1607,8 @@ static void stbir__encode_scanline(stbir__info* stbir_info, int num_pixels, void |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#define STBIR__ROUND_INT(f) ((int) ((f)+0.5)) //#define STBIR__ROUND_INT(f) (floor((f)+0.5))
|
|
|
|
|
|
|
|
|
|
switch (decode) |
|
|
|
|
{ |
|
|
|
|
case STBIR__DECODE(STBIR_TYPE_UINT8, STBIR_COLORSPACE_LINEAR): |
|
|
|
@ -1617,7 +1619,7 @@ static void stbir__encode_scanline(stbir__info* stbir_info, int num_pixels, void |
|
|
|
|
for (n = 0; n < channels; n++) |
|
|
|
|
{ |
|
|
|
|
int index = pixel_index + n; |
|
|
|
|
((unsigned char*)output_buffer)[index] = (unsigned char)(floor(stbir__saturate(encode_buffer[index]) * 255 + 0.5f)); |
|
|
|
|
((unsigned char*)output_buffer)[index] = (unsigned char) STBIR__ROUND_INT(stbir__saturate(encode_buffer[index]) * 255); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
@ -1634,7 +1636,7 @@ static void stbir__encode_scanline(stbir__info* stbir_info, int num_pixels, void |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (!(stbir_info->flags&STBIR_FLAG_ALPHA_USES_COLORSPACE)) |
|
|
|
|
((unsigned char*)output_buffer)[pixel_index + alpha_channel] = (unsigned char)(floor(stbir__saturate(encode_buffer[pixel_index + alpha_channel]) * 255+0.5f)); |
|
|
|
|
((unsigned char*)output_buffer)[pixel_index + alpha_channel] = (unsigned char) STBIR__ROUND_INT(stbir__saturate(encode_buffer[pixel_index + alpha_channel]) * 255); |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
|
|
|
|
@ -1646,7 +1648,7 @@ static void stbir__encode_scanline(stbir__info* stbir_info, int num_pixels, void |
|
|
|
|
for (n = 0; n < channels; n++) |
|
|
|
|
{ |
|
|
|
|
int index = pixel_index + n; |
|
|
|
|
((unsigned short*)output_buffer)[index] = (unsigned short)(floor(stbir__saturate(encode_buffer[index]) * 65535+0.5f)); |
|
|
|
|
((unsigned short*)output_buffer)[index] = (unsigned short)STBIR__ROUND_INT(stbir__saturate(encode_buffer[index]) * 65535); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
@ -1659,11 +1661,11 @@ static void stbir__encode_scanline(stbir__info* stbir_info, int num_pixels, void |
|
|
|
|
for (n = 0; n < channels; n++) |
|
|
|
|
{ |
|
|
|
|
int index = pixel_index + n; |
|
|
|
|
((unsigned short*)output_buffer)[index] = (unsigned short)(floor(stbir__linear_to_srgb(stbir__saturate(encode_buffer[index])) * 65535 + 0.5f)); |
|
|
|
|
((unsigned short*)output_buffer)[index] = (unsigned short)STBIR__ROUND_INT(stbir__linear_to_srgb(stbir__saturate(encode_buffer[index])) * 65535); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (!(stbir_info->flags&STBIR_FLAG_ALPHA_USES_COLORSPACE)) |
|
|
|
|
((unsigned short*)output_buffer)[pixel_index + alpha_channel] = (unsigned short)(floor(stbir__saturate(encode_buffer[pixel_index + alpha_channel]) * 65535 + 0.5f)); |
|
|
|
|
((unsigned short*)output_buffer)[pixel_index + alpha_channel] = (unsigned short)STBIR__ROUND_INT(stbir__saturate(encode_buffer[pixel_index + alpha_channel]) * 65535); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
break; |
|
|
|
@ -1676,7 +1678,7 @@ static void stbir__encode_scanline(stbir__info* stbir_info, int num_pixels, void |
|
|
|
|
for (n = 0; n < channels; n++) |
|
|
|
|
{ |
|
|
|
|
int index = pixel_index + n; |
|
|
|
|
((unsigned int*)output_buffer)[index] = (unsigned int)(floor(((double)stbir__saturate(encode_buffer[index])) * 4294967295 + 0.5f)); |
|
|
|
|
((unsigned int*)output_buffer)[index] = (unsigned int)STBIR__ROUND_INT(((double)stbir__saturate(encode_buffer[index])) * 4294967295); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
@ -1689,11 +1691,11 @@ static void stbir__encode_scanline(stbir__info* stbir_info, int num_pixels, void |
|
|
|
|
for (n = 0; n < channels; n++) |
|
|
|
|
{ |
|
|
|
|
int index = pixel_index + n; |
|
|
|
|
((unsigned int*)output_buffer)[index] = (unsigned int)(floor(((double)stbir__linear_to_srgb(stbir__saturate(encode_buffer[index]))) * 4294967295 + 0.5f)); |
|
|
|
|
((unsigned int*)output_buffer)[index] = (unsigned int)STBIR__ROUND_INT(((double)stbir__linear_to_srgb(stbir__saturate(encode_buffer[index]))) * 4294967295); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (!(stbir_info->flags&STBIR_FLAG_ALPHA_USES_COLORSPACE)) |
|
|
|
|
((unsigned int*)output_buffer)[pixel_index + alpha_channel] = (unsigned int)(floor(((double)stbir__saturate(encode_buffer[pixel_index + alpha_channel])) * 4294967295 + 0.5f)); |
|
|
|
|
((unsigned int*)output_buffer)[pixel_index + alpha_channel] = (unsigned int)STBIR__ROUND_INT(((double)stbir__saturate(encode_buffer[pixel_index + alpha_channel])) * 4294967295); |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|