Hans Leidekker : mscms: Let liblcms2 determine input and output format for transform profiles.

Alexandre Julliard julliard at wine.codeweavers.com
Thu Aug 6 10:15:44 CDT 2015


Module: wine
Branch: master
Commit: d2c9e5560a2aa13319e2ea3e8ea8899e5aea1f55
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=d2c9e5560a2aa13319e2ea3e8ea8899e5aea1f55

Author: Hans Leidekker <hans at codeweavers.com>
Date:   Thu Aug  6 14:46:34 2015 +0200

mscms: Let liblcms2 determine input and output format for transform profiles.

---

 dlls/mscms/tests/profile.c |  37 ++++++++++++++++
 dlls/mscms/transform.c     | 102 +++++++++++++++------------------------------
 2 files changed, 71 insertions(+), 68 deletions(-)

diff --git a/dlls/mscms/tests/profile.c b/dlls/mscms/tests/profile.c
index 012a7dc..f3ebe03 100644
--- a/dlls/mscms/tests/profile.c
+++ b/dlls/mscms/tests/profile.c
@@ -35,6 +35,8 @@ static HMODULE huser32;
 
 static BOOL     (WINAPI *pAssociateColorProfileWithDeviceA)(PCSTR,PCSTR,PCSTR);
 static BOOL     (WINAPI *pCloseColorProfile)(HPROFILE);
+static HTRANSFORM (WINAPI *pCreateMultiProfileTransform)(PHPROFILE,DWORD,PDWORD,DWORD,DWORD,DWORD);
+static BOOL     (WINAPI *pDeleteColorTransform)(HTRANSFORM);
 static BOOL     (WINAPI *pDisassociateColorProfileFromDeviceA)(PCSTR,PCSTR,PCSTR);
 static BOOL     (WINAPI *pGetColorDirectoryA)(PCHAR,PCHAR,PDWORD);
 static BOOL     (WINAPI *pGetColorDirectoryW)(PWCHAR,PWCHAR,PDWORD);
@@ -68,6 +70,8 @@ static BOOL init_function_ptrs( void )
 {
     GETFUNCPTR( AssociateColorProfileWithDeviceA )
     GETFUNCPTR( CloseColorProfile )
+    GETFUNCPTR( CreateMultiProfileTransform )
+    GETFUNCPTR( DeleteColorTransform )
     GETFUNCPTR( DisassociateColorProfileFromDeviceA )
     GETFUNCPTR( GetColorDirectoryA )
     GETFUNCPTR( GetColorDirectoryW )
@@ -1334,6 +1338,38 @@ static BOOL have_profile(void)
     return TRUE;
 }
 
