I'm trying to create a windows application in vb that automatically scans an
image, applies a profile (the intended scanners are very quick, but not very
color accurate unless they scan CMYK which is much slower), saves it as a
tiff in a temp directory, and opens it in photoshop.  I had every aspect of
the application functioning properly using TiffICC.exe to apply a profile
after it had already been saved, but as this application will be used tens
of thousands of times, usually in a batch of ~100 times, I was trying to
improve performance by performing the transformation from within the
application (That and I'm not comfortable having vb manipulate the tiff when
it is just making an educated guess as to when TiffICC.exe is finished with
the transformation.)

I basically want a function that will take a handle to the scanned DIB and
the path to the profile to be used and return the handle to the transformed
DIB.  I keep getting errors such as 'The memory could not be "written".',
'The memory could not be "read".', Illegal Exception Errors, or the visual
basic IDE just crashes and disappears when the cmsDoTransform is called in
the code below.  It functions fine until that point.

Is there something I'm missing or doing completely wrong?  This seems (to me
at least) to be the right way to go about doing this in visual basic, but
I'm about to start pulling my hair out.  Alterations I've been unsuccessful
with:
Using the same DIB handle for both input and output buffers.
Changing the byte size of the transform buffer.
Kicking my computer :)

On a more optimistic note, many thanks for all the work that has been put
into littlecms.  JpegICC in particular has already transformed thousands of
non-color corrected images for me.

-Isaac Chapman
Db Admin/Webmaster
Theme Co-op Promotions
[EMAIL PROTECTED]

VB Code:
Option Explicit

Public Enum cmsIntent
    cmsPerceptual = 0
    cmsRelativeColorimetric = 1
    cmsSaturation = 2
    cmsAbsoluteColorimetric = 3
End Enum
Public Const lTYPE_BGR_8 As Long = 263193
Public Declare Function cmsCreate_sRGBProfile Lib "lcms.dll" () As Long
Public Declare Function cmsOpenProfileFromFile Lib "lcms.dll" _
  (ByVal sProfilePath As String, ByVal sAccess As String) As Long
Public Declare Function cmsCloseProfile Lib "lcms.dll" _
  (ByVal lProfileHandle As Long) As Boolean
Public Declare Function cmsCreateTransform Lib "lcms.dll" _
  (ByVal lInputProfile As Long, ByVal lInputFormat As Long, _
  ByVal lOutputProfile As Long, ByVal lOutputFormat As Long, _
  ByVal iIntent As Integer, ByVal lFlags As Long) As Long
Public Declare Function cmsDoTransform Lib "lcms.dll" _
  (ByVal lTransformHandle As Long, ByVal lInputBuffer As Long, _
  ByVal lOutputBuffer As Long, ByVal lSize As Long)
Public Declare Function cmsDeleteTransform Lib "lsms.dll" _
  (ByVal lTransformHandle As Long)

Public Function TransformDib(lDibHandle As Long, lDibSize As Long, _
  sInputProfilePath As String) As Long

    Dim lInputProfile As Long
    Dim lOutputProfile As Long
    Dim lTransformHandle As Long
    Dim lOutputDib As Long

    ' Open/Create Profiles
    lInputProfile = cmsOpenProfileFromFile(sInputProfilePath, "r")
    lOutputProfile = cmsCreate_sRGBProfile

    ' Create Transform
    lTransformHandle = cmsCreateTransform(lInputProfile, lTYPE_BGR_8, _
      lOutputProfile, lTYPE_BGR_8, cmsPerceptual, 0)

    ' Allocate memory for the output DIB
    lOutputDib = GlobalAlloc(GHND, lDibSize)

    ' Apply the transform
    cmsDoTransform lTransformHandle, lDibHandle, lOutputDib, lDibSize

    ' Clean Up
    cmsDeleteTransform lTransformHandle
    cmsCloseProfile lInputProfile
    cmsCloseProfile lOutputProfile

    ' Return the handle to the transformed DIB
    TransformDib = lOutputDib
End Function



-------------------------------------------------------
This SF.net email is sponsored by: SlickEdit Inc. Develop an edge.
The most comprehensive and flexible code editor you can use.
Code faster. C/C++, C#, Java, HTML, XML, many more. FREE 30-Day Trial.
www.slickedit.com/sourceforge
_______________________________________________
Lcms-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/lcms-user

Reply via email to