Beispiel #1
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 );
}
Beispiel #2
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);
}