@@ -190,67 +190,71 @@ impl SourceProfile {
190190 /// The `profile_buffer` pointer in `color` must be valid for `buffer_length` bytes
191191 /// if `source` is `ICCP` or `ICCP_GRAY`.
192192 #[ cfg( feature = "c-codecs" ) ]
193- pub unsafe fn from_decoder_color_info ( color : & DecoderColorInfo ) -> Self { unsafe {
194- match color. source {
195- ColorProfileSource :: Null | ColorProfileSource :: sRGB => SourceProfile :: Srgb ,
196- ColorProfileSource :: ICCP => {
197- if color. profile_buffer . is_null ( ) || color. buffer_length == 0 {
198- return SourceProfile :: Srgb ;
199- }
200- let bytes =
201- std:: slice:: from_raw_parts ( color. profile_buffer , color. buffer_length ) . to_vec ( ) ;
202- SourceProfile :: IccProfile ( bytes)
203- }
204- ColorProfileSource :: ICCP_GRAY => {
205- if color. profile_buffer . is_null ( ) || color. buffer_length == 0 {
206- return SourceProfile :: Srgb ;
207- }
208- let bytes =
209- std:: slice:: from_raw_parts ( color. profile_buffer , color. buffer_length ) . to_vec ( ) ;
210- SourceProfile :: IccProfileGray ( bytes)
211- }
212- ColorProfileSource :: GAMA_CHRM => {
213- let g = color. gamma ;
214- let wx = color. white_point . x ;
215- let wy = color. white_point . y ;
216- let rx = color. primaries . Red . x ;
217- let ry = color. primaries . Red . y ;
218- let gx = color. primaries . Green . x ;
219- let gy = color. primaries . Green . y ;
220- let bx = color. primaries . Blue . x ;
221- let by = color. primaries . Blue . y ;
222- // Reject degenerate values: NaN, infinity, zero gamma, or y=0
223- let all_finite = [ wx, wy, rx, ry, gx, gy, bx, by] . iter ( ) . all ( |v| v. is_finite ( ) ) ;
224- if g <= 0.0
225- || !g. is_finite ( )
226- || !all_finite
227- || wy == 0.0
228- || ry == 0.0
229- || gy == 0.0
230- || by == 0.0
231- {
232- return SourceProfile :: Srgb ;
193+ pub unsafe fn from_decoder_color_info ( color : & DecoderColorInfo ) -> Self {
194+ unsafe {
195+ match color. source {
196+ ColorProfileSource :: Null | ColorProfileSource :: sRGB => SourceProfile :: Srgb ,
197+ ColorProfileSource :: ICCP => {
198+ if color. profile_buffer . is_null ( ) || color. buffer_length == 0 {
199+ return SourceProfile :: Srgb ;
200+ }
201+ let bytes =
202+ std:: slice:: from_raw_parts ( color. profile_buffer , color. buffer_length )
203+ . to_vec ( ) ;
204+ SourceProfile :: IccProfile ( bytes)
233205 }
234- // If gamma is neutral and primaries match sRGB, this is effectively
235- // sRGB — no transform needed. This catches gAMA-only PNGs where the
236- // C code synthesized sRGB primaries.
237- if is_neutral_gamma ( g) && is_srgb_primaries ( [ wx, wy, rx, ry, gx, gy, bx, by] ) {
238- return SourceProfile :: Srgb ;
206+ ColorProfileSource :: ICCP_GRAY => {
207+ if color. profile_buffer . is_null ( ) || color. buffer_length == 0 {
208+ return SourceProfile :: Srgb ;
209+ }
210+ let bytes =
211+ std:: slice:: from_raw_parts ( color. profile_buffer , color. buffer_length )
212+ . to_vec ( ) ;
213+ SourceProfile :: IccProfileGray ( bytes)
239214 }
240- SourceProfile :: GammaPrimaries {
241- gamma : g,
242- white_x : wx,
243- white_y : wy,
244- red_x : rx,
245- red_y : ry,
246- green_x : gx,
247- green_y : gy,
248- blue_x : bx,
249- blue_y : by,
215+ ColorProfileSource :: GAMA_CHRM => {
216+ let g = color. gamma ;
217+ let wx = color. white_point . x ;
218+ let wy = color. white_point . y ;
219+ let rx = color. primaries . Red . x ;
220+ let ry = color. primaries . Red . y ;
221+ let gx = color. primaries . Green . x ;
222+ let gy = color. primaries . Green . y ;
223+ let bx = color. primaries . Blue . x ;
224+ let by = color. primaries . Blue . y ;
225+ // Reject degenerate values: NaN, infinity, zero gamma, or y=0
226+ let all_finite = [ wx, wy, rx, ry, gx, gy, bx, by] . iter ( ) . all ( |v| v. is_finite ( ) ) ;
227+ if g <= 0.0
228+ || !g. is_finite ( )
229+ || !all_finite
230+ || wy == 0.0
231+ || ry == 0.0
232+ || gy == 0.0
233+ || by == 0.0
234+ {
235+ return SourceProfile :: Srgb ;
236+ }
237+ // If gamma is neutral and primaries match sRGB, this is effectively
238+ // sRGB — no transform needed. This catches gAMA-only PNGs where the
239+ // C code synthesized sRGB primaries.
240+ if is_neutral_gamma ( g) && is_srgb_primaries ( [ wx, wy, rx, ry, gx, gy, bx, by] ) {
241+ return SourceProfile :: Srgb ;
242+ }
243+ SourceProfile :: GammaPrimaries {
244+ gamma : g,
245+ white_x : wx,
246+ white_y : wy,
247+ red_x : rx,
248+ red_y : ry,
249+ green_x : gx,
250+ green_y : gy,
251+ blue_x : bx,
252+ blue_y : by,
253+ }
250254 }
251255 }
252256 }
253- } }
257+ }
254258
255259 /// Returns true if this profile is sRGB (no transform needed).
256260 pub fn is_srgb ( & self ) -> bool {
0 commit comments