@ -65,13 +65,18 @@ internal class PlainDecoder
using IMemoryOwner < L8 > row = allocator . Allocate < L8 > ( width ) ;
using IMemoryOwner < L8 > row = allocator . Allocate < L8 > ( width ) ;
Span < L8 > rowSpan = row . GetSpan ( ) ;
Span < L8 > rowSpan = row . GetSpan ( ) ;
bool eofReached = false ;
for ( int y = 0 ; y < height ; y + + )
for ( int y = 0 ; y < height ; y + + )
{
{
for ( int x = 0 ; x < width ; x + + )
for ( int x = 0 ; x < width ; x + + )
{
{
byte value = ( byte ) stream . ReadDecimal ( ) ;
stream . TryReadDecimal ( out int value ) ;
stream . SkipWhitespaceAndComments ( ) ;
rowSpan [ x ] = new L8 ( ( byte ) value ) ;
rowSpan [ x ] = new L8 ( value ) ;
eofReached = ! stream . TrySkipWhitespaceAndComments ( ) ;
if ( eofReached )
{
break ;
}
}
}
Span < TPixel > pixelSpan = pixels . DangerousGetRowSpan ( y ) ;
Span < TPixel > pixelSpan = pixels . DangerousGetRowSpan ( y ) ;
@ -79,6 +84,11 @@ internal class PlainDecoder
configuration ,
configuration ,
rowSpan ,
rowSpan ,
pixelSpan ) ;
pixelSpan ) ;
if ( eofReached )
{
return ;
}
}
}
}
}
@ -91,13 +101,18 @@ internal class PlainDecoder
using IMemoryOwner < L16 > row = allocator . Allocate < L16 > ( width ) ;
using IMemoryOwner < L16 > row = allocator . Allocate < L16 > ( width ) ;
Span < L16 > rowSpan = row . GetSpan ( ) ;
Span < L16 > rowSpan = row . GetSpan ( ) ;
bool eofReached = false ;
for ( int y = 0 ; y < height ; y + + )
for ( int y = 0 ; y < height ; y + + )
{
{
for ( int x = 0 ; x < width ; x + + )
for ( int x = 0 ; x < width ; x + + )
{
{
ushort value = ( ushort ) stream . ReadDecimal ( ) ;
stream . TryReadDecimal ( out int value ) ;
stream . SkipWhitespaceAndComments ( ) ;
rowSpan [ x ] = new L16 ( ( ushort ) value ) ;
rowSpan [ x ] = new L16 ( value ) ;
eofReached = ! stream . TrySkipWhitespaceAndComments ( ) ;
if ( eofReached )
{
break ;
}
}
}
Span < TPixel > pixelSpan = pixels . DangerousGetRowSpan ( y ) ;
Span < TPixel > pixelSpan = pixels . DangerousGetRowSpan ( y ) ;
@ -105,6 +120,11 @@ internal class PlainDecoder
configuration ,
configuration ,
rowSpan ,
rowSpan ,
pixelSpan ) ;
pixelSpan ) ;
if ( eofReached )
{
return ;
}
}
}
}
}
@ -117,17 +137,29 @@ internal class PlainDecoder
using IMemoryOwner < Rgb24 > row = allocator . Allocate < Rgb24 > ( width ) ;
using IMemoryOwner < Rgb24 > row = allocator . Allocate < Rgb24 > ( width ) ;
Span < Rgb24 > rowSpan = row . GetSpan ( ) ;
Span < Rgb24 > rowSpan = row . GetSpan ( ) ;
bool eofReached = false ;
for ( int y = 0 ; y < height ; y + + )
for ( int y = 0 ; y < height ; y + + )
{
{
for ( int x = 0 ; x < width ; x + + )
for ( int x = 0 ; x < width ; x + + )
{
{
byte red = ( byte ) stream . ReadDecimal ( ) ;
if ( ! stream . TryReadDecimal ( out int red ) | |
stream . SkipWhitespaceAndComments ( ) ;
! stream . TrySkipWhitespaceAndComments ( ) | |
byte green = ( byte ) stream . ReadDecimal ( ) ;
! stream . TryReadDecimal ( out int green ) | |
stream . SkipWhitespaceAndComments ( ) ;
! stream . TrySkipWhitespaceAndComments ( ) )
byte blue = ( byte ) stream . ReadDecimal ( ) ;
{
stream . SkipWhitespaceAndComments ( ) ;
// Reached EOF before reading a full RGB value
rowSpan [ x ] = new Rgb24 ( red , green , blue ) ;
eofReached = true ;
break ;
}
stream . TryReadDecimal ( out int blue ) ;
rowSpan [ x ] = new Rgb24 ( ( byte ) red , ( byte ) green , ( byte ) blue ) ;
eofReached = ! stream . TrySkipWhitespaceAndComments ( ) ;
if ( eofReached )
{
break ;
}
}
}
Span < TPixel > pixelSpan = pixels . DangerousGetRowSpan ( y ) ;
Span < TPixel > pixelSpan = pixels . DangerousGetRowSpan ( y ) ;
@ -135,6 +167,11 @@ internal class PlainDecoder
configuration ,
configuration ,
rowSpan ,
rowSpan ,
pixelSpan ) ;
pixelSpan ) ;
if ( eofReached )
{
return ;
}
}
}
}
}
@ -147,17 +184,29 @@ internal class PlainDecoder
using IMemoryOwner < Rgb48 > row = allocator . Allocate < Rgb48 > ( width ) ;
using IMemoryOwner < Rgb48 > row = allocator . Allocate < Rgb48 > ( width ) ;
Span < Rgb48 > rowSpan = row . GetSpan ( ) ;
Span < Rgb48 > rowSpan = row . GetSpan ( ) ;
bool eofReached = false ;
for ( int y = 0 ; y < height ; y + + )
for ( int y = 0 ; y < height ; y + + )
{
{
for ( int x = 0 ; x < width ; x + + )
for ( int x = 0 ; x < width ; x + + )
{
{
ushort red = ( ushort ) stream . ReadDecimal ( ) ;
if ( ! stream . TryReadDecimal ( out int red ) | |
stream . SkipWhitespaceAndComments ( ) ;
! stream . TrySkipWhitespaceAndComments ( ) | |
ushort green = ( ushort ) stream . ReadDecimal ( ) ;
! stream . TryReadDecimal ( out int green ) | |
stream . SkipWhitespaceAndComments ( ) ;
! stream . TrySkipWhitespaceAndComments ( ) )
ushort blue = ( ushort ) stream . ReadDecimal ( ) ;
{
stream . SkipWhitespaceAndComments ( ) ;
// Reached EOF before reading a full RGB value
rowSpan [ x ] = new Rgb48 ( red , green , blue ) ;
eofReached = true ;
break ;
}
stream . TryReadDecimal ( out int blue ) ;
rowSpan [ x ] = new Rgb48 ( ( ushort ) red , ( ushort ) green , ( ushort ) blue ) ;
eofReached = ! stream . TrySkipWhitespaceAndComments ( ) ;
if ( eofReached )
{
break ;
}
}
}
Span < TPixel > pixelSpan = pixels . DangerousGetRowSpan ( y ) ;
Span < TPixel > pixelSpan = pixels . DangerousGetRowSpan ( y ) ;
@ -165,6 +214,11 @@ internal class PlainDecoder
configuration ,
configuration ,
rowSpan ,
rowSpan ,
pixelSpan ) ;
pixelSpan ) ;
if ( eofReached )
{
return ;
}
}
}
}
}
@ -177,13 +231,19 @@ internal class PlainDecoder
using IMemoryOwner < L8 > row = allocator . Allocate < L8 > ( width ) ;
using IMemoryOwner < L8 > row = allocator . Allocate < L8 > ( width ) ;
Span < L8 > rowSpan = row . GetSpan ( ) ;
Span < L8 > rowSpan = row . GetSpan ( ) ;
bool eofReached = false ;
for ( int y = 0 ; y < height ; y + + )
for ( int y = 0 ; y < height ; y + + )
{
{
for ( int x = 0 ; x < width ; x + + )
for ( int x = 0 ; x < width ; x + + )
{
{
int value = stream . ReadDecimal ( ) ;
stream . TryReadDecimal ( out int value ) ;
stream . SkipWhitespaceAndComments ( ) ;
rowSpan [ x ] = value = = 0 ? White : Black ;
rowSpan [ x ] = value = = 0 ? White : Black ;
eofReached = ! stream . TrySkipWhitespaceAndComments ( ) ;
if ( eofReached )
{
break ;
}
}
}
Span < TPixel > pixelSpan = pixels . DangerousGetRowSpan ( y ) ;
Span < TPixel > pixelSpan = pixels . DangerousGetRowSpan ( y ) ;
@ -191,6 +251,11 @@ internal class PlainDecoder
configuration ,
configuration ,
rowSpan ,
rowSpan ,
pixelSpan ) ;
pixelSpan ) ;
if ( eofReached )
{
return ;
}
}
}
}
}
}
}