+static void test_CreateMultiProfileTransform( char *standardprofile, char *testprofile )
+{
+    PROFILE profile;
+    HPROFILE handle[2];
+    HTRANSFORM transform;
+    DWORD intents[2] = { INTENT_PERCEPTUAL, INTENT_PERCEPTUAL };
+
+    if (testprofile)
+    {
+        profile.dwType       = PROFILE_FILENAME;
+        profile.pProfileData = standardprofile;
+        profile.cbDataSize   = strlen(standardprofile);
+
+        handle[0] = pOpenColorProfileA( &profile, PROFILE_READ, 0, OPEN_EXISTING );
+        ok( handle[0] != NULL, "got %u\n", GetLastError() );
+
+        profile.dwType       = PROFILE_FILENAME;
+        profile.pProfileData = testprofile;
+        profile.cbDataSize   = strlen(testprofile);
+
+        handle[1] = pOpenColorProfileA( &profile, PROFILE_READ, 0, OPEN_EXISTING );
+        ok( handle[1] != NULL, "got %u\n", GetLastError() );
+
+        transform = pCreateMultiProfileTransform( handle, 2, intents, 2, 0, 0 );
+        ok( transform != NULL, "got %u\n", GetLastError() );
+
+        pDeleteColorTransform( transform );
+        pCloseColorProfile( handle[0] );
+        pCloseColorProfile( handle[1] );
+    }
+}
+
 START_TEST(profile)
 {
     UINT len;
@@ -1443,6 +1479,7 @@ START_TEST(profile)
     test_UninstallColorProfileW( testprofileW );
 
     test_AssociateColorProfileWithDeviceA( testprofile );
+    test_CreateMultiProfileTransform( standardprofile, testprofile );
 
     if (testprofile) DeleteFileA( testprofile );
     FreeLibrary( huser32 );
diff --git a/dlls/mscms/transform.c b/dlls/mscms/transform.c
index 058cffa..cada332 100644
--- a/dlls/mscms/transform.c
+++ b/dlls/mscms/transform.c
@@ -36,64 +36,51 @@ WINE_DEFAULT_DEBUG_CHANNEL(mscms);
 
 #ifdef HAVE_LCMS2
 
-static DWORD from_profile( HPROFILE profile )
-{
-    PROFILEHEADER header;
-
-    GetColorProfileHeader( profile, &header );
-    TRACE( "color space: 0x%08x %s\n", header.phDataColorSpace, dbgstr_tag( header.phDataColorSpace ) );
-
-    switch (header.phDataColorSpace)
-    {
-    case 0x434d594b: return TYPE_CMYK_16;  /* 'CMYK' */
-    case 0x47524159: return TYPE_GRAY_16;  /* 'GRAY' */
-    case 0x4c616220: return TYPE_Lab_16;   /* 'Lab ' */
-    case 0x52474220: return TYPE_RGB_16;   /* 'RGB ' */
-    case 0x58595a20: return TYPE_XYZ_16;   /* 'XYZ ' */
-    default:
-        WARN("unhandled format\n");
-        return TYPE_RGB_16;
-    }
-}
-
 static DWORD from_bmformat( BMFORMAT format )
 {
     static BOOL quietfixme = FALSE;
-    TRACE( "bitmap format: 0x%08x\n", format );
+    DWORD ret;
 
     switch (format)
     {
-    case BM_RGBTRIPLETS: return TYPE_RGB_8;
-    case BM_BGRTRIPLETS: return TYPE_BGR_8;
-    case BM_GRAY:        return TYPE_GRAY_8;
-    case BM_xRGBQUADS:   return TYPE_ARGB_8;
-    case BM_xBGRQUADS:   return TYPE_ABGR_8;
+    case BM_RGBTRIPLETS: ret = TYPE_RGB_8; break;
+    case BM_BGRTRIPLETS: ret = TYPE_BGR_8; break;
+    case BM_GRAY:        ret = TYPE_GRAY_8; break;
+    case BM_xRGBQUADS:   ret = TYPE_ARGB_8; break;
+    case BM_xBGRQUADS:   ret = TYPE_ABGR_8; break;
     default:
         if (!quietfixme)
         {
-            FIXME("unhandled bitmap format 0x%x\n", format);
+            FIXME( "unhandled bitmap format %08x\n", format );
             quietfixme = TRUE;
         }
-        return TYPE_RGB_8;
+        ret = TYPE_RGB_8;
+        break;
     }
+    TRACE( "color space: %08x -> %08x\n", format, ret );
+    return ret;
 }
 
 static DWORD from_type( COLORTYPE type )
 {
-    TRACE( "color type: 0x%08x\n", type );
+    DWORD ret;
 
     switch (type)
     {
-    case COLOR_GRAY:    return TYPE_GRAY_16;
-    case COLOR_RGB:     return TYPE_RGB_16;
-    case COLOR_XYZ:     return TYPE_XYZ_16;
-    case COLOR_Yxy:     return TYPE_Yxy_16;
-    case COLOR_Lab:     return TYPE_Lab_16;
-    case COLOR_CMYK:    return TYPE_CMYK_16;
+    case COLOR_GRAY: ret = TYPE_GRAY_16; break;
+    case COLOR_RGB:  ret = TYPE_RGB_16; break;
+    case COLOR_XYZ:  ret = TYPE_XYZ_16; break;
+    case COLOR_Yxy:  ret = TYPE_Yxy_16; break;
+    case COLOR_Lab:  ret = TYPE_Lab_16; break;
+    case COLOR_CMYK: ret = TYPE_CMYK_16; break;
     default:
-        FIXME("unhandled color type\n");
-        return TYPE_RGB_16;
+        FIXME( "unhandled color type %08x\n", type );
+        ret = TYPE_RGB_16;
+        break;
     }
+
+    TRACE( "color type: %08x -> %08x\n", type, ret );
+    return ret;
 }
 
 #endif /* HAVE_LCMS2 */
@@ -145,7 +132,7 @@ HTRANSFORM WINAPI CreateColorTransformW( LPLOGCOLORSPACEW space, HPROFILE dest,
     struct transform transform;
     struct profile *dst, *tgt = NULL;
     cmsHPROFILE cmsinput, cmsoutput, cmstarget = NULL;
-    DWORD in_format, out_format, proofing = 0;
+    DWORD proofing = 0;
     int intent;
 
     TRACE( "( %p, %p, %p, 0x%08x )\n", space, dest, target, flags );
@@ -163,9 +150,6 @@ HTRANSFORM WINAPI CreateColorTransformW( LPLOGCOLORSPACEW space, HPROFILE dest,
     TRACE( "lcsCSType:   %s\n", dbgstr_tag( space->lcsCSType ) );
     TRACE( "lcsFilename: %s\n", debugstr_w( space->lcsFilename ) );
 
-    in_format  = TYPE_RGB_16;
-    out_format = from_profile( dest );
-
     cmsinput = cmsCreate_sRGBProfile(); /* FIXME: create from supplied color space */
     if (target)
     {
@@ -173,8 +157,9 @@ HTRANSFORM WINAPI CreateColorTransformW( LPLOGCOLORSPACEW space, HPROFILE dest,
         cmstarget = tgt->cmsprofile;
     }
     cmsoutput = dst->cmsprofile;
-    transform.cmstransform = cmsCreateProofingTransform(cmsinput, in_format, cmsoutput, out_format, cmstarget,
-                                                        intent, INTENT_ABSOLUTE_COLORIMETRIC, proofing);
+    transform.cmstransform = cmsCreateProofingTransform(cmsinput, 0, cmsoutput, 0, cmstarget,
+                                                        intent, INTENT_ABSOLUTE_COLORIMETRIC,
+                                                        proofing);
     if (!transform.cmstransform)
     {
         if (tgt) release_profile( tgt );
@@ -212,10 +197,9 @@ HTRANSFORM WINAPI CreateMultiProfileTransform( PHPROFILE profiles, DWORD nprofil
 {
     HTRANSFORM ret = NULL;
 #ifdef HAVE_LCMS2
-    cmsHPROFILE *cmsprofiles, cmsconvert = NULL;
+    cmsHPROFILE *cmsprofiles;
     struct transform transform;
     struct profile *profile0, *profile1;
-    DWORD in_format, out_format;
 
     TRACE( "( %p, 0x%08x, %p, 0x%08x, 0x%08x, 0x%08x )\n",
            profiles, nprofiles, intents, nintents, flags, cmm );
@@ -236,32 +220,14 @@ HTRANSFORM WINAPI CreateMultiProfileTransform( PHPROFILE profiles, DWORD nprofil
         release_profile( profile0 );
         return NULL;
     }
-    in_format  = from_profile( profiles[0] );
-    out_format = from_profile( profiles[nprofiles - 1] );
-
-    if (in_format != out_format)
-    {
-        /* insert a conversion profile for pairings that lcms doesn't handle */
-        if (out_format == TYPE_RGB_16) cmsconvert = cmsCreate_sRGBProfile();
-        if (out_format == TYPE_Lab_16) cmsconvert = cmsCreateLab2Profile( NULL );
-    }
 
-    cmsprofiles = HeapAlloc( GetProcessHeap(), 0, (nprofiles + 1) * sizeof(cmsHPROFILE) );
-    if (cmsprofiles)
+    if ((cmsprofiles = HeapAlloc( GetProcessHeap(), 0, (nprofiles + 1) * sizeof(cmsHPROFILE) )))
     {
         cmsprofiles[0] = profile0->cmsprofile;
-        if (cmsconvert)
-        {
-            cmsprofiles[1] = cmsconvert;
-            cmsprofiles[2] = profile1->cmsprofile;
-            nprofiles++;
-        }
-        else
-        {
-            cmsprofiles[1] = profile1->cmsprofile;
-        }
-        transform.cmstransform = cmsCreateMultiprofileTransform( cmsprofiles, nprofiles, in_format,
-                                                                 out_format, *intents, 0 );
+        cmsprofiles[1] = profile1->cmsprofile;
+
+        transform.cmstransform = cmsCreateMultiprofileTransform( cmsprofiles, nprofiles, 0,
+                                                                 0, *intents, 0 );
         HeapFree( GetProcessHeap(), 0, cmsprofiles );
         if (!transform.cmstransform)
         {




More information about the wine-cvs mailing list