void CServerView::init_paste( LPOBJECT lpObject, CPoint *pt) { RECT rImage, rObjects; CServerDoc* pDoc = GetDocument(); ASSERT(pDoc); LPIMAGE lpImage = pDoc->m_lpImage; ASSERT(lpImage); int xData = RectWidth(&lpObject->rObject); int yData = RectHeight(&lpObject->rObject); // get location rect to center to object on rImage = m_lpDisplay->FileRect; int x, y; // center the object around point if (pt) { x = pt->x; y = pt->y; Display2File(GetSafeHwnd(), (LPINT)&x, (LPINT)&y); x = x - (xData/2); y = y - (yData/2); } // center the object in the location rectangle else { x = ( rImage.left + rImage.right - xData ) / 2; y = ( rImage.top + rImage.bottom - yData ) / 2; } if (x < rImage.left) x = rImage.left; if (y < rImage.top) y = rImage.top; OffsetRect(&lpObject->rObject, x, y); RemoveObjectMarquee(lpImage); // make this object temporary, so it will go away if // the paste is cancelled lpObject->StorageType = ST_TEMPORARY; // save the selection state in case of cancel SaveSelectedObjects(lpImage); ImgAddNewObject(lpImage, lpObject); ImgGetSelObjectRect(lpImage, &rObjects, YES); UpdateImage(lpImage, &rObjects, YES); }
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 ); }