예제 #1
0
BOOL OutputDIB::TidyUp()
{
	BOOL Result = TRUE;

	if(OutputFile != NULL)
	{
		// Check that what we wrote was what was required in terms of number of lines
		// used to use BitmapInfo.biHeight but this may now be the height of a strip
#ifdef _BATCHING         
		if ( HeightWritten != HeightWanted )
		{
			TRACEUSER( "Martin", _T("OutputDIB::TidyUp HeightReqd = %d  HeightWritten = %d\n"),
				HeightWanted,HeightWritten);
		}
#else	//cos this goes off
		ERROR3IF( HeightWritten != HeightWanted, "Wrote wrong amount of bitmap to disk");
#endif

		// could do fixups into the header here etc when using compression
		Result = !OutputFile->bad();

		OutputFile = NULL;								// stop usage until StartFile time

		// If 8, 4, 1bpp export then put back the recommended palette by destructing the
		// convert function.
		if (DoExportConvert)
		{
			delete DoExportConvert;
			DoExportConvert = NULL;
		}	
	}

	// Free up the bitmap info if present.
	// This contains the info header and palette
	if (lpBitmap)
	{
		CCFree(lpBitmap);
		lpBitmap = NULL;
	}

	// Free up the output palette buffer if present
	if (OutputPalette)
	{
		CCFree(OutputPalette);
		OutputPalette = NULL;
	}

	// Free up the export buffer if present
	if (ExportBuffer)
	{
		CCFree(ExportBuffer);
		ExportBuffer = NULL;
	}

	return Result;
}
예제 #2
0
파일: blndhelp.cpp 프로젝트: vata/xarino
void BlendHelpers::DeallocTempBuffers()
{
	if (m_pTempCoords != NULL) { CCFree(m_pTempCoords); m_pTempCoords = NULL; }
	if (m_pTempVerbs  != NULL) { CCFree(m_pTempVerbs);  m_pTempVerbs  = NULL; }
	if (m_pTempFlags  != NULL) { CCFree(m_pTempFlags);  m_pTempFlags  = NULL; }
	m_TempArraySize = 0;

	if (m_pGBlendBuff != NULL) { CCFree(m_pGBlendBuff); m_pGBlendBuff = NULL; }
	m_GBlendBuffSize = 0;
}
예제 #3
0
void FreeHandEPSFilter::CleanUpAfterImport(BOOL Successful)
{
	// ensure that there's no old fill hanging around
	if(OldFill != 0)
		delete OldFill;

	OldFill = 0;

	// add new colours if successful, destroy them if not
	if(Successful)
	{
		pNewColours->AddColoursToDocument();
	}
	else
	{
		pNewColours->DestroyColours();
	}

	// delete the colour reference array
	if(ColourArray != 0)
	{
		CCFree(ColourArray);
		ColourArray = 0;
	}

	// get rid of any stuff in the stack
	Stack.DeleteAll ();

	EPSFilter::CleanUpAfterImport(Successful);
}
예제 #4
0
BOOL GuidesPropertiesTab::DeleteClicked()
{
	INT32* pIndexList = pPropertiesDlg->GetSelectedItems(_R(IDC_GUIDETAB_GUIDELINELIST));
	INT32 Count = GuidelineList.GetCount();

	INT32 i;

	BOOL ok = (pIndexList != NULL && Count > 0);
	NodeGuideline** pGuidelineList = NULL;

	if (ok)
	{
		pGuidelineList = (NodeGuideline**)CCMalloc(sizeof(NodeGuideline*)*(Count+1));

		ok = (pGuidelineList != NULL);

		if (ok)
		{
			for (i=0; (pIndexList[i] >= 0) && (i < Count);i++)
			{
				GuidelineListItem* pItem = (GuidelineListItem*)GuidelineList.FindItem(pIndexList[i]);
				if (pItem != NULL)
					pGuidelineList[i] = pItem->pGuideline;
				else
				{
					pGuidelineList[i] = NULL;
					ERROR3_PF(("List item at index [%d] is NULL",i));
				}
			}

			pGuidelineList[i] = NULL;
		}
	}
	else
		ok = FALSE;

	if (ok)
	{
		OpDescriptor* pOpDesc = OpDescriptor::FindOpDescriptor(OPTOKEN_GUIDELINE);
		ERROR3IF(pOpDesc == NULL,"FindOpDescriptor(OPTOKEN_GUIDELINE) failed");

		if (pOpDesc != NULL)
		{
			OpGuidelineParam GuidelineParam;

			GuidelineParam.Method 			= GUIDELINEOPMETHOD_DELETE;
			GuidelineParam.pGuidelineList 	= pGuidelineList;

			pOpDesc->Invoke(&GuidelineParam);
		}
	}

	if (pGuidelineList != NULL)
		CCFree(pGuidelineList);

	if (pIndexList != NULL)
		delete [] pIndexList;

	return ok;
}
예제 #5
0
/********************************************************************************************

>	BOOL PNGFilter::EndWriteToFile( )

	Author:		Neville_Humphrys (Xara Group Ltd) <*****@*****.**>
	Created:	14/5/96
	Inputs:		-
	Purpose:	Cleans up after writing the bitmap data out to a file. Inherited classes
				override this to write in different file formats.
				This is slightly different to most other bitmap filters in that it is here
				that the data actually gets written out to file, after doing the transparency
				translation, if required.
	Returns:	TRUE if worked, FALSE if failed.

********************************************************************************************/
BOOL PNGFilter::EndWriteToFile()
{
	if (GeneratingOptimisedPalette())
		return TRUE;		// No need to output anything

	//  Can reset the band number now.
	m_BandNumber = 0;

	PNGExportOptions* pPNGOptions = (PNGExportOptions*)GetBitmapExportOptions();
	ERROR2IF(pPNGOptions == NULL, FALSE, "NULL Args");
	ERROR3IF(!pPNGOptions->IS_KIND_OF(PNGExportOptions), "pPNGOptions isn't");

	// Do the transparency translation just before we write out the data as a PNG.
	// This involves doing a 1 bpp export of the same area and using this to work
	// out which areas are transparent or not.
	// Only do this if the user has requested transparency and we outputting at 8bpp
	BOOL ok = TRUE;
	BOOL SaveDataOut = TRUE;

	if (BadExportRender)
	{
		// Delete our whitearea bitmap
		if (pTempBitmapMask != NULL)
			CCFree(pTempBitmapMask);

		pTempBitmapMask = NULL;
	}

	// Save the data out if required. Only if we exported ok.
	if (SaveDataOut && !BadExportRender)
	{
		if (ok)
		{
			// Now that we know the transparent index we can output the PNG header
			ok = DestPNG.OutputPNGHeader(OutputFile, NULL, pPNGOptions->WantInterlaced(),
										pPNGOptions->GetTransparencyIndex(),
										pPNGOptions->GetDepth() <= 8 ? pPNGOptions->GetLogicalPalette() : NULL);
		}

		// Actually write the destination bitmap out to the file showing an hourglass
		// and/or progress bar as we go. Always show the Exporting message.
		// Need to do in one go due to interlacing
		if (ok)
		{
			String_64 ProgressString(ExportingMsgID);
			ProgressString = GetExportProgressString(OutputFile, ExportingMsgID);
			BeginSlowJob(100, FALSE, &ProgressString);
			
			DestPNG.OutputPNGBits(OutputFile, DestPNG.GetDestBitmapBits());
			
			EndSlowJob();
		}
	}

	ASSERT(ok);
	
	return DestPNG.TidyUp();
}
예제 #6
0
RIFFFile::~RIFFFile(void)
{
	// get rid of all the list entries in the file
	Levels.DeleteAll();

	// Get rid of the aquired object, if there is one
	if(AquiredData != 0)
		CCFree(AquiredData);
}
예제 #7
0
TrapsList::~TrapsList()
{
	if (pTraps != NULL)
	{
		for (UINT32 Index = 0; Index < Used; Index++)
			delete pTraps[Index];

		CCFree(pTraps);
	}
}
예제 #8
0
void TunedMemory::LimitedCCFree(LPVOID buf)
{
	// Find out how big the block was
	size_t BlockSize = CCGetBlockSize(buf); 

	// add it back into the pool
	if (!IsInfinite)
		AvailableRAM += BlockSize;

	// Free the memory
	CCFree(buf);
}
예제 #9
0
파일: blndhelp.cpp 프로젝트: vata/xarino
UINT32* BlendHelpers::GetGBlendBuff(UINT32 MinSize)
{
	MinSize++;
	if (m_GBlendBuffSize >= MinSize) return m_pGBlendBuff;

	if (m_pGBlendBuff != NULL) CCFree(m_pGBlendBuff);

	m_pGBlendBuff = (UINT32*) CCMalloc(MinSize*sizeof(UINT32));

	if (m_pGBlendBuff != NULL)
		m_GBlendBuffSize = MinSize;
	else
		m_GBlendBuffSize = 0;

	return m_pGBlendBuff;
}
예제 #10
0
파일: thumb.cpp 프로젝트: vata/xarino
SGThumbs::~SGThumbs()
{
	DeleteThumbnails();

	if(Thumbnails != NULL)
	{
		CCFree(Thumbnails);
		Thumbnails = NULL;
	}

	if(Directory != NULL)
	{
		delete Directory;
		Directory = NULL;
	}
}
예제 #11
0
void VectorFileRenderRegion::DeInitAttributes()
{
	// Release the 'Last Ouput' array
	if ( LastOutputAttrs != NULL )
	{
		for ( INT32 i = 0; i < NumCurrentAttrs; i++ )
		{
			if ( LastOutputAttrs[i].Temp )
			{
				delete LastOutputAttrs[i].pAttr;
			}
		}

		// We've finished with this array of attributes now
		CCFree( LastOutputAttrs );
		LastOutputAttrs = NULL;
	}
}
예제 #12
0
BOOL RIFFFile::EnsureAquiredSizeIsAtLeast(INT32 Size)
{
	if(AquiredData == 0 || AquiredDataSize < Size)
	{
		if(AquiredData != 0) 
		{
			CCFree(AquiredData);
			AquiredData = 0;
		}

		if((AquiredData = (BYTE *)CCMalloc(Size)) == 0)
			RIFFFILE_RETURNERR;

		AquiredDataSize = Size;
	}

	return TRUE;
}
예제 #13
0
RenderStack::~RenderStack()
{
	// Delete all temporary items left in the stack
	for (UINT32 i = 0; i < Top; i++)
	{
		if (TheStack[i].Temporary)
		{
			// Make sure pointer is sane before we delete it.
			CC_ASSERT_VALID(TheStack[i].pAttrValue);
			delete TheStack[i].pAttrValue;
		}
	}

	// Clean up and free stack objects.
	ContextLevel = 0;
	StackLimit = 0;
	Top = 0;
	CCFree(TheStack);
	TheStack = NULL;
}
예제 #14
0
파일: memblk.cpp 프로젝트: vata/xarino
void MemoryBlock::DeInit()
{
#if USE_STD_ALLOC
	if( NULL != m_pMemBlk )
	{
		CCFree(  m_pMemBlk );
		m_pMemBlk = NULL;
	}
#elif USE_VM_BLOCKS
	if (MemBase)
	{
		BOOL Result = VirtualFree(MemBase, 0L, MEM_RELEASE);
		MemBase = NULL;
		ENSURE( Result, "VirtualFree failed");
	}
#else
	if (MemHandle)
	{
		GlobalUnlock( MemHandle );
		GlobalFree( MemHandle );
		MemHandle = 0;
	}
#endif
}
예제 #15
0
BOOL GIFUtil::ReadFromFile( CCLexFile *File, LPBITMAPINFO *Info, LPBYTE *Bits,
							int *TransColour, int& nBitmapToRead, String_64 *ProgressString,
							BaseCamelotFilter *pFilter, UINT32* Delay, GIFDisposalMethod *Restore,
							UINT32 * pLeftOffset, UINT32 * pTopOffset,
							BOOL * pLocalPalette)
{
	if ((nBitmapToRead > 1 && nBitmapToRead == m_nCurrentBitmap) || nBitmapToRead < 1)
	{
		ERROR3("GIFUtil::ReadFromFile() - can't read that bitmap");
		return FALSE;
	}

	*Info			= NULL;		// in case of early exit
	*Bits			= NULL;
	Transparent 	= -1;
	*TransColour 	= -1;		// in case of early exit set to none
	int Background 	= 0;		// background colour number !!! not used !!!
	Interlace 		= FALSE;	// set interlace to false by default

	// Must set the exception throwing flag to True and force reporting of errors to False.
	// This means that the caller must report an error if the function returns False.
	// Any calls to CCLexFile::GotError will now throw a file exception and should fall into
	// the catch handler at the end of the function.
	BOOL OldThrowingState = File->SetThrowExceptions( TRUE );
	BOOL OldReportingState = File->SetReportErrors( FALSE );

	// If the caller has specified a string then assume they require a progress bar
	// Start it up.
	if (ProgressString != NULL)
		BeginSlowJob(100, FALSE, ProgressString);

	try
	{
		// If we want the first bitmap we'll assume we're at the start of the file & read the header
		if (nBitmapToRead == 1)
		{
			// place to store the global palette, if present, for later use
			lpGlobalPalette 		= NULL;	// pointer to temporary palette store
			GlobalPaletteSize 			= 0;	// size of the global palette found	 

			GIFINFOHEADER Header;
			// This is really sizeof(GIFINFOHEADER) but this returns 14 instead of 13
			// as it rounds to the nearest word boundary
			const size_t HeaderSize = sizeof(char)* 6 + sizeof(WORD) * 2 + sizeof(BYTE) * 3;

			File->read( &Header, HeaderSize );
			if (File->bad())
				File->GotError( _R(IDE_FORMATNOTSUPPORTED) );

			// Just double check that the signature is correct, if not then fail immediately
			if (
				(strncmp(Header.giName, "GIF89a", 6) != 0) &&
	 			(strncmp(Header.giName, "GIF87a", 6) != 0)
			)
				File->GotError( _R(IDE_BADFORMAT) );

			// Note the overall size of the GIF from the header, may be the animation size
			m_GlobalWidth		= Header.giWidth;
			m_GlobalHeight  	= Header.giHeight;
			// flags word consists of:-
			// - bit 7 colour table flag				= set if global colour table follows
			// - bits 6-4 colour resolution				= bpps - 1
			// - bit 3 sort flag						= set global colour table sorted
			// - bits 3-0 size of global colour table 	= size is 2^(value+1)
			int ColorResolution = (((Header.giFlags >> 4) & 0x07) + 1);
			GlobalPaletteSize	= 2 << (Header.giFlags & 0x07);
			Background			= Header.giBackground;
//			int AspectRatio		= Header.giAspect;

TRACEUSER("Neville",_T("Gif Global Width = %d Height = %d\n"), m_GlobalWidth, m_GlobalHeight);
TRACEUSER("Neville",_T("Gif ColorResolution = %d\n"), ColorResolution);

			// Check if we have a global colour map present or not, if so then read it in.
			if (BitSet(Header.giFlags, GLOBALCOLOURMAP))
			{
TRACEUSER("Neville",_T("Gif read global colour table size = %d\n"), GlobalPaletteSize);
			    // Read in the global colour map into a palette structure for possible later use
				const size_t TotalPal = sizeof(RGBQUAD) * GlobalPaletteSize;
				lpGlobalPalette = (LPRGBQUAD)CCMalloc( TotalPal );
				if (lpGlobalPalette==NULL)
					return FALSE;

				ReadColourMap(File, GlobalPaletteSize, lpGlobalPalette);
			}
			m_nCurrentBitmap = 0;
			m_NextImageStartPosition = 0;
		}

		// We now need to go through and process the data in this file which
		// should now consist off GIF blocks until we hit the end of file or
		// we have processed the lot.
		BOOL FileProcessed = FALSE;

		m_bImageRead = FALSE;
		unsigned char c;
		// Set up bad values so that the DIB alloc claim will fail if there
		// has been no GIFIMAGEBLOCK found
//		int	Width 		  	= 0;	// Width of bitmap	
//		int Height 		  	= 0;	// Height of bitmap	
//		int BitsPerPixel	= 0;	//ColorResolution;	// Colour depth required

		if (m_NextImageStartPosition != 0)
		{
			File->seekIn(m_NextImageStartPosition, ios::beg);
			m_NextImageStartPosition = 0;
		}

		while (!File->eof() && !File->bad() && !FileProcessed)
		{
			// Get the next character in the stream and see what it indicates
			// comes next in the file
			// Use Get as this will read the EOF character (255) and exit via the
			// File->eof() test rather than Read which will throw an exception. 
			//File->read( &c, 1 );
			File->get( (char&)c );
			
			switch (c)
			{
				case ';':
				{
					// GIF terminator
					// Cannot assume that the terminator immediately follows the image data
					// Might have some extensions following the image data. 					 
					FileProcessed = TRUE;
					nBitmapToRead = -1;
					break;
				}

				case '!': //EXTENSIONBLOCK:
				{
					// Extension
					ProcessExtension(File);
					break;
				}
				
				case ',':
				{
					// start of image character
					if (m_bImageRead)	// another bitmap - save it for the next call to ReadFromFile()
					{
						if (m_NextImageStartPosition == 0)
						{
							// No transparency info for the next one so start here
							m_NextImageStartPosition = File->tellIn() - 1;
						}
						++nBitmapToRead;
						FileProcessed = TRUE;
						break;
					}

					UINT32 LeftOffset = 0;
					UINT32 TopOffset = 0;
					BOOL LocalPalette = FALSE;

					// Should be followed by a GIFIMAGE BLOCK
					ProcessImageBlock(File, Info, Bits, &LeftOffset, &TopOffset, &LocalPalette);
					++m_nCurrentBitmap;

					if (nBitmapToRead == m_nCurrentBitmap)
					{
						m_bImageRead = TRUE;
					}

					// return the values back to the caller if it desired them
					if (pLeftOffset)
						*pLeftOffset = LeftOffset;
					if (pTopOffset)
						*pTopOffset = TopOffset;
					if (pLocalPalette)
						*pLocalPalette = LocalPalette;
					break;
				}

				default:
					// We have found something other than what we are expecting
					// so fail with an error
					//File->GotError( IDE_BADFORMAT );
					// Cannot do this as some files have random bits
					// e.g. galileo.gif has a random zero before the ;
					//     	colsec.gif has a rampant > at the end instead of ;
					if (m_bImageRead)
					{
						// We've already got something so ignore anything else in case it goes
						// completely wrong.
						FileProcessed = TRUE;
						nBitmapToRead = -1;
					}
					TRACE( _T("Unrecognized Character %x at %d\n"), (int)c, File->tellIn());

					break;
			}
		}

		// If we reach here and the bitmap allocations are still null then no valid image
		// was found and so we should error now.
		// Might have just been a GIF file with extension tags in and no images!
		if (*Info == NULL || *Bits == NULL)
			File->GotError( _R(IDE_BADFORMAT) );

		// We read the desired bitmap but the EOF came along before we could try anything else
		// Signal this is the last bitmap
		if (m_bImageRead && File->eof())
		{
			TRACE( _T("GIF: Premature end of file") );
			nBitmapToRead = -1;
		}

		// Return the transparency/delay/restore found to the caller.
		*TransColour = Transparent;
		if (Delay)
		{
			*Delay = m_Delay;
		}
		if (Restore)
		{
			*Restore = m_Restore;
		}

		// Free up the bit of memory for a palette we grabbed, if present & no more images to read
		if (lpGlobalPalette && nBitmapToRead == -1)
		{
			CCFree(lpGlobalPalette);
			lpGlobalPalette = NULL;
		}

		// If started, then stop then progress bar
		if (ProgressString != NULL)
			EndSlowJob();

		// Must set the exception throwing and reporting flags back to their entry states
		File->SetThrowExceptions( OldThrowingState );
		File->SetReportErrors( OldReportingState );

		// er, we seem to have finished OK so say so
		return TRUE;
	}
예제 #16
0
ProcessPath::~ProcessPath()
{
	if (ProcCache)
		CCFree(ProcCache);
}
예제 #17
0
파일: pngfuncs.cpp 프로젝트: vata/xarino
void camelot_png_free(png_structp png_ptr, png_voidp data)
{
	CCFree(data);
}
예제 #18
0
BOOL OutputPNG::StartFile( LPBITMAPINFOHEADER lpHeader, LPLOGPALETTE Palette,
                           UINT32 OutputDepth, DWORD CompressionType,
                           UINT32 FinalHeight, INT32 ExportSize, UINT32 DitherType )
{
    TRACEUSER( "Jonathan", _T("PNG write: Start\n"));
    ERROR2IF( lpHeader==NULL , FALSE, "OutputPNG::StartFile NULL lpHeader");

    // Set up memory pointers to NULL
    if (DestBitmapInfo && DestBitmapBytes)
    {
        FreeDIB( DestBitmapInfo, DestBitmapBytes );
        DestBitmapInfo = NULL;
        DestBitmapBytes = NULL;
    }
//	DestBitmapInfo = NULL;
//	DestBitmapBytes = NULL;
    if (OutputPalette)
    {
        CCFree(OutputPalette);
        OutputPalette = NULL;
    }
//	OutputPalette = NULL;
    IsFirstStrip = TRUE;
    HeightWritten = 0;

    // remember input args
    BitmapInfo = *lpHeader;								// take a copy of user's header
    CurrentExportSize = ExportSize;						// size set up for the progress bar
    HeightWanted = FinalHeight;							// the actual height of the export required
    Dither = DitherType;

    // We will need to have the entire image present before writing out so that we can
    // cope with interlacing and transparency, so create that DIB
    // Set up the information header for the dib which we hold during export
    UINT32 LineWidth = DIBUtil::ScanlineSize( BitmapInfo.biWidth, OutputDepth );
    INT32 PalSize = 0;
    BOOL ok = SetUpInfoHeader(lpHeader, OutputDepth, CompressionType, LineWidth, FinalHeight, &PalSize);

    // Claim memory for the bitmap
    if (ok)
    {
        DestBitmapInfo = AllocDIB( BitmapInfo.biWidth, FinalHeight, OutputDepth, &DestBitmapBytes );
        ok = (DestBitmapInfo != NULL) && (DestBitmapBytes != NULL);
    }

    // Transfer across the required other bits of info
    if (ok)
    {
        DestBitmapInfo->bmiHeader.biXPelsPerMeter = BitmapInfo.biXPelsPerMeter;
        DestBitmapInfo->bmiHeader.biYPelsPerMeter = BitmapInfo.biYPelsPerMeter;
        DestBitmapInfo->bmiHeader.biClrUsed = PalSize;
    }

    // Point the place to put the next strip of data at the start ready for the first strip
    pNextStrip = DestBitmapBytes;

    // Take a copy of the palette
    if (ok && PalSize && Palette)
    {
        const size_t TotalPal = sizeof(LOGPALETTE) + ( sizeof(PALETTEENTRY) * PalSize );
        OutputPalette = (LPLOGPALETTE)CCMalloc( TotalPal );
        if (OutputPalette != NULL)
            memcpy( OutputPalette, Palette, TotalPal );
        else
            ok = FALSE;
    }

    // Clean up if an error happened
    if (!ok)
    {
        // Free up the DIB that we have just created
        FreeDIB( DestBitmapInfo, DestBitmapBytes );
        DestBitmapInfo = NULL;
        DestBitmapBytes = NULL;
        if (OutputPalette != NULL)
        {
            CCFree(OutputPalette);
            OutputPalette = NULL;
        }
    }

    return ok;
}
예제 #19
0
BOOL OutputPNG::WriteBlock( UINT32 YPos, UINT32 Height, LPBYTE BlockStart, UINT32 InputBPP,
                            INT32 ProgressOffset)
{
    ERROR2IF(DestBitmapInfo == NULL, FALSE,"OutputPNG::WriteBlock destination bitmap info null");
    ERROR2IF(DestBitmapBytes == NULL, FALSE,"OutputPNG::WriteBlock destination bitmap bits null");
    ERROR2IF(pNextStrip == NULL, FALSE,"OutputPNG::WriteBlock next strip pointer is null");

    FNPTR_SCANLINE ConvertFn = NULL;
    LPBYTE Buffer = NULL;
    size_t BufSize = 0L;
    size_t ChunkHeight = 1;
    DIBConvert *DoConvert = NULL;

    // Set up the size and other information for the dib block that we require. This is
    // dependent on the export depth or bpp required.
    if ( !SetUpBlock( &BufSize, &ChunkHeight, &DoConvert, &ConvertFn ) )
        return FALSE;			// Error details already set up

    if (BufSize)
    {
        Buffer = (LPBYTE)CCMalloc( BufSize );
        if (Buffer==NULL)
            return FALSE;
    }

    if ( DoConvert )
    {
        // use new classes to do it
        // 8bpp, 4bpp and 1bpp conversion
        INT32 h = Height;
        INT32 count = 0;
        LPBYTE Data = BlockStart;
        const size_t SourceWidth = DIBUtil::ScanlineSize( BitmapInfo.biWidth, InputBPP ) * ChunkHeight;
        const size_t DestWidth   = DIBUtil::ScanlineSize( BitmapInfo.biWidth, BitmapInfo.biBitCount );

        while (h)
        {
            ENSURE(h >= 0, "bad looping");

            const size_t ThisBit = min( h, (INT32)ChunkHeight );
            if (!DoConvert->Convert( Data, Buffer, ThisBit, IsFirstStrip ))
                break;								// stop if conversion failed

            IsFirstStrip = FALSE;

            // Copy this block to our destination bitmap
            // pNextStrip should be pointing at the next place to copy the data to
            memcpy(pNextStrip, Buffer, ThisBit * DestWidth);

            Data += SourceWidth;
            h -= ThisBit;
            pNextStrip += ThisBit * DestWidth;

            // now update the progress display, started with CurrentExportSize
            // CurrentExport size is now the point to go from in the export
            count++;
            ContinueSlowJob( (INT32)(ProgressOffset + count) );
            //ContinueSlowJob( (INT32)(100*count/(Height)) );
        }
    }
    else if ( ConvertFn && Buffer )
    {
        // Write via conversion function
        // 24 bpp convert
        UINT32 h = Height;
        INT32 count = 0;
        LPBYTE Data = BlockStart;
        const size_t SourceWidth = DIBUtil::ScanlineSize( BitmapInfo.biWidth, InputBPP );

        while (h)
        {
            ConvertFn( BitmapInfo.biWidth, Data, Buffer );

            // Copy this block to our destination bitmap
            // pNextStrip should be pointing at the next place to copy the data to
            memcpy(pNextStrip, Buffer, BufSize);

            Data += SourceWidth;
            h -= ChunkHeight;
            pNextStrip += BufSize;

            // now update the progress display, started with CurrentExportSize
            // ProgressOffset size is now the point to go from in the export
            count++;
            ContinueSlowJob( (INT32)( ProgressOffset + count ));
            //ContinueSlowJob( (INT32)((CurrentExportSize * count)/Height) );
        }
    }
    else
    {
        // Write the actual bytes out to file. Used to do it in one go but we really
        // require some progress bar indication so we will do it in chunks.
        DWORD BitsSize = BitmapInfo.biSizeImage;
        if (BitsSize > 0)
        {
            if (BitsSize < 1024)
            {
                // File very small or no progress bar required, so load in one go
                // Copy this block to our destination bitmap
                // pNextStrip should be pointing at the next place to copy the data to
                memcpy(pNextStrip, BlockStart, BitsSize);
                pNextStrip += BitsSize;
            }
            else
            {
                // Load in chunks, for present split into 100 chunks
                DWORD ChunkSize = BitsSize/100;
                DWORD Position = 0;
                LPBYTE pBitInfo = BlockStart;

                while (Position < BitsSize)
                {
                    if ( (BitsSize - Position) > ChunkSize)
                    {
                        // Copy this block to our destination bitmap
                        // pNextStrip should be pointing at the next place to copy the data to
                        memcpy(pNextStrip, pBitInfo, ChunkSize);
                    }
                    else
                    {
                        ChunkSize = BitsSize - Position;
                        // Copy this block to our destination bitmap
                        // pNextStrip should be pointing at the next place to copy the data to
                        memcpy(pNextStrip, pBitInfo, ChunkSize);
                    }

                    // Increment our counters/pointers
                    Position+=ChunkSize;
                    pBitInfo+=ChunkSize;
                    pNextStrip += ChunkSize;
                    // Progress bar started with height of bitmap
                    ContinueSlowJob( (INT32)(ProgressOffset + (Height * Position)/BitsSize) );
                    //ContinueSlowJob( (INT32)((CurrentExportSize * Position)/BitsSize) );
                }
            }
        }
    }

    // If present, get rid of our export function
    if (DoConvert)
    {
        delete DoConvert;
        DoConvert = NULL;
    }

    CCFree( Buffer );

    HeightWritten += Height;						// remember we wrote this lot

    return TRUE;
}
예제 #20
0
TrapEdgeList::~TrapEdgeList()
{
	if (pEdges != NULL)
		CCFree(pEdges);
}
예제 #21
0
void OpAlign::DoWithParam(OpDescriptor* pOp, OpParam* pAlignParam)
{
	// DMc alterations so that this works with compound nodes	
	SelRange   Selection(*(GetApplication()->FindSelection()));

	RangeControl rg = Selection.GetRangeControlFlags();
	rg.PromoteToParent = TRUE;
	Selection.Range::SetRangeControl(rg);

	DocRect		SelRect   = Selection.GetBoundingRect();
	DocRect		TargetRect;
	TargetRect.MakeEmpty();
	INT32        NumObjs   = Selection.Count();
	AlignParam* pAlign    =(AlignParam*)pAlignParam;

	BOOL moved=FALSE;					// set to TRUE if any object is moved
	BeginSlowJob(-1,FALSE);
	BOOL OK=DoStartTransOp(FALSE);

	// find parent spread of first object in selection
	Node*   pFirstNode=NULL;
	Spread* pSpread   =NULL;
	if (OK)
	{
		pFirstNode=Selection.FindFirst();
		if (pFirstNode!=NULL)
			pSpread=pFirstNode->FindParentSpread();
		OK=(pSpread!=NULL);
		if (!OK)
			ERROR2RAW("OpAlign::DoWithParam() - could not find parent spread");
	}

	// Find the size of the target rectangle
	if (pAlign->target==ToSelection)
		TargetRect=SelRect;
	else
	{
		Page* pPage=pSpread->FindFirstPageInSpread();
		while (pPage)
		{
			DocRect PageRect=pPage->GetPageRect();
			if (pAlign->target==ToSpread || SelRect.IsIntersectedWith(PageRect))
				TargetRect=TargetRect.Union(PageRect);
			pPage=pPage->FindNextPage();
		}
	}

	// allocate all dynamic memory required
	Node**	 pObj=NULL;
	ObjInfo* x   =NULL;
	ObjInfo* y   =NULL;
	INT32*    dx  =NULL;
	INT32*    dy  =NULL;
	if (OK)			ALLOC_WITH_FAIL(pObj,(Node**)  CCMalloc(NumObjs*sizeof(Node*)),  this);
	if (pObj!=NULL)	ALLOC_WITH_FAIL(x,   (ObjInfo*)CCMalloc(NumObjs*sizeof(ObjInfo)),this);
	if (   x!=NULL) ALLOC_WITH_FAIL(y,   (ObjInfo*)CCMalloc(NumObjs*sizeof(ObjInfo)),this);
	if (   y!=NULL) ALLOC_WITH_FAIL(dx,  (INT32*)   CCMalloc(NumObjs*sizeof(INT32)),   this);
	if (  dx!=NULL) ALLOC_WITH_FAIL(dy,  (INT32*)   CCMalloc(NumObjs*sizeof(INT32)),   this);
	OK=(dy!=NULL);

	// if memory claimed OK and target rect not empty proceed with op
	// (ie. do nothing if 'within page(s)' when no object on a page)
	DocRect EmptyRect;
	if (OK && TargetRect!=EmptyRect)
	{
		// create an array of pointers to objects (nodes) to be affected
		Node* pNode=Selection.FindFirst();
		INT32  i=0;
		while (pNode!=NULL)
		{
			if (pNode->IsBounded() && !((NodeRenderableBounded*)pNode)->GetBoundingRect(TRUE).IsEmpty())
				pObj[i++]=pNode;
			pNode=Selection.FindNext(pNode);
		}
		NumObjs=i;

		// cache x & y info in separate arrays so they can be sorted separately
		XLONG SumObjWidths =0;
		XLONG SumObjHeights=0;
		for (i=0; i<NumObjs; i++)
		{
			DocRect ObjRect=((NodeRenderableBounded*)pObj[i])->GetBoundingRect();
			x[i].i=i;
			x[i].lo=ObjRect.lo.x;
			x[i].hi=ObjRect.hi.x;
			SumObjWidths+=ObjRect.hi.x-ObjRect.lo.x;
			y[i].i=i;
			y[i].lo=ObjRect.lo.y;
			y[i].hi=ObjRect.hi.y;
			SumObjHeights+=ObjRect.hi.y-ObjRect.lo.y;
		}

		// for each object, calculate the x and y displacements independently
		AlignOneAxis(pAlign->h,NumObjs,SumObjWidths, TargetRect.lo.x,TargetRect.hi.x,x,dx);
		AlignOneAxis(pAlign->v,NumObjs,SumObjHeights,TargetRect.lo.y,TargetRect.hi.y,y,dy);

		// apply the x and y displacements simultaneously to each object
		for (i=0; i<NumObjs; i++)
			if (dx[i]!=0 || dy[i]!=0)
			{
				moved=TRUE;
				Trans2DMatrix* pMatrix=new Trans2DMatrix(dx[i],dy[i]);
				DoTransformNode((NodeRenderableInk*)pObj[i],pMatrix);
			}
	}

	// free up any memory which was allocated
	CCFree(dx);
	CCFree(dy);
	CCFree(x);
	CCFree(y);
	CCFree(pObj);

	if (moved)
	{
		Document::GetSelected()->ForceRedraw(pSpread, TargetRect);
		GetApplication()->UpdateSelection();
	}
	else
		FailAndExecute();
	End();
	EndSlowJob();
}
예제 #22
0
AcornDrawFilter::~AcornDrawFilter()
{
	// Clean up our input buffer
	CCFree(DataBuf);
}
예제 #23
0
파일: nativeop.cpp 프로젝트: vata/xarino
BOOL OpMenuLoad::LoadFile(CCLexFile* pFileToLoad, UINT32 nPrefFilter)
{
	// Make sure we have a valid file to load.
/*	TRACEUSER( "JustinF", _T("In OpMenuLoad::LoadFile(%p, %u)\n"),
				(LPVOID) pFileToLoad, nPrefFilter);
*/	ERROR3IF(!pFileToLoad, "Null CCLexFile* in OpMenuLoad::LoadFile");
	
	// Find out the position of the filter selected by the user in the open dialog
	INT32 SelectedPos = 0;

#if !defined(EXCLUDE_FROM_RALPH) && !defined(EXCLUDE_FROM_XARALX)
	SelectedPos = BaseFileDialog::SelectedFilter;
#endif

	// Go get the first filter in the list
	Filter* pFilter = Filter::GetFirst();

	// Do we know which filter was used? (we know nothing about things in the recent file
	// list).  If we don't, then use the preferred one, by default the generic filter.
	if (nPrefFilter != FILTERID_USERCHOICE || SelectedPos == 0)
	{
		// We know nothing. We will have to go and have a look at all the possibles
		// We will find the Filter Family and ask it to try and load the file.
		UINT32 nID = (nPrefFilter != FILTERID_USERCHOICE) ? nPrefFilter : FILTERID_GENERIC;
		while (pFilter != NULL && pFilter->FilterID != nID)
		{
			// Try the next filter
			pFilter = Filter::GetNext(pFilter);
		}
	}
	else
	{
		// We know which type of filter the user had selected in the file dialog
		// Find the filter that the user chose.
		while (pFilter != NULL)
		{
			// This is the filter?
			if (pFilter->GetFlags().CanImport &&
				pFilter->pOILFilter->Position == SelectedPos)
					break;

			// Try the next filter
			pFilter = Filter::GetNext(pFilter);
		}
	}
	
	// Check that the Filter existed
	if (pFilter == NULL)
	{
		// It did not...
		InformError(_R(IDT_CANT_FIND_FILTER));
		return FALSE;
	}

	// Get pointer to current doc 'cos we'll need it several times...
	Document* pCurDoc = Document::GetCurrent();

	// If this is not a filter family, check for compatibility before asking
	// filter to load the file.
	// This means the user has chosen an explicit filter to handle the import
	PathName Path = pFileToLoad->GetPathName();
	String_256 FilePath = Path.GetPath();
	// FilePath will be null if a pathname is not valid
	if (!pFilter->IS_KIND_OF(FilterFamily) && !FilePath.IsEmpty())
	{
		UINT32		Size = 1024;
		size_t		FileSize;
		ADDR		FilterBuf = pFilter->LoadInitialSegment(Path, &Size, &FileSize);

		// If there has been a problem in the load initial segment then fail now.
		if (FilterBuf == NULL)
		{
			// Tell the user about the problem and get out now while the goings good 
			InformError();
			return FALSE;
		}

		// Inform any filters that we are about to do a HowCompatible call.
		// This would allow a set of filters which have common functionality hidden in a
		// filter that cannot import and cannot export handle this call and hence set
		// itself up. This would allow it to maybe cache a result which should only be
		// checked by the first filter in the group. 
		pFilter->PreHowCompatible();
		
		// Change this to be less than 8 as the filters like the Accusoft forms return
		// 8 and 9 to make sure that they are last in the chain.
		if (pFilter->HowCompatible(Path, FilterBuf, Size, UINT32(FileSize)) < 8)
		{
			// Not 100% happy with this file - ask for confirmation.
			ErrorInfo Question;
			Question.ErrorMsg = _R(IDW_OPENQUERY_NOTSURE);
			Question.Button[0] = _R(IDB_OPENQUERY_OPEN);
			Question.Button[1] = _R(IDB_OPENQUERY_DONTOPEN);

			if ((ResourceID)AskQuestion(&Question) != _R(IDB_OPENQUERY_OPEN))
			{
				// User asked for this to be cancelled.
				TRACEUSER( "Tim", _T("Filter compatibility was less than 10\n"));

				// Close the file, report the abort and finish.
				CCFree(FilterBuf);
				//InformMessage(_R(IDT_IMP_USERABORT));
				return FALSE;
			}
		}

		// Get rid of initial file header
		CCFree(FilterBuf);
	}

	// we have to try and open the file
	try
	{
		// Found the Filter, so ask it to import the file please
		if (!pFilter->DoImport(this, pFileToLoad, pCurDoc))
		{
			// Something went a bit wrong - tell the user what it was.
			// Only tell them if not special user cancelled error message
			if (Error::GetErrorNumber() != _R(IDN_USER_CANCELLED))
			{
				// Only supress the error if not the special user abort error
				// ***** For now use the native EPS filter
				if (pFilter->FilterID == FILTERID_NATIVE_EPS &&
					Error::GetErrorNumber() != _R(IDT_IMPORT_USERABORT))
				{
					Error::ClearError();
					InformError(_R(IDS_ERRORINARTFILE));
				}
				else
				{
					// Tell the user what the problem was
					InformError();
					wxMessageDialog dlg(
						NULL,
						_T( "Xara LX failed to load the design.\n\n")
						_T( "This is an early demonstration version of the program which does ")
						_T( "not yet support all of the data types that can appear in XAR designs."),
						_T("Load failed"),
						wxOK
					);
					dlg.ShowModal() ;
				}
			}
			else
			{
				// otherwise remove the error so it won't get reported
				Error::ClearError();
			}

			// and fail
			return FALSE;
		}

	}
	// See if there was a file io errir
	catch( CFileException )
	{
		// Report the error if no one else did, otherwise clear it.
		if (Error::GetErrorNumber() != _R(IDN_USER_CANCELLED))
			InformError();
		else
			Error::ClearError();

		// and fail
		return FALSE;
	}

	// Success.
	return TRUE;
}
예제 #24
0
BOOL RenderStack::Copy(const RenderStack *Other, RenderRegion *pRegion)
{
	ERROR3IF(Other == NULL || pRegion == NULL, "Illegal NULL params");

// WEBSTER - markn 15/8/97
// This has bee taken out of Webster builds as it can cause fatal access violations with Paper render regions.
// It is new path processor code that not's totally bug-free, and as path processors are not used in Webster,
// it can be safely taken out.
#ifndef WEBSTER
	// Make sure all attributes are properly popped && deinitialised, so that any used
	// PathProcessors are correctly removed, etc
	// (Note: This doesn't deinit the DEFAULT attributes, which we hope will never use
	// PathProcessors - this should be OK, because the places where this is called from
	// (at present) always make sure all PathProcessors are properly cleaned up too)
	CleanUpBeforeDestruct(pRegion);
#endif // WEBSTER

	// Make sure we have an empty stack to work with
	if (TheStack!=NULL)
	{
		// Empty the current stack before copying the new one onto it
		// For every item in the stack, check to see if it is 'temporary'.  If it is,
		// we can't use it in our stack - we must take a copy.
		for (UINT32 i=0; i<Top; i++)
		{
			// Get rid of all the temp attrs in the stack
			if (TheStack[i].Temporary)
			{
				// Delete this tempory attr.
				CC_ASSERT_VALID(TheStack[i].pAttrValue);
				delete TheStack[i].pAttrValue;
			}
		}

		// then get rid of the stack itself
		CCFree(TheStack);
		TheStack=NULL;

		ContextLevel = 0;
		StackLimit = 0;
		Top = 0;
	}

	// Sanity check
	ENSURE(TheStack == NULL,"RenderStack::Copy called on a non-empty stack");

#if FALSE
	// Jason (7/3/97)
	// Copying the stack like this is rampant. We must render all the attributes across onto
	// the new stack, so that they are properly stacked and initialised
/*
	// Copy stack variables
	ContextLevel = Other->ContextLevel;
	StackLimit = Other->StackLimit;
	Top = Other->Top;

	// The other stack may be empty, which will often be the case when merging as it may
	// not have started rendering yet.
	if (Other->TheStack == NULL)
	{
		// Just to be on the safe side
		TheStack = NULL;

		// We're done.
		return TRUE;
	}

	// Allocate the same amount of memory for the stack
	TheStack = (AttributeRec *) CCMalloc(StackLimit * ITEM_SIZE);
	if (TheStack == NULL)
		return FALSE;

	// Copy the other render region's stack data into this new stack
	memcpy(TheStack, Other->TheStack, StackLimit * ITEM_SIZE);

	// For every item in the stack, check to see if it is 'temporary'.  If it is,
	// we can't use it in our stack - we must take a copy.
	for (UINT32 i = 0; i < Top; i++)
	{
		if (TheStack[i].Temporary)
		{
			// Get the runtime class info on this object
			CCRuntimeClass *pCCRuntimeClass = TheStack[i].pAttrValue->GetRuntimeClass();
	
			// Create another object of the same type
			AttributeValue *pNewAttr = (AttributeValue *) pCCRuntimeClass->CreateObject();

			if (pNewAttr == NULL)
			{
				// Failed to create object - quit with error, but first ensure that this
				// stack is limited to the items copied so far. Otherwise the destructor
				// will attempt to delete objects that belong to the other stack.
				Top = i;
				return FALSE;
			}

			// Object created ok - get the object to copy its contents across.
			pNewAttr->SimpleCopy(TheStack[i].pAttrValue);

			// Put it in the stack
			TheStack[i].pAttrValue = pNewAttr;
		}
	}
*/
#else
	if (Other->TheStack == NULL)
		return(TRUE);

	UINT32 LastContextLevel = 0;

	// Copy all attributes across to the new stack by rendering them into the provided render region.
	// If we aren't "pRegion->TheStack" then we've just lost our paddle, and we're being sucked up the creek...
	for (UINT32 i = 0; i < Other->Top; i++)
	{
		// Make sure we copy context level information across too - if the context level changed, we must
		// save the context level now.
		if (LastContextLevel != Other->TheStack[i].ContextLevel)
			pRegion->SaveContext();

		// Get each attribute to render into our render region
		AttributeValue *pAttrVal = Other->TheStack[i].pAttrValue;

		// If it's temporary, then replace it with a unique copy for this render region
		if (Other->TheStack[i].Temporary)
		{
			// Get the runtime class info on this object
			CCRuntimeClass *pCCRuntimeClass = Other->TheStack[i].pAttrValue->GetRuntimeClass();
	
			// Create another object of the same type
			pAttrVal = (AttributeValue *) pCCRuntimeClass->CreateObject();

			if (pAttrVal == NULL)
				return FALSE;

			// Object created ok - get the object to copy its contents across.
			pAttrVal->SimpleCopy(Other->TheStack[i].pAttrValue);
		}

		// and render the attribute into this render region
		pAttrVal->Render(pRegion, Other->TheStack[i].Temporary);
	}
	
#endif

	// It worked
	return TRUE;
}