Exemplo n.º 1
0
BOOL CImage::DuplicateSelObjects()
{
LPOBJECT lpDupObject;
OBJECTLIST DupList;
LPOBJECT lpObject;
RECT rUpdate;
WORD wGroupID, wOldGroupID, wLastGroupID;

if (!ImgEditInit( this, ET_OBJECT, UT_DELETEOBJECTS, GetBase() ))
    return(FALSE);

DupList.lpHead = DupList.lpTail = NULL;
lpObject = NULL;
while (lpObject = GetSelObject(lpObject))
    {
    if (!(lpDupObject = ObjDuplicateObject(lpObject)))
        {
        ObjDeleteObjects(&DupList, ST_ALL);
        return(FALSE);
        }
    ObjAddTail(&DupList, (LPPRIMOBJECT)lpDupObject);
    }
wLastGroupID = wGroupID = GetNextGroupID();
lpDupObject = NULL;
while (lpDupObject = (LPOBJECT)ObjGetNextObject(&DupList,
                    (LPPRIMOBJECT)lpDupObject, YES))
    {
    if (!lpDupObject->wGroupID || lpDupObject->wGroupID >= wLastGroupID)
        continue;
    wOldGroupID = lpDupObject->wGroupID;
    lpDupObject->wGroupID = wGroupID;
    lpObject = lpDupObject;
    while (lpObject = (LPOBJECT)ObjGetNextObject(&DupList,
                    (LPPRIMOBJECT)lpObject, YES))
        {
        if (lpObject->wGroupID == wOldGroupID)
            lpObject->wGroupID = wGroupID;
        }
    ++wGroupID;
    }

RemoveObjectMarquee(this);
ObjDeselectAll(&ObjList);
while (lpObject = (LPOBJECT)ObjGetNextObject(&DupList, NULL, YES))
    {
    ObjUnlinkObject(&DupList, (LPPRIMOBJECT)lpObject);
    ObjSelectObject( (LPPRIMOBJECT)lpObject, YES ); // Select the new object
    ObjAddTail( &ObjList, (LPPRIMOBJECT)lpObject ); // Add to the image's list
    lpObject->fUndoDeleted = YES;
    }
ImgEditedObject(this, GetBase(), IDS_UNDODUPLICATE, NULL);

GetSelObjectRect(&rUpdate, NO);
UpdateImage(this, &rUpdate, YES);
SetupMiniViews(NULL, NO);
return(TRUE);
}
Exemplo n.º 2
0
BOOL CChromaMask::JoinChromaMask(LPIMAGE lpImage, LPRECT lpUpdateRect)
{
	LPOBJECT    lpBase;
	LPMASK      lpMask;
	RECT        rDummy;
   	RECT        rMask;
	BOOL        fNewMask = NO;
   	BOOL        fCreateMask = NO;
   	UNDO_TYPE   Type;

   	AstralSetRectEmpty(lpUpdateRect);
   	if (ImgGetMask(lpImage))
    	Type = UT_ALPHA;
   	else
    {
    	fNewMask = TRUE;
      	Type = UT_CREATEMASK;
    }
         
	// get mask, create one if one does not exist
	lpMask = ImgGetMaskEx(lpImage, iMode==SHAPE_SUBTRACT ? OFF : ON, 
            Control.NoUndo, &fNewMask, lpUpdateRect);
	if (!lpMask)
		return(FALSE);

	// if not new mask and we are allowed to create undo, initialize undo
	lpBase = ImgGetBase(lpImage);
 	if (!ImgEditInit(lpImage, ET_OBJECT,Type, lpBase))
		return(FALSE);

	EnableMarqueeEx( lpImage, NO );

	// add Chroma to mask
	MaskAddChroma(lpImage, lpMask, &rMask, !fNewMask);
	AstralUnionRect(lpUpdateRect, lpUpdateRect, &rMask);

	// if using undo, indicate in-place editing has occurred
	ImgEditedObject(lpImage, lpBase, IDS_CHROMA_APPLY,	fNewMask ? NULL : &rMask);

	// after subtractive masks we dont know area
	if (iMode!=SHAPE_ADD)
		MaskRectUpdate(lpMask, &rDummy);

	// get area that needs to be redisplayed, may be larger
	// than rUpdate because of slime
	if (ImgGetMaskUpdateRect(lpImage, fNewMask, NO, &rMask))
		AstralUnionRect(lpUpdateRect, lpUpdateRect, &rMask);

	EnableMarqueeEx(lpImage, YES);
	return(TRUE);
}
Exemplo n.º 3
0
STATUS_CODE ApplyColorMap(LPIMAGE lpImage, LPCOLORMAP lpColorMap, BOOL fReMap,
							DITHER_TYPE DitherType,	ITEMID idDirty)
