Esempio n. 1
0
void CChromaMask::MaskAddChroma(LPIMAGE lpImage, LPMASK lpMask, LPRECT lpRect, BOOL MaskExist)
{
	int         dx, dy, i, depth;
	LPTR        lpAlphaLine;
	LPTR        lpLine;
	LPOBJECT    lpBase = ImgGetBase(lpImage);
   	int         top = -1;
   	int         bottom = 0;
   	FRMTYPEINFO TypeInfo;

	ProgressBegin(1,PROGRESS_ID(IDS_CHROMA_APPLY));
	PixmapGetInfo(&lpMask->Pixmap, PMT_EDIT, &dx, &dy, NULL, NULL);
	
   	ImgGetTypeInfo(lpImage, &TypeInfo);
   	if (!(depth = FrameDepth(ObjGetEditFrame(lpBase))))
    	depth = 1; // never worry about lineart
	
   	xExtL = 10000;
   	xExtR = 0;
   	lpLine = Alloc((long)dx*depth);
	for (i = 0; i < dy; ++i)
	{
    	AstralClockCursor(i, dy, NO);
      	Dirty = FALSE;
		lpAlphaLine = PixmapPtr( &lpMask->Pixmap, PMT_EDIT, 0, i, YES);
      	if (Delete)
			clr(lpAlphaLine, dx);
      	ImgGetLine(lpImage, lpBase, 0, i, dx, lpLine, NULL);
      	ChromaProc(dx, TypeInfo, lpLine, lpAlphaLine, MaskExist);
      	if (Dirty)
        {
        	if (top == -1)
            	top = i;
         	if (i > bottom)
            bottom = i;
        }
	}
	lpRect->left   = xExtL;
   	lpRect->right  = xExtR;
   	lpRect->top    = top;
   	lpRect->bottom = bottom;
   	FreeUp(lpLine);
	ProgressEnd();
}
Esempio n. 2
0
void ImgInitDisplay(LPIMAGE lpImage, BOOL fGeneratePaletteLUT)
/***********************************************************************/
{
LPTR lpPaletteLUT;
RGBS RGBmap[256];
LPRGB lpRGBmap;
int nColors;
FRMTYPEINFO TypeInfo, DstTypeInfo = ColorManager.Monitor.dst;
LPOBJECT lpObject;

lpObject = lpImage->GetDisplayObject();
if (!lpObject)
	return;
FrameGetTypeInfo(ObjGetEditFrame(lpObject), &TypeInfo);

if ( lpBltScreen->BitMapInfo.bmiHeader.biBitCount == 8 &&
        !lpImage->lpPaletteLUT)
    {
    ProgressBegin(1, PROGRESS_ID(IDS_UNDOSETUPDISPLAY));
    if (TypeInfo.DataType == FDT_PALETTECOLOR)
        lpPaletteLUT = Alloc(32768L);
    else
        lpPaletteLUT = NULL;
    if (lpPaletteLUT)
        {
        if (TypeInfo.ColorMap->NumEntries > MAX8BITCOLORS)
            {
            nColors = MAX8BITCOLORS;
            lpRGBmap = RGBmap;
            if (!ReducePalette(TypeInfo.ColorMap->RGBData,  TypeInfo.ColorMap->NumEntries,
                                lpRGBmap, nColors))
                {
                FreeUp(lpPaletteLUT);
                lpPaletteLUT = NULL;
                }
            }
        else
            {
            lpRGBmap = TypeInfo.ColorMap->RGBData;
            nColors = TypeInfo.ColorMap->NumEntries;
            }
        }
    if (lpPaletteLUT)
        {
		if (fGeneratePaletteLUT)
	        CreatePaletteLut15(lpRGBmap, nColors, lpPaletteLUT, AstralClockCursor);
        lpImage->lpPaletteLUT = lpPaletteLUT;
        lpImage->PaletteType = PT_CUSTOMPALETTE;
        lpImage->hPal = CreateLogicalPalette(lpRGBmap, nColors);
		  GetObject(lpImage->hPal, sizeof(nColors), (void *)&nColors);
        lpImage->nPaletteEntries = GetPaletteEntries(lpImage->hPal,
                        0, nColors, lpImage->Palette);
        }
    else
        {
        if ( FrameType(ImgGetBaseEditFrame(lpImage)) <= FDT_GRAYSCALE)
            {
            lpImage->hPal = lpBltScreen->hGrayPal;
            lpImage->nPaletteEntries = lpBltScreen->nGrayEntries;
            lpImage->PaletteType = lpBltScreen->GrayPaletteType;
            lpImage->lpPaletteLUT = lpBltScreen->lpGrayPaletteLUT;
            copy((LPTR)lpBltScreen->GrayPalette,
                 (LPTR)lpImage->Palette,
                 sizeof(lpImage->Palette));
            }
        else
            {
            lpImage->hPal = lpBltScreen->hColorPal;
            lpImage->nPaletteEntries = lpBltScreen->nColorEntries;
            lpImage->PaletteType = lpBltScreen->ColorPaletteType;
            lpImage->lpPaletteLUT = lpBltScreen->lpColorPaletteLUT;
            copy((LPTR)lpBltScreen->ColorPalette,
                 (LPTR)lpImage->Palette,
                 sizeof(lpImage->Palette));
            }
        }
    ProgressEnd();
    }

if (lpImage->m_cmsXform)
	{
	if( Control.CMSEnabled && lpKCMSFreeProc )
		{
		if (lpImage->PtInfo.toRCS != TypeInfo.ptInfo.toRCS &&
			lpImage->PtInfo.frRCS != TypeInfo.ptInfo.frRCS )
			{
			( lpKCMSFreeProc )( lpImage->m_cmsXform );
			lpImage->m_cmsXform = NULL;
			}
		}
	else
		lpImage->m_cmsXform = NULL;
	}

	
if( Control.CMSEnabled &&
	IsSrcPTSelected( &TypeInfo.ptInfo ) &&
	IsDstPTSelected( &DstTypeInfo.ptInfo ) &&
	lpKCMSCnctProc )
	{
	lpImage->m_bDoCmsGamma = YES;
	if (!lpImage->m_cmsXform)
		{
		if( ( !FrameTypeInfoEqual( TypeInfo, DstTypeInfo ) ) &&
				ConvertCRCtoUID( &TypeInfo, &DstTypeInfo ) )
			{
			// save for later check to avoid a monitor reconnect.
			lpImage->PtInfo = TypeInfo.ptInfo;
			lpImage->m_cmsXform = ( *lpKCMSCnctProc )( &TypeInfo, &DstTypeInfo );
			}
		else
			lpImage->m_cmsXform = NULL;
		}
	}
else
	lpImage->m_cmsXform = NULL;
}
Esempio n. 3
0
int AstralImageImport( LPSTR lpInFile, LPSTR lpProfile, int nFileType )
//////////////////////////////////////////////////////////////////////////
{
    OFSTRUCT ofstruct;

    HINSTANCE hDLL              = NULL;
    HINSTANCE hSrcLibrary       = NULL;
    HINSTANCE hDstLibrary       = NULL;
    HINSTANCE hImportSetupData  = NULL;
    HINSTANCE hExportSetupData  = NULL;

    CREATESETUP  lpfnCreateSetup    = NULL;
    DESTROYSETUP lpfnDestroySetup   = NULL;
    IMPORTPROC   lpfnImportProc     = NULL;

    IMPORT_OPTIONS   Options;
    EXPORT_OPTIONS   Export;

    int error = IMPORT_NOERROR;

    FNAME szFilterPath;
    FNAME szOutFile; 
    FNAME szTempFile;
    FNAME szINIPath;
    char szFilter[13]; 
    char szINI[13]; 

    ProgressBegin( 1, PROGRESS_ID( IDS_UNDOIMPORTIMAGE ));

    szFilterPath[0] = szOutFile[0] = szTempFile[0] = szINIPath[0] = 0;
    szFilter[0] = szINI[0] = 0; 

    if( !nFileType || 
         nFileType < IDN_FIRSTIMPORTFILETYPE || 
         nFileType > IDN_LASTIMPORTFILETYPE )
    {
        error = IMPORT_INVALIDFILE_ERROR;
        goto ImportAbort;
    }

    // load ISGDI9.DLL explicitly
    GetModuleFileName( PictPubApp.Get_hInstAstral(), szFilterPath, sizeof( szFilterPath ));
    *strrchr( szFilterPath, '\\' ) = '\0';        
    lstrcat( szFilterPath, "\\" );
    lstrcat( szFilterPath, FILTER_DRIVER );

    hDLL = LoadLibrary( szFilterPath );

#ifdef WIN32
    if( hDLL == NULL )
#else
    if( hDLL < HINSTANCE_ERROR )
#endif
    {
        error = IMPORT_DLLLOAD_ERROR;
        goto ImportAbort;
    }

    // get filter and profile names
    GetImportFilter( nFileType, szFilter, szINI );

    // get location of filters
    GetExtNamePath( szFilterPath, IDN_IMPORTFILTERS );

    // set import filter path
    lstrcat( szFilterPath, szFilter );  

    if( OpenFile( szFilterPath, &ofstruct, OF_EXIST ) == HFILE_ERROR ) 
    {
        error = IMPORT_SRCLIBLOAD_ERROR;
        goto ImportAbort;
    }

    // set import filter profile path
    if( Control.bNetworkInstall )       // use pouch path
    {
        GetIniPath( szINIPath );
    }
    else                               // use filters directory
    {
        GetExtNamePath( szINIPath, IDN_IMPORTFILTERS );
    }
    lstrcat( szINIPath, szINI );  

#ifdef WIN32
    if(( hSrcLibrary = LoadLibrary( szFilterPath )) != NULL )
#else
    if(( hSrcLibrary = LoadLibrary( szFilterPath )) >= HINSTANCE_ERROR )
#endif
    {
        lpfnCreateSetup     = 
                ( CREATESETUP )GetProcAddress( hSrcLibrary, "CreateSetup" );
        hImportSetupData    = 
                ( HINSTANCE )( *lpfnCreateSetup )( hSrcLibrary, szINIPath, NULL, NULL );
    }
    else
    {
        error = IMPORT_SRCLIBLOAD_ERROR;
        goto ImportAbort;
    }

    // set export filter path 
    *strrchr( szFilterPath, '\\' ) = '\0';        
    lstrcat( szFilterPath, "\\" );
    lstrcat( szFilterPath, EXPORT_FILTER );

    if( OpenFile( szFilterPath, &ofstruct, OF_EXIST ) == HFILE_ERROR ) 
    {
        error = IMPORT_DSTLIBLOAD_ERROR;
        goto ImportAbort;
    }

#ifdef WIN32
    if(( hDstLibrary = LoadLibrary( szFilterPath )) != NULL )
#else
    if(( hDstLibrary = LoadLibrary( szFilterPath )) >= HINSTANCE_ERROR )
#endif
    {
        lpfnCreateSetup     = 
                ( CREATESETUP )GetProcAddress( hDstLibrary, "CreateSetup" );
        hExportSetupData    = 
                ( HINSTANCE )( *lpfnCreateSetup )( hDstLibrary, lpProfile, NULL, NULL );
    }
	else
    {
        error = IMPORT_DSTLIBLOAD_ERROR;
        goto ImportAbort;
    }

    memset( &Export, 0, sizeof( EXPORT_OPTIONS ));

    Export.GetSet_Status   = 
        ( GETSET_STATUS )MakeProcInstance(( FARPROC )GetSet_DialogStatus, PictPubApp.Get_hInstAstral());

    if( Export.GetSet_Status == NULL )
    {
        error = IMPORT_IMPORTFILE_ERROR;
        goto ImportAbort;
    }

    *strrchr( szFilterPath, '\\' ) = '\0';        
    *strrchr( szINIPath, '\\' ) = '\0';        

    memset( &Options, 0, sizeof( IMPORT_OPTIONS ));

    Options.hInputData     = hImportSetupData;      // Handle to import data
    Options.hOutputData    = hExportSetupData;      // Handle to export data
    Options.lpszDriverPath = szFilterPath;          // Driver DLL directory
    Options.lpszFontPath   = szFilterPath;          // Font file directory
    Options.lpExport       = &Export;

    // set temp file directory
    if( Control.bNetworkInstall )
        Options.lpszWorkPath   = szINIPath;         
    else
        Options.lpszWorkPath   = szFilterPath;         

    lstrcpy( szOutFile, Options.lpszWorkPath );     
    lstrcat( szOutFile, "\\" ); 

    // create temp file name
    lstrcpy( szTempFile, "PP" );
    GetTempFilename( szTempFile, ".TIF" );
    lstrcat( szOutFile, szTempFile );    

    lpfnImportProc = ( IMPORTPROC )GetProcAddress( hSrcLibrary, "ImportFile" );

    if( !( error = (( *lpfnImportProc )( NULL, EXPORT_FILTER, szOutFile, lpInFile, ( LPSTR )&Options ))))    
        lstrcpy( lpInFile, szOutFile );
    else
        FileDelete( szOutFile );        // get rid of temp file in case of error

    if( Export.GetSet_Status != NULL )
        FreeProcInstance(( FARPROC )Export.GetSet_Status );
    
ImportAbort:

#ifdef WIN32
    if( hDstLibrary != NULL )
#else
    if( hDstLibrary >= HINSTANCE_ERROR )
#endif
    {
        lpfnDestroySetup = ( DESTROYSETUP )GetProcAddress( hDstLibrary, "DestroySetup" );
        ( *lpfnDestroySetup )( hExportSetupData );

        FreeLibrary( hDstLibrary );
    }

#ifdef WIN32
    if( hSrcLibrary != NULL )
#else
    if( hSrcLibrary >= HINSTANCE_ERROR )
#endif
    {
        lpfnDestroySetup = ( DESTROYSETUP )GetProcAddress( hSrcLibrary, "DestroySetup" );
        ( *lpfnDestroySetup )( hImportSetupData );

        FreeLibrary( hSrcLibrary );
    }

#ifdef WIN32
    if( hDLL != NULL )
#else
    if( hDLL >= HINSTANCE_ERROR )
#endif
    {
        FreeLibrary( hDLL );
    }

    ProgressEnd();

    switch( error )
    {
        case IMPORT_NOERROR:
            break;

        case IMPORT_INVALIDFILE_ERROR:              // type not supported
            Message( IDS_INVALIDIMPORTFILE_ERROR );
            break;

        case IMPORT_SRCLIBLOAD_ERROR:               // error loading import filter
            Message( IDS_IMPORTLIBLOAD_ERROR );
            break;

        case IMPORT_DSTLIBLOAD_ERROR:               // error loading export filter
            Message( IDS_EXPORTLIBLOAD_ERROR );
            break;

        case IME_INVALID_FILE_TYPE:                 // incorrect file format
            Message( IDS_INVALIDIMPORTFILE_TYPE );
            break;

        case IME_INVALID_FILE_VERSION:              // unsupported file version
            Message( IDS_INVALIDIMPORTFILE_VERSION );
            break;

        case IME_MEMORY:                            // insufficient memory
            Message( IDS_EMEMALLOC );
            break;

        case IMPORT_DLLLOAD_ERROR:
        case IMPORT_IMPORTFILE_ERROR:               // non-specific error from app
        default:                                    // non-specific error from filter
            Message( IDS_IMPORTFILE_ERROR );    
            break;
    }
    return error;
}
Esempio n. 4
0
BOOL CombineObjObjects( LPIMAGE lpImage, LPCMD_PARMS lpCmdParms )
/************************************************************************/
{
RECT		rCombine,r;
LPOBJECT	lpBase, lpObj;
LPALPHA	lpAlpha, lpMask;
LPFRAME	lpDFrame, lpSFrame;
LPTR		lpDF, lpDM, *lpSM, *lpSF;
int		x, y, yy, depth;
int      N, H, W, i;
double  *lpAlphaTable, *AiXOi;
double   red,blue,green,k;
POINT    pt;
double   Oi, Ai, Mi, Mc;
LPOBJECT *lpObject;
FRMTYPEINFO TypeInfo;
BOOL	fCanDoOpacity;
FRMDATATYPE MaskType = FDT_GRAYSCALE;

if (!(lpImage))
	return( FALSE );

ImgGetTypeInfo(lpImage, &TypeInfo);
if (TypeInfo.DataType == FDT_LINEART && Mask.OneBitMask)
   MaskType = FDT_LINEART;
fCanDoOpacity = CANDOTRANSPARENCY(TypeInfo.DataType);

lpObj = lpBase = ImgGetBase(lpImage);
if (!(depth = FrameDepth(ObjGetEditFrame(lpBase))))
   depth = 1; // never worry about lineart
N = ImgCountSelObjects(lpImage, NULL);
ImgGetSelObjectRect(lpImage, &rCombine, YES);
H = RectHeight(&rCombine);
W = RectWidth (&rCombine);

lpObject = NULL;
AiXOi = lpAlphaTable = NULL;

lpAlphaTable = (double *)Alloc((N+1) * sizeof(double));
AiXOi        = (double *)Alloc(N * sizeof(double));
lpSM         = (LPTR *)Alloc(N * sizeof(LPTR));
lpSF         = (LPTR *)Alloc(N * sizeof(LPTR));
lpObject     = (LPOBJECT *)Alloc(N * sizeof(LPOBJECT));
lpAlpha = MaskCreate(NULL, W, H, YES, Control.NoUndo, MaskType);
lpDFrame = ImgGetBaseEditFrame(lpImage);
lpDFrame = FrameOpen(FrameType(lpDFrame), W, H, FrameResolution(lpDFrame));

if (!lpAlphaTable || !lpObject || !AiXOi || !lpAlpha || !lpDFrame || !lpSM || !lpSF)
    {
    if (lpAlphaTable)
      FreeUp(lpAlphaTable);
    if (lpObject)
      FreeUp(lpObject);
    if (AiXOi)
      FreeUp(AiXOi);
    if (lpDFrame)
      FreeUp(lpDFrame);
    if (lpSF)
      FreeUp(lpSF);
    if (lpSM)
      FreeUp(lpSM);
      
    Message(IDS_EMEMALLOC);
    return(FALSE);
    }

for (i=0; i < N; i++)
   lpObj = lpObject[i] = ImgGetSelObject(lpImage, lpObj);

ImgEditInit(lpImage, ET_OBJECT, UT_DELETEOBJECTS, lpBase);

ProgressBegin(1, PROGRESS_ID(IDS_UNDOOBJCOMBOBJS));
for (y = 0; y <= H; y++)
   {
 	AstralClockCursor(y, H, NO);

   lpDF = FramePointer(lpDFrame, 0, y, YES);
   lpDM = PixmapPtr(&lpAlpha->Pixmap, PMT_EDIT, 0, y, YES);
   pt.y = y + rCombine.top;

   for (i=0; i < N; i++)
      {
      yy = pt.y - lpObject[i]->rObject.top;
      lpSFrame = ObjGetEditFrame(lpObject[i]);
      lpSF[i] = FramePointer(lpSFrame, 0, yy, NO);
      lpMask   = ObjGetAlpha(lpObject[i]);
      lpSM[i] = PixmapPtr(&lpMask->Pixmap, PMT_EDIT, 0, yy, NO);
      }
   
	for (x = 0; x < W; x++)
      {
      lpAlphaTable[N] = 1.0;
      pt.x = x + rCombine.left;

      for (i=N-1; i >= 0; i--)
         {
         r = lpObject[i]->rObject;
         r.bottom++;
         r.right++;
         if (PtInRect(&r, pt))
            {
			   if (fCanDoOpacity)
	           	Oi = lpObject[i]->Opacity / 255.0;
            else
					Oi = 1;
			   if (fCanDoOpacity)
	            Ai = *lpSM[i]++ / 255.0;
			   else if (*lpSM[i] < 128)
               {
               Ai = 0;
				   lpSM[i]++;
               }
			   else
			      {
				   Ai = 1;
				   lpSM[i]++;
			      }
            AiXOi[i] = Oi * Ai;
            lpAlphaTable[i] = lpAlphaTable[i+1] * (1.0 - AiXOi[i]);
            }
         else
            {
            AiXOi[i] = 1.0;
            lpAlphaTable[i] = lpAlphaTable[i+1];
            }
         }
      Mc = 1.0 - lpAlphaTable[0];
      lpDM[x] = (BYTE)(Mc * 255);

      red = blue = green = k = 0;
      for (i=0; i < N; i++)
         {
         r = lpObject[i]->rObject;
         r.bottom++;
         r.right++;
         if (PtInRect(&r, pt))
            {
            Mi = AiXOi[i] * lpAlphaTable[i+1];
            switch(depth)
               {
               case 1:
                  red     += *lpSF[i]++ * Mi;
                  break;
               case 3:
                  red     += *lpSF[i]++ * Mi;
                  green   += *lpSF[i]++ * Mi;
                  blue    += *lpSF[i]++ * Mi;
                  break;
               case 4:
                  red     += *lpSF[i]++ * Mi;
                  green   += *lpSF[i]++ * Mi;
                  blue    += *lpSF[i]++ * Mi;
                  k       += *lpSF[i]++ * Mi;
                  break;
               }
            }
         }

      if (Mc == 0.0)
         Mc = 1.0;
      switch(depth)
         {
         case 1:
            *lpDF++ = (BYTE)(red / Mc);
            break;
         case 3:
            *lpDF++ = (BYTE)(red   / Mc);
            *lpDF++ = (BYTE)(green / Mc);
            *lpDF++ = (BYTE)(blue  / Mc);
            break;
         case 4:
            *lpDF++ = (BYTE)(red   / Mc);
            *lpDF++ = (BYTE)(green / Mc);
            *lpDF++ = (BYTE)(blue  / Mc);
            *lpDF++ = (BYTE)(k     / Mc); 
            break;
         }
      }
   }

lpObj = ObjCreateFromFrame(ST_PERMANENT, lpDFrame, lpAlpha, &rCombine,
	Control.NoUndo );
lpObj->fSelected = YES;
lpObj->fUndoDeleted = YES;
ImgAddNewObject(lpImage, lpObj);
for (i=0; i < N; i++)
   lpObject[i]->fDeleted = YES;
ImgEditedObject(lpImage, lpBase, IDS_UNDOOBJCOMBOBJS, NULL);
UpdateImage(lpImage, &rCombine, YES);

FreeUp(lpSM);
FreeUp(lpSF);
FreeUp(AiXOi);
FreeUp(lpAlphaTable);
FreeUp(lpObject);
ProgressEnd();
return( TRUE );
}