Ignore:
Timestamp:
10/03/11 21:21:09 (20 months ago)
Author:
glennrp
Message:

Recognize certain sRGB profiles by their crc32.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • ImageMagick/trunk/coders/png.c

    r5485 r5495  
    76297629               (LocaleCompare(name,"ICM") == 0)) 
    76307630              { 
     7631                 int 
     7632                   icheck; 
     7633 
     7634                 /* 0: not a known sRGB profile 
     7635                  * 1: HP-Microsoft sRGB v2 
     7636                  * 2: ICC sRGB v4 perceptual 
     7637                  * 3: ICC sRGB v2 perceptual no black-compensation 
     7638                  */ 
     7639                 png_uint_32 
     7640                   check_crc[4] = {0, 0xf29e526dUL, 0xbbef7812UL, 0x427ebb21UL}, 
     7641                   check_len[4] = {0, 3144, 60960, 3052}; 
     7642 
     7643                 png_uint_32 
     7644                   length, 
     7645                   profile_crc; 
     7646 
    76317647                 unsigned char 
    76327648                   *data; 
    76337649 
    7634                  png_uint_32 
    7635                    length; 
    7636  
    76377650                 length=(png_uint_32) GetStringInfoLength(profile); 
    76387651 
    7639                  if (length == 3144) 
     7652                 for (icheck=3; icheck > 0; icheck--) 
    76407653                 { 
    7641                    (void) LogMagickEvent(CoderEvent,GetMagickModule(), 
    7642                        "    got a 3144-byte ICC profile (potentially sRGB)"); 
    7643  
    7644                    data=GetStringInfoDatum(profile); 
    7645  
    7646                    if (data[52]=='s' && data[53]=='R' && 
    7647                        data[54]=='G' && data[55]=='B') 
     7654                   if (length == check_len[icheck]) 
    76487655                   { 
    7649                       (void) LogMagickEvent(CoderEvent,GetMagickModule(), 
    7650                           "    It is the HP-Microsoft sRGB)"); 
    7651                       if (image->rendering_intent==UndefinedIntent) 
    7652                         image->rendering_intent=PerceptualIntent; 
     7656                     (void) LogMagickEvent(CoderEvent,GetMagickModule(), 
     7657                         "    Got a %lu-byte ICC profile (potentially sRGB)", 
     7658                         (unsigned long) length); 
     7659 
     7660                     data=GetStringInfoDatum(profile); 
     7661                     profile_crc=crc32(0,data,length); 
     7662 
     7663                     (void) LogMagickEvent(CoderEvent,GetMagickModule(), 
     7664                         "      with crc=%8x",profile_crc); 
     7665 
     7666                     if (profile_crc == check_crc[icheck]) 
     7667                     { 
     7668                        (void) LogMagickEvent(CoderEvent,GetMagickModule(), 
     7669                            "      It is sRGB."); 
     7670                        if (image->rendering_intent==UndefinedIntent) 
     7671                          image->rendering_intent=PerceptualIntent; 
     7672                        break; 
     7673                     } 
    76537674                   } 
    7654                    else 
    7655                       (void) LogMagickEvent(CoderEvent,GetMagickModule(), 
    7656                           "    It is not sRGB (%c%c%c%c)",data[52], 
    7657                           data[53],data[54],data[55]); 
    7658                     
    76597675                 } 
    7660                  else if (length == 3052) 
    7661                  { 
    7662                    (void) LogMagickEvent(CoderEvent,GetMagickModule(), 
    7663                        "    got a 3052-byte ICC profile (potentially sRGB)"); 
    7664  
    7665                    data=GetStringInfoDatum(profile); 
    7666  
    7667                    if (data[336]=='s' && data[337]=='R' && 
    7668                        data[338]=='G' && data[339]=='B') 
    7669                    { 
    7670                       (void) LogMagickEvent(CoderEvent,GetMagickModule(), 
    7671                           "    It is the ICC no-black sRGB)"); 
    7672                       if (image->rendering_intent==UndefinedIntent) 
    7673                         image->rendering_intent=PerceptualIntent; 
    7674                    } 
    7675                    else 
    7676                       (void) LogMagickEvent(CoderEvent,GetMagickModule(), 
    7677                           "    It is not sRGB (%c%c%c%c)",data[52], 
    7678                           data[53],data[54],data[55]); 
    7679                     
    7680                  } 
    7681                  else 
     7676                 if (icheck == 0) 
    76827677                    (void) LogMagickEvent(CoderEvent,GetMagickModule(), 
    7683                         "    got a %lu-byte ICC profile", 
     7678                        "    Got a %lu-byte ICC profile", 
    76847679                        (unsigned long) length); 
    76857680              } 
Note: See TracChangeset for help on using the changeset viewer.