/************************************************************************/
{
	UNDO_TYPE UndoType;
	int iMaxWidth;
	FRMTYPEINFO OldTypeInfo, NewTypeInfo;
	LPOBJECT lpObject;
	RECT rEdit;
	CFrameTypeConvert TypeConvert;

	UndoType = UT_COLORMAP;
	if (fReMap)
		UndoType |= UT_DATA;
	if (!ImgEditInit(lpImage, ET_ALLOBJECTS, UndoType, NULL))
		return(SC_UNDOERROR);

	ProgressBegin(ImgCountObjects(lpImage), idDirty-IDS_UNDOFIRST+IDS_PROGFIRST);
	if (fReMap)
	{	
		ImgGetTypeInfo(lpImage, &OldTypeInfo);
		FrameSetTypeInfo(&NewTypeInfo, FDT_PALETTECOLOR, lpColorMap);

		iMaxWidth = 0;
		lpObject = NULL;
		while (lpObject = ImgGetNextObject(lpImage, lpObject, YES, NO))
		{
			if (RectWidth(&lpObject->rObject) > iMaxWidth)
				iMaxWidth = RectWidth(&lpObject->rObject);
		}
		if (!TypeConvert.Init(OldTypeInfo, NewTypeInfo, iMaxWidth, DitherType))
		{
			ProgressEnd();
			Message(IDS_EMEMALLOC);
			return(SC_MEMERROR);
		}
	}
	lpObject = NULL;
	while (lpObject = ImgGetNextObjectEx(lpImage, lpObject, YES, NO, YES))
	{
		if (fReMap)
			PaletteMapPixmap(&lpObject->Pixmap, &TypeConvert);
		FrameSetColorMap(ObjGetEditFrame(lpObject), lpColorMap);
		rEdit = lpObject->rObject;
		ImgEditedObject(lpImage, lpObject, idDirty, &rEdit);
	}
	ImgColorMapChanged(lpImage);
	ProgressEnd();

	return(SC_SUCCESS);
}
Exemplo n.º 4
0
BOOL PosObjects( LPIMAGE lpImage, LPPOSOBJECTS_PARMS lpPosParms )
/************************************************************************/
{
RECT		bRect, uRect;
LPOBJECT	lpObject;
int      res;
int      x,y;

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

if( !( lpObject = ImgGetBase( lpImage ) )	)
   return( FALSE );

ImgEditInit( lpImage, ET_SELOBJECTS, UT_OBJECTRECT, lpObject );

ImgGetInfoEx(lpImage, NULL, NULL, NULL, NULL, &res);
x = lpPosParms->XOffset;
y = lpPosParms->YOffset;
ResConvertUL(lpPosParms->iBaseRes, res, &x, &y);

ImgGetSelObjectRect( lpImage, &bRect, YES );
x -= bRect.left;
y -= bRect.top;

while ( lpObject = ImgGetSelObject(lpImage, lpObject) )
   {
	if( lpObject->wGroupID )
		{
		if( !( IsGroupLocked( lpObject->wGroupID ) ) )
			{
  			ImgEditedObject( lpImage, lpObject, IDS_UNDOOBJPOS, NULL );
			OffsetRect( &lpObject->rObject, x, y);
			}
		}
	else if (!lpObject->bLocked)
		{
  		ImgEditedObject( lpImage, lpObject, IDS_UNDOOBJPOS, NULL );
		OffsetRect( &lpObject->rObject, x, y);
		}

   }
ImgGetSelObjectRect( lpImage, &uRect, YES );
AstralUnionRect( &uRect, &uRect, &bRect );
UpdateImage( lpImage, &uRect, YES );
return( TRUE );
}
Exemplo n.º 5
0
BOOL UnGroupObjects(LPIMAGE lpImage, LPCMD_PARMS lpCmdParms)
   {
   LPOBJECT lpObject = NULL;

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

   if( !( lpObject = ImgGetBase( lpImage ) )	)
      return( FALSE );

   ImgEditInit(lpImage, ET_SELOBJECTS, UT_GROUPOBJECTS, lpObject );
   while (lpObject = ImgGetSelObject(lpImage, lpObject))
      {
	   ImgEditedObject( lpImage, lpObject, IDS_UNDOUNGROUPOBJ, NULL );
      lpObject->wGroupID = 0;
      }
   return(TRUE);
   }
