Ejemplo n.º 1
0
        void TextureSerializer::DeserializePixelmap(std::istream& stream, std::vector<PixmapPtr>& pixelmaps)
        {
            if (!stream)
                throw Commons::IOException("Stream is not opened");

            PixmapPtr curPixmap;

            BigEndianStreamReader reader(stream);

            FileHeaderChunk fileHeader;
            ChunkHeader header;
            while (!reader.isEOF())
            {
                header.read(reader);                

                uint32_t lastOffset = reader.tell();

                if (header.getMagic() == FileHeaderChunk::MAGIC)
                {
                    fileHeader.read(reader);
                }
                else if (header.getMagic() == TextureHeadChunk::MAGIC)
                {
                    curPixmap = PixmapPtr(new Pixmap());
                    assert(curPixmap.get());
                    curPixmap->m_header.read(reader);
                }
                else if (header.getMagic() == TextureDataChunk::MAGIC)
                {
                    assert(curPixmap.get());
                    curPixmap->m_data.read(reader);
                }
                else if (header.isNULL())
                {
                    if (!curPixmap.get() || !curPixmap->isValid())
                        throw Commons::SerializationException("Pixelmap object is incorrect");
                    pixelmaps.push_back(curPixmap);
                    curPixmap.reset();
                }
                else
                {
                    std::stringstream ss;
                    ss << "Unknown chunk: " << header.getMagic() << " at " << reader.tell();
                    throw Commons::SerializationException(ss.str());
                }

                uint32_t redSize = reader.tell() - lastOffset;
                if (redSize != header.getSize())
                {
                    std::stringstream ss;
                    ss << "Incorrect chunk size red: required: " << header.getSize() << " current " << redSize;
                    throw Commons::SerializationException(ss.str());
                }
            }
        }
Ejemplo n.º 2
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();
}
Ejemplo n.º 3
0
LOCAL void PaletteMapPixmap(LPPIXMAP lpPixmap, CFrameTypeConvert *pTypeConvert)
/***********************************************************************/
{
int y, w, h;
LPTR lp;

ProgressBegin(1, 0);
w = FrameXSize(lpPixmap->EditFrame);
h = FrameYSize(lpPixmap->EditFrame);
for (y = 0; y < h; ++y)
	{
	AstralClockCursor(y, h, NO);
	lp = PixmapPtr(lpPixmap, PMT_EDIT, 0, y, YES);
	if (!lp)
		break;
	pTypeConvert->ConvertData(lp, lp, y, w);
	}
ProgressEnd();
}
Ejemplo 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 );
}
Ejemplo n.º 5
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);
}