@@ -32,15 +32,14 @@ public struct stbi__result_info
32
32
public int channel_order ;
33
33
}
34
34
35
- [ StructLayout ( LayoutKind . Sequential ) ]
36
- public struct stbi__huffman
35
+ public class stbi__huffman
37
36
{
38
- public fixed byte fast [ 1 << 9 ] ;
39
- public fixed ushort code [ 256 ] ;
40
- public fixed byte values [ 256 ] ;
41
- public fixed byte size [ 257 ] ;
42
- public fixed uint maxcode [ 18 ] ;
43
- public fixed int delta [ 17 ] ;
37
+ public byte [ ] fast = new byte [ 1 << 9 ] ;
38
+ public ushort [ ] code = new ushort [ 256 ] ;
39
+ public byte [ ] values = new byte [ 256 ] ;
40
+ public byte [ ] size = new byte [ 257 ] ;
41
+ public uint [ ] maxcode = new uint [ 18 ] ;
42
+ public int [ ] delta = new int [ 17 ] ;
44
43
}
45
44
46
45
[ StructLayout ( LayoutKind . Sequential ) ]
@@ -840,7 +839,7 @@ public static ushort stbi__compute_y_16(int r, int g, int b)
840
839
return good ;
841
840
}
842
841
843
- public static int stbi__build_huffman ( stbi__huffman * h , int * count )
842
+ public static int stbi__build_huffman ( stbi__huffman h , int * count )
844
843
{
845
844
int i ;
846
845
int j ;
@@ -850,63 +849,66 @@ public static int stbi__build_huffman(stbi__huffman* h, int* count)
850
849
{
851
850
for ( j = ( int ) ( 0 ) ; ( j ) < ( count [ i ] ) ; ++ j )
852
851
{
853
- h -> size [ k ++ ] = ( ( byte ) ( i + 1 ) ) ;
852
+ h . size [ k ++ ] = ( ( byte ) ( i + 1 ) ) ;
854
853
}
855
854
}
856
855
857
- h -> size [ k ] = ( byte ) ( 0 ) ;
856
+ h . size [ k ] = ( byte ) ( 0 ) ;
858
857
code = ( int ) ( 0 ) ;
859
858
k = ( int ) ( 0 ) ;
860
859
for ( j = ( int ) ( 1 ) ; j <= 16 ; ++ j )
861
860
{
862
- h -> delta [ j ] = ( int ) ( k - code ) ;
863
- if ( ( h -> size [ k ] ) == ( j ) )
861
+ h . delta [ j ] = ( int ) ( k - code ) ;
862
+ if ( ( h . size [ k ] ) == ( j ) )
864
863
{
865
- while ( ( h -> size [ k ] ) == ( j ) )
864
+ while ( ( h . size [ k ] ) == ( j ) )
866
865
{
867
- h -> code [ k ++ ] = ( ( ushort ) ( code ++ ) ) ;
866
+ h . code [ k ++ ] = ( ( ushort ) ( code ++ ) ) ;
868
867
}
869
868
870
869
if ( ( code - 1 ) >= ( 1 << j ) )
871
870
return ( int ) ( stbi__err ( "bad code lengths" ) ) ;
872
871
}
873
872
874
- h -> maxcode [ j ] = ( uint ) ( code << ( 16 - j ) ) ;
873
+ h . maxcode [ j ] = ( uint ) ( code << ( 16 - j ) ) ;
875
874
code <<= 1 ;
876
875
}
877
876
878
- h ->maxcode [ j ] = ( uint ) ( 0xffffffff ) ;
879
- CRuntime . memset ( h ->fast , ( int ) ( 255 ) , ( ulong ) ( 1 << 9 ) ) ;
877
+ h . maxcode [ j ] = ( uint ) ( 0xffffffff ) ;
878
+ for ( i = 0 ; i < h . fast . Length ; ++ i )
879
+ {
880
+ h . fast [ i ] = 255 ;
881
+ }
880
882
for ( i = ( int ) ( 0 ) ; ( i ) < ( k ) ; ++ i )
881
883
{
882
- int s = ( int ) ( h -> size [ i ] ) ;
884
+ int s = ( int ) ( h . size [ i ] ) ;
883
885
if ( s <= 9 )
884
886
{
885
- int c = ( int ) ( h -> code [ i ] << ( 9 - s ) ) ;
887
+ int c = ( int ) ( h . code [ i ] << ( 9 - s ) ) ;
886
888
int m = ( int ) ( 1 << ( 9 - s ) ) ;
887
889
for ( j = ( int ) ( 0 ) ; ( j ) < ( m ) ; ++ j )
888
890
{
889
- h -> fast [ c + j ] = ( ( byte ) ( i ) ) ;
891
+ h . fast [ c + j ] = ( ( byte ) ( i ) ) ;
890
892
}
891
893
}
892
894
}
893
895
894
896
return ( int ) ( 1 ) ;
895
897
}
896
898
897
- public static void stbi__build_fast_ac ( short * fast_ac , stbi__huffman * h )
899
+ public static void stbi__build_fast_ac ( short [ ] fast_ac , stbi__huffman h )
898
900
{
899
901
int i ;
900
902
for ( i = ( int ) ( 0 ) ; ( i ) < ( 1 << 9 ) ; ++ i )
901
903
{
902
- byte fast = ( byte ) ( h -> fast [ i ] ) ;
904
+ byte fast = ( byte ) ( h . fast [ i ] ) ;
903
905
fast_ac [ i ] = ( short ) ( 0 ) ;
904
906
if ( ( fast ) < ( 255 ) )
905
907
{
906
- int rs = ( int ) ( h -> values [ fast ] ) ;
908
+ int rs = ( int ) ( h . values [ fast ] ) ;
907
909
int run = ( int ) ( ( rs >> 4 ) & 15 ) ;
908
910
int magbits = ( int ) ( rs & 15 ) ;
909
- int len = ( int ) ( h -> size [ fast ] ) ;
911
+ int len = ( int ) ( h . size [ fast ] ) ;
910
912
if ( ( ( magbits ) != 0 ) && ( len + magbits <= 9 ) )
911
913
{
912
914
int k = ( int ) ( ( ( i << len ) & ( ( 1 << 9 ) - 1 ) ) >> ( 9 - magbits ) ) ;
@@ -946,29 +948,29 @@ public static void stbi__grow_buffer_unsafe(stbi__jpeg j)
946
948
} while ( j . code_bits <= 24 ) ;
947
949
}
948
950
949
- public static int stbi__jpeg_huff_decode ( stbi__jpeg j , stbi__huffman * h )
951
+ public static int stbi__jpeg_huff_decode ( stbi__jpeg j , stbi__huffman h )
950
952
{
951
953
uint temp ;
952
954
int c ;
953
955
int k ;
954
956
if ( ( j . code_bits ) < ( 16 ) )
955
957
stbi__grow_buffer_unsafe ( j ) ;
956
958
c = ( int ) ( ( j . code_buffer >> ( 32 - 9 ) ) & ( ( 1 << 9 ) - 1 ) ) ;
957
- k = ( int ) ( h -> fast [ c ] ) ;
959
+ k = ( int ) ( h . fast [ c ] ) ;
958
960
if ( ( k ) < ( 255 ) )
959
961
{
960
- int s = ( int ) ( h -> size [ k ] ) ;
962
+ int s = ( int ) ( h . size [ k ] ) ;
961
963
if ( ( s ) > ( j . code_bits ) )
962
964
return ( int ) ( - 1 ) ;
963
965
j . code_buffer <<= s ;
964
966
j . code_bits -= ( int ) ( s ) ;
965
- return ( int ) ( h -> values [ k ] ) ;
967
+ return ( int ) ( h . values [ k ] ) ;
966
968
}
967
969
968
970
temp = ( uint ) ( j . code_buffer >> 16 ) ;
969
971
for ( k = ( int ) ( 9 + 1 ) ; ; ++ k )
970
972
{
971
- if ( ( temp ) < ( h -> maxcode [ k ] ) )
973
+ if ( ( temp ) < ( h . maxcode [ k ] ) )
972
974
break ;
973
975
}
974
976
@@ -980,10 +982,10 @@ public static int stbi__jpeg_huff_decode(stbi__jpeg j, stbi__huffman* h)
980
982
981
983
if ( ( k ) > ( j . code_bits ) )
982
984
return ( int ) ( - 1 ) ;
983
- c = ( int ) ( ( ( j . code_buffer >> ( 32 - k ) ) & stbi__bmask [ k ] ) + h -> delta [ k ] ) ;
985
+ c = ( int ) ( ( ( j . code_buffer >> ( 32 - k ) ) & stbi__bmask [ k ] ) + h . delta [ k ] ) ;
984
986
j . code_bits -= ( int ) ( k ) ;
985
987
j . code_buffer <<= k ;
986
- return ( int ) ( h -> values [ c ] ) ;
988
+ return ( int ) ( h . values [ c ] ) ;
987
989
}
988
990
989
991
public static int stbi__extend_receive ( stbi__jpeg j , int n )
@@ -1023,8 +1025,8 @@ public static int stbi__jpeg_get_bit(stbi__jpeg j)
1023
1025
return ( int ) ( k & 0x80000000 ) ;
1024
1026
}
1025
1027
1026
- public static int stbi__jpeg_decode_block ( stbi__jpeg j , short * data , stbi__huffman * hdc , stbi__huffman * hac ,
1027
- short * fac , int b , ushort * dequant )
1028
+ public static int stbi__jpeg_decode_block ( stbi__jpeg j , short * data , stbi__huffman hdc , stbi__huffman hac ,
1029
+ short [ ] fac , int b , ushort [ ] dequant )
1028
1030
{
1029
1031
int diff ;
1030
1032
int dc ;
@@ -1085,7 +1087,7 @@ public static int stbi__jpeg_decode_block(stbi__jpeg j, short* data, stbi__huffm
1085
1087
return ( int ) ( 1 ) ;
1086
1088
}
1087
1089
1088
- public static int stbi__jpeg_decode_block_prog_dc ( stbi__jpeg j , short * data , stbi__huffman * hdc , int b )
1090
+ public static int stbi__jpeg_decode_block_prog_dc ( stbi__jpeg j , short * data , stbi__huffman hdc , int b )
1089
1091
{
1090
1092
int diff ;
1091
1093
int dc ;
@@ -1112,7 +1114,7 @@ public static int stbi__jpeg_decode_block_prog_dc(stbi__jpeg j, short* data, stb
1112
1114
return ( int ) ( 1 ) ;
1113
1115
}
1114
1116
1115
- public static int stbi__jpeg_decode_block_prog_ac ( stbi__jpeg j , short * data , stbi__huffman * hac , short * fac )
1117
+ public static int stbi__jpeg_decode_block_prog_ac ( stbi__jpeg j , short * data , stbi__huffman hac , short [ ] fac )
1116
1118
{
1117
1119
int k ;
1118
1120
if ( ( j . spec_start ) == ( 0 ) )
@@ -1476,9 +1478,9 @@ public static int stbi__parse_entropy_coded_data(stbi__jpeg z)
1476
1478
{
1477
1479
int ha = ( int ) ( z . img_comp [ n ] . ha ) ;
1478
1480
if (
1479
- stbi__jpeg_decode_block ( z , data , ( stbi__huffman * ) z . huff_dc + z . img_comp [ n ] . hd ,
1480
- ( stbi__huffman * ) z . huff_ac + ha ,
1481
- z . fast_ac [ ha ] , ( int ) ( n ) , ( ushort * ) z . dequant [ z . img_comp [ n ] . tq ] ) ==
1481
+ stbi__jpeg_decode_block ( z , data , z . huff_dc [ z . img_comp [ n ] . hd ] ,
1482
+ z . huff_ac [ ha ] ,
1483
+ z . fast_ac [ ha ] , ( int ) ( n ) , z . dequant [ z . img_comp [ n ] . tq ] ) ==
1482
1484
0 )
1483
1485
return ( int ) ( 0 ) ;
1484
1486
z . idct_block_kernel ( z . img_comp [ n ] . data + z . img_comp [ n ] . w2 * j * 8 + i * 8 ,
@@ -1520,9 +1522,9 @@ public static int stbi__parse_entropy_coded_data(stbi__jpeg z)
1520
1522
int ha = ( int ) ( z . img_comp [ n ] . ha ) ;
1521
1523
if (
1522
1524
stbi__jpeg_decode_block ( z , data ,
1523
- ( stbi__huffman * ) z . huff_dc + z . img_comp [ n ] . hd ,
1524
- ( stbi__huffman * ) z . huff_ac + ha , z . fast_ac [ ha ] , ( int ) ( n ) ,
1525
- ( ushort * ) z . dequant [ z . img_comp [ n ] . tq ] ) == 0 )
1525
+ z . huff_dc [ z . img_comp [ n ] . hd ] ,
1526
+ z . huff_ac [ ha ] , z . fast_ac [ ha ] , ( int ) ( n ) ,
1527
+ z . dequant [ z . img_comp [ n ] . tq ] ) == 0 )
1526
1528
return ( int ) ( 0 ) ;
1527
1529
z . idct_block_kernel ( z . img_comp [ n ] . data + z . img_comp [ n ] . w2 * y2 + x2 ,
1528
1530
( int ) ( z . img_comp [ n ] . w2 ) , data ) ;
@@ -1561,14 +1563,13 @@ public static int stbi__parse_entropy_coded_data(stbi__jpeg z)
1561
1563
if ( ( z . spec_start ) == ( 0 ) )
1562
1564
{
1563
1565
if ( stbi__jpeg_decode_block_prog_dc ( z , data ,
1564
- ( stbi__huffman * ) z . huff_dc + z . img_comp [ n ] . hd , ( int ) ( n ) ) == 0 )
1566
+ z . huff_dc [ z . img_comp [ n ] . hd ] , ( int ) ( n ) ) == 0 )
1565
1567
return ( int ) ( 0 ) ;
1566
1568
}
1567
1569
else
1568
1570
{
1569
1571
int ha = ( int ) ( z . img_comp [ n ] . ha ) ;
1570
- if ( stbi__jpeg_decode_block_prog_ac ( z , data , ( stbi__huffman * ) z . huff_ac + ha ,
1571
- z . fast_ac [ ha ] ) == 0 )
1572
+ if ( stbi__jpeg_decode_block_prog_ac ( z , data , z . huff_ac [ ha ] , z . fast_ac [ ha ] ) == 0 )
1572
1573
return ( int ) ( 0 ) ;
1573
1574
}
1574
1575
@@ -1607,7 +1608,7 @@ public static int stbi__parse_entropy_coded_data(stbi__jpeg z)
1607
1608
int y2 = ( int ) ( j * z . img_comp [ n ] . v + y ) ;
1608
1609
short * data = z . img_comp [ n ] . coeff + 64 * ( x2 + y2 * z . img_comp [ n ] . coeff_w ) ;
1609
1610
if ( stbi__jpeg_decode_block_prog_dc ( z , data ,
1610
- ( stbi__huffman * ) z . huff_dc + z . img_comp [ n ] . hd , ( int ) ( n ) ) == 0 )
1611
+ z . huff_dc [ z . img_comp [ n ] . hd ] , ( int ) ( n ) ) == 0 )
1611
1612
return ( int ) ( 0 ) ;
1612
1613
}
1613
1614
}
@@ -1630,7 +1631,7 @@ public static int stbi__parse_entropy_coded_data(stbi__jpeg z)
1630
1631
1631
1632
}
1632
1633
1633
- public static void stbi__jpeg_dequantize ( short * data , ushort * dequant )
1634
+ public static void stbi__jpeg_dequantize ( short * data , ushort [ ] dequant )
1634
1635
{
1635
1636
int i ;
1636
1637
for ( i = ( int ) ( 0 ) ; ( i ) < ( 64 ) ; ++ i )
@@ -1655,7 +1656,7 @@ public static void stbi__jpeg_finish(stbi__jpeg z)
1655
1656
for ( i = ( int ) ( 0 ) ; ( i ) < ( w ) ; ++ i )
1656
1657
{
1657
1658
short * data = z . img_comp [ n ] . coeff + 64 * ( i + j * z . img_comp [ n ] . coeff_w ) ;
1658
- stbi__jpeg_dequantize ( data , ( ushort * ) z . dequant [ z . img_comp [ n ] . tq ] ) ;
1659
+ stbi__jpeg_dequantize ( data , z . dequant [ z . img_comp [ n ] . tq ] ) ;
1659
1660
z . idct_block_kernel ( z . img_comp [ n ] . data + z . img_comp [ n ] . w2 * j * 8 + i * 8 ,
1660
1661
( int ) ( z . img_comp [ n ] . w2 ) , data ) ;
1661
1662
}
@@ -1704,7 +1705,7 @@ public static int stbi__process_marker(stbi__jpeg z, int m)
1704
1705
L = ( int ) ( stbi__get16be ( z . s ) - 2 ) ;
1705
1706
while ( ( L ) > ( 0 ) )
1706
1707
{
1707
- byte * v ;
1708
+ byte [ ] v ;
1708
1709
int * sizes = stackalloc int [ 16 ] ;
1709
1710
int i ;
1710
1711
int n = ( int ) ( 0 ) ;
@@ -1722,17 +1723,17 @@ public static int stbi__process_marker(stbi__jpeg z, int m)
1722
1723
L -= ( int ) ( 17 ) ;
1723
1724
if ( ( tc ) == ( 0 ) )
1724
1725
{
1725
- if ( stbi__build_huffman ( ( stbi__huffman * ) z . huff_dc + th , sizes ) == 0 )
1726
+ if ( stbi__build_huffman ( z . huff_dc [ th ] , sizes ) == 0 )
1726
1727
return ( int ) ( 0 ) ;
1727
- stbi__huffman * h = ( stbi__huffman * ) z . huff_dc + th ;
1728
- v = h -> values ;
1728
+ stbi__huffman h = z . huff_dc [ th ] ;
1729
+ v = h . values ;
1729
1730
}
1730
1731
else
1731
1732
{
1732
- if ( stbi__build_huffman ( ( stbi__huffman * ) z . huff_ac + th , sizes ) == 0 )
1733
+ if ( stbi__build_huffman ( z . huff_ac [ th ] , sizes ) == 0 )
1733
1734
return ( int ) ( 0 ) ;
1734
- stbi__huffman * h = ( stbi__huffman * ) z . huff_ac + th ;
1735
- v = h -> values ;
1735
+ stbi__huffman h = z . huff_ac [ th ] ;
1736
+ v = h . values ;
1736
1737
}
1737
1738
1738
1739
for ( i = ( int ) ( 0 ) ; ( i ) < ( n ) ; ++ i )
@@ -1741,7 +1742,7 @@ public static int stbi__process_marker(stbi__jpeg z, int m)
1741
1742
}
1742
1743
1743
1744
if ( tc != 0 )
1744
- stbi__build_fast_ac ( z . fast_ac [ th ] , ( stbi__huffman * ) z . huff_ac + th ) ;
1745
+ stbi__build_fast_ac ( z . fast_ac [ th ] , z . huff_ac [ th ] ) ;
1745
1746
L -= ( int ) ( n ) ;
1746
1747
}
1747
1748
0 commit comments