Exemplo n.º 6
0
BOOL UnLockObjects( LPIMAGE lpImage, LPCMD_PARMS lpCmdParms )
/************************************************************************/
{
LPOBJECT	lpObject;

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

if( !( lpObject = ImgGetBase( lpImage ) )	)
   return( FALSE );

ImgEditInit( lpImage, ET_SELOBJECTS, UT_LOCKOBJECTS, lpObject );

while ( lpObject = ImgGetSelObject(lpImage, lpObject) )
   {
	ImgEditedObject( lpImage, lpObject, IDS_UNDOOBJUNLOCK, NULL );
	lpObject->bLocked = NO;
	}
return( TRUE );
}
Exemplo n.º 7
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 );
}
Exemplo n.º 8
0
BOOL AlignObjects( LPIMAGE lpImage, LPALIGNOBJECTS_PARMS lpAlignParms )
/************************************************************************/
{
RECT		bRect, gRect, uRect;
LPOBJECT	lpObject, lpGroupObject;
int		xOffset, yOffset, gXOffset, gYOffset, nWidth, nHeight, nCount;
LFIXED	hSpace, vSpace, fx, fy;
WORD		wGroupIDs[NUM_GROUPS];

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

if( !( lpObject = ImgGetBase( lpImage ) )	)
   return( FALSE );

if( !( lpAlignParms->bPreview ) )
	{
	if( !( ImgEditInit( lpImage, ET_SELOBJECTS, UT_OBJECTRECT, lpObject ) ) )
		return( FALSE );
	}

if( lpAlignParms->RectAlign == RA_IMAGE )
	{	
	ImgGetImageRect( lpImage, &bRect );
	}
else
	{	
	if( lpAlignParms->RectAlign == RA_MASK )
  		ImgGetMaskRect( lpImage, &bRect );
	else
		ImgGetSelObjectRect( lpImage, &bRect, YES );
	}

ImgGetSelObjectRect( lpImage, &uRect, YES );


nWidth = RectWidth( &bRect );
nHeight = RectHeight( &bRect );

nCount = 0;

InitGroupList( wGroupIDs );

while ( lpObject = ImgGetSelObject(lpImage, lpObject) )
   {
	if( lpObject->wGroupID )
		{
		if( !( IsPrevGroup( lpObject->wGroupID, wGroupIDs ) ) &&
			!( IsGroupLocked( lpObject->wGroupID ) ) )
			{
			SetGroupList( lpObject->wGroupID, wGroupIDs );
			lpImage->GetGroupRect( lpObject, &gRect );
			nWidth -= RectWidth( &gRect );
			nHeight -= RectHeight( &gRect );
			++nCount;
			}
		}
	else if (!lpObject->bLocked)
		{
		nWidth -= RectWidth( &lpObject->rObject );
		nHeight -= RectHeight( &lpObject->rObject );
		++nCount;
		}
	}

if( nCount == 0 )
	return( FALSE );

hSpace = FGET( nWidth, nCount - 1 );
vSpace = FGET( nHeight, nCount - 1 );

fx = fy = 0;

InitGroupList( wGroupIDs );

lpObject = ImgGetBase( lpImage );

while ( lpObject = ImgGetSelObject(lpImage, lpObject) )
   {
	if( lpObject->wGroupID )
		{
		if( !( IsPrevGroup( lpObject->wGroupID, wGroupIDs ) ) &&
			!( IsGroupLocked( lpObject->wGroupID ) ) )
			{
			SetGroupList( lpObject->wGroupID, wGroupIDs );
			lpImage->GetGroupRect( lpObject, &gRect );
			ObjAlign( &bRect, &gRect, lpAlignParms, vSpace, hSpace,
				&gXOffset, &gYOffset, &fx, &fy );
			lpGroupObject = ImgGetBase( lpImage );
			while( lpGroupObject = ImgGetSelObject( lpImage, lpGroupObject ) )
				{
				if( lpObject->wGroupID == lpGroupObject->wGroupID )
					{
					if( !( lpAlignParms->bPreview ) )
						ImgEditedObject( lpImage, lpGroupObject, IDS_UNDOOBJALIGN,
							NULL );
					OffsetRect( &lpGroupObject->rObject, gXOffset, gYOffset );
					}
				}
			}
		}
	else if (!lpObject->bLocked)
		{
		ObjAlign( &bRect, &lpObject->rObject, lpAlignParms, vSpace, hSpace,
			&xOffset, &yOffset, &fx, &fy ); 
		if( !( lpAlignParms->bPreview ) )
			ImgEditedObject( lpImage, lpObject, IDS_UNDOOBJALIGN, NULL );
		OffsetRect( &lpObject->rObject, xOffset, yOffset );
		}
   }
ImgGetSelObjectRect( lpImage, &bRect, YES );
AstralUnionRect( &uRect, &uRect, &bRect );
UpdateImage( lpImage, &uRect, YES );
return( TRUE );
}
Exemplo n.º 9
0
BOOL CImage::CombineObjects(BOOL fNoUndo, BOOL fCreateMask,
                        BOOL fForceIt, ITEMID idDirty, LPRECT lpUpdateRect)
{
LPOBJECT lpBase, lpObject;
int     iWidth, iHeight, depth, y, iImageWidth, iImageHeight;
LPTR    lpDataBuf, lpMaskPtr;
RECT    rFloaters, rMask, rTemp;
BOOL fNewMask;
LPMASK lpMask;
UNDO_TYPE UndoType;

AstralSetRectEmpty(lpUpdateRect);

// get rectangle for all floating objects
if (!GetFloatingObjectsRect(&rFloaters))
    return(FALSE);

// Get base object
lpBase = GetBase();

// get pixmap information
PixmapGetInfo(&lpBase->Pixmap, PMT_EDIT, &iImageWidth, &iImageHeight, &depth, NULL);
BoundRect(&rFloaters, 0, 0, iImageWidth-1, iImageHeight-1);

iWidth = RectWidth(&rFloaters);
iHeight = RectHeight(&rFloaters);

// allocate buffer for alpha channel combining
if (!(lpDataBuf = Alloc((long)iWidth*depth)))
    {
    Message(IDS_EMEMALLOC);
    return(FALSE);
    }

lpMask = NULL;
if (fCreateMask)
    {
    lpMask = GetMaskEx(OFF, Control.NoUndo, &fNewMask, &rTemp);
    AstralUnionRect(lpUpdateRect, lpUpdateRect, &rTemp);
    }


// do it to it
ProgressBegin(lpMask != NULL ? 2 : 1, idDirty-IDS_UNDOFIRST+IDS_PROGFIRST);

if (!fNoUndo)
    {
    UndoType = UT_DATA|UT_DELETEOBJECTS;
    if (lpMask)
        {
        if (fNewMask)
            UndoType |= UT_CREATEMASK;
        else
            UndoType |= UT_ALPHA;
        }
    if (!ImgEditInit(this, ET_OBJECT, UndoType, lpBase))
        {
        if (!fForceIt)
            {
            ProgressEnd();
            FreeUp(lpDataBuf);
            return(FALSE);
            }
        }
    }

// do it to it
ProgressBegin(1, 0);
for (y = rFloaters.top; y <= rFloaters.bottom; ++y)
    {
    AstralClockCursor(y-rFloaters.top, iHeight, NO);
    ImgGetLine(this, NULL, rFloaters.left, y, iWidth, lpDataBuf);
    PixmapWrite(&lpBase->Pixmap, PMT_EDIT, rFloaters.left, y, iWidth,
                lpDataBuf, iWidth);
    }
ProgressEnd();

if (lpMask && (lpObject = GetNextObject(lpBase, YES, NO)))
    {
    ProgressBegin(1, 0);
    for (y = rFloaters.top; y <= rFloaters.bottom; ++y)
        {
        AstralClockCursor(y-rFloaters.top, iHeight, NO);
        lpMaskPtr = PixmapPtr(&lpMask->Pixmap, PMT_EDIT, rFloaters.left,
                            y, YES);
        if (!lpMaskPtr)
            continue;
        ImgMaskLoad(this, lpObject, NULL,
                rFloaters.left, y, iWidth, lpDataBuf, NO,
                CR_OR, 0, 0);
        CombineData(lpDataBuf, lpMaskPtr, iWidth, NO, CR_OR);
        }
    MaskRectUpdate(lpMask, &rMask); 
    ProgressEnd();
    }

FreeUp(lpDataBuf);

GetObjectMarqueeRect(this, &rTemp);
AstralUnionRect(lpUpdateRect, lpUpdateRect, &rTemp);
lpObject = lpBase;
while (lpObject = GetNextObject(lpObject, YES, NO))
    {
// always let undo stuff initialize this
//  lpObject->fUndoDeleted = NO;
    lpObject->fDeleted = YES;
    }
//DeleteObjects((LPOBJECT)lpBase->lpNext, NO);

if (!fNoUndo)
    ImgEditedObject(this, lpBase, idDirty, &rFloaters);
else
    fChanged = YES;

//if ( Tool.hRibbon )
//  SendMessage( Tool.hRibbon, WM_CONTROLENABLE, 0, 0L );
ProgressEnd();
//SetupMiniViews(NULL, NO);
return(TRUE);
}
Exemplo n.º 10
0
BOOL ConvertImage(LPIMAGE lpImage, LPCONVERT_PARMS lpParms)
/***********************************************************************/
{
BOOL fRet = FALSE;
LPFRAME lpDstFrame, lpBaseFrame;
LPOBJECT lpBase, lpObject;
BOOL fError, fOptimize, fProgressSet;
INTERNAL_DATA data;
int	inDepth, iMaxWidth, nColors, i;
LPCOLORMAP lpColorMap;
LPRGB lpRGB;
FRMTYPEINFO InTypeInfo, OutTypeInfo;
CFrameTypeConvert TypeConvert;
DITHER_TYPE DitherType = DT_DEFAULT;

if (ImgInMaskEditMode(lpImage))
	return(TRUE);

lpColorMap = NULL;

lpBase = ImgGetBase(lpImage);
lpBaseFrame = ObjGetEditFrame(lpBase);
inDepth = FrameDepth(lpBaseFrame);

OutTypeInfo = lpParms->cmsInfo.dst;
FrameGetTypeInfo(lpBaseFrame, &InTypeInfo);

// are we try to convert to a color managed image?
if (Control.CMSEnabled && IsDstPTSelected(&OutTypeInfo.ptInfo))
	{
	// see if our image already has a color managed source
	if (!IsSrcPTSelected(&InTypeInfo.ptInfo))
		{
		// nope, see if the source passed in is valid for this image
		if (IsSrcPTSelected(&lpParms->cmsInfo.src.ptInfo) &&
			(lpParms->cmsInfo.src.DataType == InTypeInfo.DataType))
			{	
			InTypeInfo = lpParms->cmsInfo.src;
			}
		// go get a source from the user
		else
			{
			CMSINFO CmsInfo2;
			if( CmsGetSrcPTType( &InTypeInfo, &CmsInfo2) )
				InTypeInfo = CmsInfo2.src;
			}
		}
	}
else
 	FrameSetTypeInfo(&InTypeInfo, InTypeInfo.DataType, InTypeInfo.ColorMap);

// no conversion necessary
if (FrameTypeInfoEqual(InTypeInfo, OutTypeInfo))
	return(TRUE);

DitherType = lpParms->DitherType;
fOptimize = lpParms->ConvertType == CT_OPTIMIZED;
fProgressSet = FALSE;


if ( OutTypeInfo.DataType == FDT_PALETTECOLOR/* && inDepth >= 3 */)
	{
	if (lpParms->ConvertType == CT_CUSTOM)
		{
		FNAME szFileName;

		if ( !LookupExtFileN( lpParms->szPalette, szFileName, IDN_PALETTE, NO ) )
			return(FALSE);
		if (!(lpColorMap = Palette_ReadColorMap(szFileName)))
			return(FALSE);
		}
	else
		{
		// allocate a map to carry around with image
		lpColorMap = FrameCreateColorMap();
		if (!lpColorMap)
			{
			Message(IDS_EMEMALLOC);
			goto MemError;
			}

		lpColorMap->NumEntries = lpParms->iLevels;

		if (InTypeInfo.DataType == FDT_GRAYSCALE && lpColorMap->NumEntries == 256 &&
			fOptimize)
			{
			DitherType = DT_NONE;
			lpRGB = lpColorMap->RGBData;
			for (i = 0; i < lpColorMap->NumEntries; ++i)
				{
				lpRGB->red = lpRGB->green = lpRGB->blue = i;
				++lpRGB;
				}
			}
		else
			{
			// 1. CreateOptimizedPalette phase - only if fOptimize
			// 2. Mapping phase
			ProgressBegin(fOptimize ? 2 : 1,
					lpParms->Common.idDirty-IDS_UNDOFIRST+IDS_PROGFIRST);
			fProgressSet = TRUE;
			if (fOptimize)
				ProgressBegin(1, 0);
			if (!CreateOptimizedPalette(lpBase, ObjGetEditFrame(lpBase),
									lpColorMap->RGBData, &lpColorMap->NumEntries,
									fOptimize,
									fOptimize ? AstralClockCursor : NULL))
				{
				if (fOptimize)
					ProgressEnd();
				Message(IDS_EMEMALLOC);
				goto ExitFalse;
				}
			if (fOptimize)
				ProgressEnd();
			}
		}
	if (lpColorMap->NumEntries <= 16)
		lpColorMap->NumEntries = 16;
	else
		lpColorMap->NumEntries = 256;
	FrameSetTypeInfo(&OutTypeInfo, FDT_PALETTECOLOR, lpColorMap);
	}

if (!fProgressSet)
	ProgressBegin(1, lpParms->Common.idDirty-IDS_UNDOFIRST+IDS_PROGFIRST);
fProgressSet = TRUE;
	
iMaxWidth = 0;
lpObject = NULL;
while (lpObject = ImgGetNextObject(lpImage, lpObject, YES, NO))
	{
	if (RectWidth(&lpObject->rObject) > iMaxWidth)
		iMaxWidth = RectWidth(&lpObject->rObject);
	}
if (!TypeConvert.Init(InTypeInfo, OutTypeInfo, iMaxWidth, DitherType))
	{
	Message(IDS_EMEMALLOC);
	goto ExitFalse;
	}

if (ImgMultipleObjects(lpImage))
	{
	ProgressBegin(ImgCountObjects(lpImage), 0);
	
	if ( !ImgEditInit(lpImage, ET_ALLOBJECTS, UT_NEWDATA|UT_COLORMAP, lpBase) )
		goto ExitFalse;

	fError = NO;
	lpObject = NULL;
	while (lpObject = ImgGetNextObject(lpImage, lpObject, YES, NO))
		{
		lpDstFrame = ConvertFrame(ObjGetEditFrame(lpObject), OutTypeInfo, &TypeConvert);
		if (!lpDstFrame)
			{
			fError = YES;
			break;
			}
 		ImgEditedObjectFrame( lpImage, lpObject, lpParms->Common.idDirty, NULL,
						lpDstFrame, NULL);
		}

	if (fError)
		{
		lpObject = NULL;
		while (lpObject = ImgGetNextObject(lpImage, lpObject, YES, NO))
			{
			if (lpObject->Pixmap.UndoFrame)
				{
		 		lpDstFrame = lpObject->Pixmap.EditFrame;
		 		lpObject->Pixmap.EditFrame = lpObject->Pixmap.UndoFrame;
		 		lpObject->Pixmap.UndoFrame = NULL;
		 		FrameClose(lpDstFrame);
		 		}
			}
		}
	ProgressEnd();
	}
else
	{
	if ( !ImgEditInit(lpImage, ET_OBJECT, UT_NEWDATA|UT_COLORMAP, lpBase) )
		goto ExitFalse;

	ProgressBegin(1, 0);
	lpDstFrame = ConvertFrame(lpBaseFrame, OutTypeInfo, &TypeConvert);
	ProgressEnd();

	if (!lpDstFrame)
		goto ExitFalse;
	/* Setup the new image and bring up the new image window */
	ImgEditedObjectFrame( lpImage, lpBase, lpParms->Common.idDirty, NULL,
						lpDstFrame, NULL);
	}

switch (lpParms->cmsInfo.dst.DataType)
	{
	case FDT_LINEART:
		lpImage->DataType = IDC_SAVELA;
		break;
	case FDT_GRAYSCALE:
		lpImage->DataType = IDC_SAVECT;
		break;
	case FDT_PALETTECOLOR:
		lpImage->DataType = IDC_SAVE8BITCOLOR;
		break;
	case FDT_RGBCOLOR:
		lpImage->DataType = IDC_SAVE24BITCOLOR;
		break;
	case FDT_CMYKCOLOR:
		lpImage->DataType = IDC_SAVE32BITCOLOR;
		break;
	}
ImgColorMapChanged(lpImage);
lpParms->Common.UpdateType = UT_DATATYPE;

fRet = TRUE;

ExitFalse:
if (fProgressSet)
	ProgressEnd();
MemError:
if (lpColorMap)
	FrameDestroyColorMap(lpColorMap);
return(fRet);
}
Exemplo n.º 11
0
int LinesProc( HWND hWindow, LPARAM lParam, UINT msg )
/************************************************************************/
{
int x, y, fx, fy;
LPOBJECT lpObject;
RGBS rgb;
LPFRAME lpFrame;
STRING szOptions;
static RGBS rgbLast;

x = LOWORD(lParam);
y = HIWORD(lParam);
switch (msg)
    {
    case WM_CREATE:	// The first mouse down message
	if (!ONIMAGE(x, y))
		break;
	Display2File(&x, &y);
	if ( !ImgSelectObjectType( lpImage, x, y,
		YES/*bAllowBase*/, YES/*bAllowMovable*/, NO/*bAllowPlayable*/ ) )
			break;
	if (!Retouch.hBrush)
		break;
	GetActiveRGB( &rgb );
	if ( rgb.red != rgbLast.red || rgb.green != rgbLast.green ||
		 rgb.blue != rgbLast.blue )
		{ // if a color change, restuff the brush source
		OptionGetString( hOptions, iTool+1, szOptions );
		lpFrame = TiffResource2Frame( hOptions, (LPSTR)MAKEINTRESOURCE(iTool+1) );
		SetSimpleBrushSource( Retouch.hBrush, lpFrame, szOptions );
		rgbLast = rgb;
		}
	Tool.bActive = YES;
	break;

	case WM_SETCURSOR:
	return( SetToolCursor( hWindow, NULL/*idMoveObject*/, ID_PLAY_OBJECT ) );

	case WM_ACTIVATE:
	if (!lParam) // a deactivate
		{
		if (Retouch.hBrush)
			DestroySimpleBrush(Retouch.hBrush);
		Retouch.hBrush = NULL;
		}
	else
		{ // an activate ( to re-create brush)
		if ( Tool.hRibbon )
			SendMessage( Tool.hRibbon, WM_CONTROLENABLE, 1, 0L );
		}
	break;

    case WM_LBUTTONDOWN:
	Tool.bActive = NO;
	if (ImgCountSelObjects(lpImage, NULL) == 1)
		lpObject = ImgGetSelObject(lpImage, NULL);
	else
		{
		fx = x;
		fy = y;
		Display2File( &fx, &fy );
		lpObject = ImgFindSelObject(lpImage, fx, fy, NO);
		}
	if (!lpObject)
		break;
	if (!ImgEditInit(lpImage, ET_OBJECT, UT_DATA, lpObject))
		break;

	if (!SimpleBrushBegin(hWindow, &lpObject->Pixmap,
		lpObject->rObject.left, lpObject->rObject.top, Retouch.hBrush))
	    break;
	ImgEditedObject(lpImage, lpObject, IDS_UNDOCHANGE, NULL);
	Tool.bActive = SimpleBrushActive();

	/* fall through to WM_MOUSEMOVE */

    case WM_MOUSEMOVE:	// sent when ToolActive is on
	fx = x;
	fy = y;
	Display2File( &fx, &fy );
	SimpleBrushStroke(fx, fy, x, y);
	break;

    case WM_LBUTTONUP:
	SimpleBrushEnd(NO);
	Tool.bActive = NO;
	break;

    case WM_LBUTTONDBLCLK:
	break;

    case WM_DESTROY:	// The cancel operation message
	SimpleBrushEnd(NO);
	Tool.bActive = NO;
	break;
    }

return(TRUE);
}