@@ -150,28 +150,30 @@ public static void AddMetadataReader(WicProcessingContext ctx, bool basicOnly =
150
150
var cct = cc . GetType ( ) ;
151
151
if ( cct == WICColorContextType . WICColorContextProfile )
152
152
{
153
- uint ccs = cc . GetProfileBytes ( 0 , null ) ;
153
+ int ccs = ( int ) cc . GetProfileBytes ( 0 , null ) ;
154
154
155
155
// don't try to read giant profiles. 4MiB is more than enough
156
- if ( ccs > ( 1024 * 1024 * 4 ) )
156
+ if ( ( uint ) ccs > ( 1024 * 1024 * 4 ) )
157
157
continue ;
158
158
159
- var ccb = ArrayPool < byte > . Shared . Rent ( ( int ) ccs ) ;
160
- cc . GetProfileBytes ( ccs , ccb ) ;
161
- var cpi = ColorProfile . Cache . GetOrAdd ( new ArraySegment < byte > ( ccb , 0 , ( int ) ccs ) ) ;
162
- ArrayPool < byte > . Shared . Return ( ccb ) ;
163
-
164
- // match only color profiles that match our intended use. if we have a standard sRGB profile, don't save it; we don't need to convert
165
- if ( cpi . IsValid && (
166
- ( cpi . DataColorSpace == ColorProfile . ProfileColorSpace . Rgb && ( fmt . ColorRepresentation == PixelColorRepresentation . Bgr || fmt . ColorRepresentation == PixelColorRepresentation . Rgb ) && ! cpi . IsSrgb )
167
- || ( cpi . DataColorSpace == ColorProfile . ProfileColorSpace . Grey && fmt . ColorRepresentation == PixelColorRepresentation . Grey && ! cpi . IsSrgbCurve )
168
- || ( cpi . DataColorSpace == ColorProfile . ProfileColorSpace . Cmyk && fmt . ColorRepresentation == PixelColorRepresentation . Cmyk )
169
- ) )
159
+ using ( var ccb = MemoryPool < byte > . Shared . Rent ( ccs ) )
170
160
{
171
- profile = cc ;
172
- if ( cpi . IsRgbMatrix || cpi . IsGreyTrc )
173
- ctx . SourceColorProfile = cpi ;
174
- break ;
161
+ MemoryMarshal . TryGetArray ( ccb . Memory . Slice ( 0 , ccs ) , out ArraySegment < byte > cca ) ;
162
+ cc . GetProfileBytes ( ( uint ) cca . Count , cca . Array ) ;
163
+ var cpi = ColorProfile . Cache . GetOrAdd ( cca ) ;
164
+
165
+ // match only color profiles that match our intended use. if we have a standard sRGB profile, don't save it; we don't need to convert
166
+ if ( cpi . IsValid && (
167
+ ( cpi . DataColorSpace == ColorProfile . ProfileColorSpace . Rgb && ( fmt . ColorRepresentation == PixelColorRepresentation . Bgr || fmt . ColorRepresentation == PixelColorRepresentation . Rgb ) && ! cpi . IsSrgb )
168
+ || ( cpi . DataColorSpace == ColorProfile . ProfileColorSpace . Grey && fmt . ColorRepresentation == PixelColorRepresentation . Grey && ! cpi . IsSrgbCurve )
169
+ || ( cpi . DataColorSpace == ColorProfile . ProfileColorSpace . Cmyk && fmt . ColorRepresentation == PixelColorRepresentation . Cmyk )
170
+ ) )
171
+ {
172
+ profile = cc ;
173
+ if ( cpi . IsRgbMatrix || cpi . IsGreyTrc )
174
+ ctx . SourceColorProfile = cpi ;
175
+ break ;
176
+ }
175
177
}
176
178
}
177
179
else if ( cct == WICColorContextType . WICColorContextExifColorSpace && cc . GetExifColorSpace ( ) == ExifColorSpace . AdobeRGB )
0 commit comments