00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
#include "Windef.h"
00015
#include "WinGdi.h"
00016
#include <wtypes.h>
00017
#include <winbase.h>
00018
#include <windowsX.h>
00019
#include "ICM.h"
00020
00021
#ifndef LHGeneralIncs_h
00022
#include "General.h"
00023
#endif
00024
00025
#ifndef MSNewMemProfile_h
00026
#include "MemProf.h"
00027
#endif
00028
00029
#ifndef MemLink_h
00030
#include "MemLink.h"
00031
#endif
00032
00033
#ifdef _DEBUG
00034
00035
#endif
00036
#if ! realThing
00037
#ifdef DEBUG_OUTPUT
00038
#define kThisFile kLHMemProfileID
00039
#endif
00040
#endif
00041
00042
#ifdef WRITE_PROFILE
00043
void WriteProf( LPSTR name,
icProfile *theProf,
long currentSize );
00044
#endif
00045
00046 CMError MyNewDeviceLink( CMWorldRef cw,
CMConcatProfileSet *profileSet, LPSTR theProf )
00047 {
00048
CMError err =
unimpErr;
00049 PROFILE pProf;
00050 HPROFILE aHProf;
00051
00052 pProf.pProfileData = (PVOID *)theProf;
00053 pProf.dwType = PROFILE_FILENAME;
00054 pProf.cbDataSize =
strlen((
const unsigned char *)pProf.pProfileData) *
sizeof(
CHAR);
00055 aHProf = OpenColorProfile( &pProf, PROFILE_READWRITE, 0, CREATE_ALWAYS );
00056
if( !aHProf ){
00057 err = GetLastError();
00058
goto CleanupAndExit;
00059 }
00060 err =
MyNewDeviceLinkFill( cw, profileSet, aHProf );
00061
00062 CleanupAndExit:
00063
return err;
00064 }
00065
00066 CMError MyNewDeviceLinkW( CMWorldRef cw,
CMConcatProfileSet *profileSet, LPWSTR theProf )
00067 {
00068
CMError err =
unimpErr;
00069 PROFILE pProf;
00070 HPROFILE aHProf;
00071
00072 pProf.pProfileData = (PVOID *)theProf;
00073 pProf.dwType = PROFILE_FILENAME;
00074 pProf.cbDataSize = wcslen((
const unsigned short *)pProf.pProfileData) *
sizeof(WCHAR);
00075 aHProf =
OpenColorProfileW( &pProf, PROFILE_READWRITE, 0, CREATE_ALWAYS );
00076
if( !aHProf ){
00077 err = GetLastError();
00078
goto CleanupAndExit;
00079 }
00080 err =
MyNewDeviceLinkFill( cw, profileSet, aHProf );
00081 CleanupAndExit:
00082
return err;
00083 }
00084
00085 CMError MyNewDeviceLinkFill( CMWorldRef cw,
CMConcatProfileSet *profileSet, HPROFILE aHProf )
00086 {
00087
CMError err =
unimpErr;
00088
OSErr aOSerr =
unimpErr;
00089
#ifdef __MWERKS__
00090
unsigned char theText[] =
"\pLogColorSpProfile�";
00091
#else
00092
char theText[] =
"\024DeviceLinkProfile ";
00093
#endif
00094
char copyrightText[] =
"\060�1996 by Heidelberger Druckmaschinen AG U.J.K.";
00095
Ptr aPtr=0;
00096
long theHeaderSize;
00097
long theDescSize;
00098
long theMediaSize;
00099
long theCopyRightSize;
00100
long currentSize=0;
00101
long theTotalSize=0;
00102
long theSequenceDescSize = 0;
00103
long theA2B0Size;
00104
unsigned long aIntent;
00105
UINT32 sCS,dCS,clutSize;
00106
OSErr aOSErr;
00107
00108
00109
MyDoubleXYZ D50XYZ = { 0.9642, 1.0000, 0.8249 };
00110
icXYZNumber D50 = { (
unsigned long)(D50XYZ.
X * 65536), (
unsigned long)(D50XYZ.
Y * 65536), (
unsigned long)(D50XYZ.
Z * 65536)};
00111 theHeaderSize =
sizeof(
icHeader);
00112
00113 theDescSize =
sizeof(
OSType)
00114 +
sizeof(
unsigned long)
00115 +
sizeof(
unsigned long)
00116 + theText[0]
00117 +
sizeof(
unsigned long)
00118 +
sizeof(
unsigned long)
00119 +
sizeof(
unsigned short)
00120 +
sizeof(
unsigned char)
00121 + 67
00122 ;
00123 theCopyRightSize =
sizeof(
OSType)
00124 +
sizeof(
unsigned long)
00125 + copyrightText[0]
00126 ;
00127 theMediaSize =
sizeof(
icXYZType );;
00128
00129 aPtr =
SmartNewPtrClear( 5000, &aOSerr );
00130 err = aOSerr;
00131
if (err)
00132
goto CleanupAndExit;
00133
00134 aIntent = 0;
00135
00136 err =
MyGetColorSpaces( profileSet, &sCS, &dCS );
00137
if (err)
00138
goto CleanupAndExit;
00139
00140 err =
MyAdd_NL_HeaderMS(theHeaderSize+4, (
icHeader*)aPtr, aIntent, sCS, dCS );
00141
if (err)
00142
goto CleanupAndExit;
00143
00144 err =
SetColorProfileHeader( aHProf, (PPROFILEHEADER)aPtr);
00145
if (!err){
00146 err = GetLastError();
00147
goto CleanupAndExit;
00148 }
00149
00150 err =
MyAdd_NL_DescriptionTag ( (
LHTextDescriptionType *)aPtr, (
unsigned char *)theText );
00151
if (err)
00152
goto CleanupAndExit;
00153 err =
SetColorProfileElementSize( aHProf,
icSigProfileDescriptionTag, theDescSize );
00154
if (!err){
00155 err = GetLastError();
00156
goto CleanupAndExit;
00157 }
00158 err =
SetColorProfileElement( aHProf,
icSigProfileDescriptionTag, 0, (
DWORD *)&theDescSize, aPtr );
00159
if (!err){
00160 err = GetLastError();
00161
goto CleanupAndExit;
00162 }
00163
00164 err =
MyAdd_NL_ColorantTag((
icXYZType *)aPtr, &D50);
00165
if (err)
00166
goto CleanupAndExit;
00167
00168 err =
SetColorProfileElementSize( aHProf,
icSigMediaWhitePointTag, theMediaSize );
00169
if (!err){
00170 err = GetLastError();
00171
goto CleanupAndExit;
00172 }
00173 err =
SetColorProfileElement( aHProf,
icSigMediaWhitePointTag, 0, (
DWORD *)&theMediaSize, aPtr );
00174
if (!err){
00175 err = GetLastError();
00176
goto CleanupAndExit;
00177 }
00178
00179 err =
MyAdd_NL_CopyrightTag( (
unsigned char *)copyrightText, (
LHTextType *)aPtr);
00180
if (err)
00181
goto CleanupAndExit;
00182 err =
SetColorProfileElementSize( aHProf,
icSigCopyrightTag, theCopyRightSize );
00183
if (!err){
00184 err = GetLastError();
00185
goto CleanupAndExit;
00186 }
00187 err =
SetColorProfileElement( aHProf,
icSigCopyrightTag, 0, (
DWORD *)&theCopyRightSize, aPtr );
00188
if (!err){
00189 err = GetLastError();
00190
goto CleanupAndExit;
00191 }
00192
00193 err =
MyAdd_NL_SequenceDescTag( profileSet, (
icProfileSequenceDescType *)aPtr, &theSequenceDescSize );
00194
if (err)
00195
goto CleanupAndExit;
00196 err =
SetColorProfileElementSize( aHProf,
icSigProfileSequenceDescTag, theSequenceDescSize );
00197
if (!err){
00198 err = GetLastError();
00199
goto CleanupAndExit;
00200 }
00201 err =
SetColorProfileElement( aHProf,
icSigProfileSequenceDescTag, 0, (
DWORD *)&theSequenceDescSize, aPtr );
00202
if (!err){
00203 err = GetLastError();
00204
goto CleanupAndExit;
00205 }
00206
00207 aPtr =
DisposeIfPtr( aPtr );
00208
00209 theA2B0Size =
GetSizes( (
CMMModelPtr)cw, &clutSize );
00210
00211 aPtr =
SmartNewPtr( theA2B0Size, &aOSErr );
00212 err = aOSErr;
00213
if (err)
00214
goto CleanupAndExit;
00215
00216
if ( ((
CMMModelPtr)cw)->lutParam.colorLutWordSize == 8)
00217 err =
MyAdd_NL_AToB0Tag_mft1( (
CMMModelPtr)cw, (
icLut8Type *)aPtr, clutSize );
00218
else
00219 err =
MyAdd_NL_AToB0Tag_mft2( (
CMMModelPtr)cw, (
icLut16Type *)aPtr, clutSize );
00220
00221
if (err)
00222
goto CleanupAndExit;
00223
00224
00225 err =
SetColorProfileElementSize( aHProf,
icSigAToB0Tag, theA2B0Size );
00226
if (!err){
00227 err = GetLastError();
00228
goto CleanupAndExit;
00229 }
00230 err =
SetColorProfileElement( aHProf,
icSigAToB0Tag, 0, (
DWORD *)&theA2B0Size, aPtr );
00231
if (!err){
00232 err = GetLastError();
00233
goto CleanupAndExit;
00234 }
00235
00236 err =
noErr;
00237
00238 CleanupAndExit:
00239
CloseColorProfile( aHProf );
00240 aPtr =
DisposeIfPtr( aPtr );
00241
return err;
00242 }
00243
00244
#ifdef WRITE_PROFILE
00245
#ifdef IS_MAC
00246
00247
00248
#else
00249
#include <fcntl.h>
00250
#include <io.h>
00251
#include <sys/stat.h>
00252
#endif
00253
#include <stdio.h>
00254
00255
void WriteProf( LPSTR name,
icProfile *theProf,
long currentSize )
00256 {
00257
int fh;
00258
00259 fh = open( name, O_CREAT|O_RDWR|O_BINARY, _S_IREAD | _S_IWRITE );
00260
if( fh <= 0 ){
00261
#ifdef DEBUG_OUTPUT
00262
printf(
"Open %s failed\n",name);
00263
#endif
00264
return;
00265 }
00266 write( fh, (Ptr)theProf, currentSize );
00267 close(fh);
00268 }
00269
#endif
00270
00271
#include <io.h>
00272
#include <fcntl.h>
00273
#include <sys/stat.h>
00274 long SaveMyProfile( LPSTR lpProfileName, LPWSTR lpProfileNameW, PPROFILE theProf )
00275 {
00276
long ret;
00277
int fh;
00278
00279
if( theProf->dwType != PROFILE_MEMBUFFER ){
00280 SetLastError( (
unsigned long)
unimpErr );
00281
return 0;
00282 }
00283
if( lpProfileNameW == 0 ){
00284
if( lpProfileName == 0 )
return 0;
00285 fh = _open( lpProfileName, _O_BINARY | _O_CREAT | _O_EXCL, _S_IREAD | _S_IWRITE );
00286 }
00287
else{
00288 fh = _wopen( lpProfileNameW, _O_BINARY | _O_CREAT | _O_EXCL, _S_IREAD | _S_IWRITE );
00289 }
00290
if( fh == -1 )
return -1;
00291
00292
if( theProf->pProfileData == 0 ){
00293 SetLastError( ERROR_INVALID_DATA );
00294
return 0;
00295 }
00296 ret = _write( fh, theProf->pProfileData, theProf->cbDataSize );
00297
if( ret == -1 )
return -1;
00298
00299 ret = _close( fh );
00300
if( ret == -1 )
return -1;
00301
return 0;
00302 }