Exemple #1
0
/********************************************************************************************

>	virtual void PNGFilter::CleanUpAfterExport()

	Author:		Neville_Humphrys (Xara Group Ltd) <*****@*****.**>
	Created:	14/5/96
	Purpose:	Cleans up the memory allocated at the end of Exporting or when exporting has
				been aborted for some reason. Does its cleaning up and then calls the
				baseclass version to do its stuff,  - used
				when the import process ends, either normally or abnormally. Override if
				extra things are required.
	SeeAlso:	BaseBitmapFilter::PrepareToExport(); BaseBitmapFilter::CleanUpAfterExport();
	Scope: 		Protected

********************************************************************************************/
void PNGFilter::CleanUpAfterExport()
{
	// Called right at the end of the export process or when the epxort has been aborted
	// Clean up any objects unique to this class.
	// Free up any DIBs that we might have left lying around on the export
	if (pDestBMInfo && pDestBMBytes)
	{
		FreeDIB( pDestBMInfo, pDestBMBytes );
		pDestBMInfo = NULL;
		pDestBMBytes = NULL;	
	}

	// the depth we ask GDraw to render is always 32-bit, so we can get transparency
	// we have to convert for other formats	when writing the actual bytes to the file
	SetDepthToRender(32);

	// We haven't written the header yet
	WrittenHeader = FALSE;

	// We are a first pass render and not doing the mask, by default
	SecondPass = FALSE;
	DoingMask = FALSE;

	// Now call the baseclass version to do its stuff
	BaseBitmapFilter::CleanUpAfterExport();
}
Exemple #2
0
void GRenderWinG::FreeLPBits( LPBITMAPINFO lpBMI, LPBYTE lpB )
{
	if (WinGBitmap)
	{
		DeleteObject( WinGBitmap );
		WinGBitmap = NULL;
	}
	FreeDIB( lpBMI, NULL );
}
Exemple #3
0
// Bitmaps einlesen und Paletten initialisieren
bool CBildObjekt :: InitDIB (const char *pcFullName) 
{
int fh;					/* Dateihandle (evtl. komprimiertes File) */
OFSTRUCT of;            /* Dateistruktur */
HPALETTE hPalCurrent;   /* PaletteStruct */
HBITMAP hDIBCurrent;    /* DIB */
HBITMAP hBMCurrent;     /* DDB */

// alte DIB freigeben 
	FreeDIB ();

// Datei eröffnen, Speicherplatz anlegen
	fh = OpenFile (pcFullName, (OFSTRUCT *)&of, OF_READ);
	if (fh < 0) return false;

	hDIBCurrent = ReadDIBitmapInfo (fh);    // Farbtabelle lesen

// Gültigkeit der DIB-Datei prüfen 
	if (hDIBCurrent == NULL) {
		_lclose (fh);
		return false;
	}
	m_hDIB = hDIBCurrent;					// im Objekt merken

// PaletteSetup 
	hPalCurrent = CreateDIBPalette ();		// Palette bilden
	if (hPalCurrent == NULL) {
		_lclose (fh);
		return false;
	}
	m_hPal = hPalCurrent;

// DIB einlesen 
	hDIBCurrent = ReadDIB (fh);
	if (!hDIBCurrent) {
		_lclose (fh);
		return false;
	}
	m_hDIB = hDIBCurrent;
	_lclose (fh);

// DDB bilden
	hBMCurrent = DIBToBitmap();
	if (!hBMCurrent)
		return false;

	m_hDDB = hBMCurrent;

return true;
}
Exemple #4
0
BOOL OutputPNG::TidyUp()
{
    // Just in case we have any png related bits left around
    // Call up function to clean up the png structures
    CleanUpPngStructures();

    // Free up the DIB that we have just created
    if (DestBitmapInfo && DestBitmapBytes)
    {
        FreeDIB( DestBitmapInfo, DestBitmapBytes );
        DestBitmapInfo = NULL;
        DestBitmapBytes = NULL;
    }

    // Call the baseclass version to do its stuff
    const BOOL ok = OutputDIB::TidyUp();

    return ok;
}
Exemple #5
0
KernelBitmap *CDRBitmap::ConvertBitmap4(RIFFFile *RIFF, DWORD *Reference, CDRFilter *C)
{
	// check various things
	ERROR3IF(RIFF->GetObjChunkType() != cdrT_bmp, "ConvertBitmap called for non-bitmap RIFF chunk");
	ERROR3IF(RIFF->GetObjType() != RIFFOBJECTTYPE_CHUNK, "ConvertBitmap called for a non-chunk RIFF object");

	if(RIFF->GetObjSize() < sizeof(cdrfBitmapHeader4))
	{
		// Empty 'if' statement
		// Anyone's guess if this was intended
		// Changed to this form to remove a compiler warning
		// Markn 19/3/99
	}

	// get some data from the RIFF file
	cdrfBitmapHeader4 Hdr;

	// get the header from offset 0
	if(!RIFF->GetChunkData((ADDR)&Hdr, sizeof(Hdr), 0))
		return 0;

	// check the header...
	if((((Hdr.SizeX * Hdr.SizeY) / Hdr.Depth) + Hdr.ImageOffset - cdrfBitmapHeaderImageOffsetCorrect)
					> (DWORD)RIFF->GetObjSize()
					|| Hdr.Depth < 1 || Hdr.Depth > 32)
	{
TRACEUSER( "Ben", _T("Header in CDR bitmap doesn't check out\n"));
		return 0;
	}

	// store the reference
TRACEUSER( "Ben", _T("Bitmap reference = %X\n"), Hdr.Reference);
	*Reference = Hdr.Reference;

	// find a plausible number of palette entries...
	INT32 NPaletteEntries = Hdr.NPaletteEntries;

	if(NPaletteEntries > (1 << Hdr.Depth))
		NPaletteEntries = (1 << Hdr.Depth);

	if(NPaletteEntries < 0)
		NPaletteEntries = 0;	

	// is it a greyscale type bitmap?
	BOOL Greyscale = FALSE;
//	if(Hdr.Depth <= 8 && Hdr.ImageType == cdrfBITMAPTYPE_GREYSCALE)
//		Greyscale = TRUE;

	// OK, create a bitmap...
	LPBYTE Image;
	LPBITMAPINFO ImageHeader;
	ImageHeader = AllocDIB(Hdr.SizeX, Hdr.SizeY, Hdr.Depth, &Image);

	if(ImageHeader == 0)
		return 0;

	// right then, sort out that there palette if we really want to
	if(Hdr.Depth <= 8)
	{
		if(Greyscale)
		{	// it's a greyscale image - create a nice palette
			UINT32 Entries = 1 << Hdr.Depth;
			UINT32 Inc = 256 / Entries;
			UINT32 Value = 0;
			UINT32 l;

			for(l = 0; l < Entries; l++)
			{
				ImageHeader->bmiColors[l].rgbRed = Value;
				ImageHeader->bmiColors[l].rgbGreen = Value;
		 		ImageHeader->bmiColors[l].rgbBlue = Value;
				ImageHeader->bmiColors[l].rgbReserved = 0;

				Value += Inc;
			}
		}
		else
		{	// it's a colour image - load it's palette from the file
			// load the palette data into the palette in the created bitmap
			if(!RIFF->GetChunkData((ADDR)ImageHeader->bmiColors,
					sizeof(cdrfBitmapPaletteEntry4) * NPaletteEntries, sizeof(cdrfBitmapHeader4)))
			{
				FreeDIB(ImageHeader, Image);
				return 0;
			}
		}
	}

	// work out the scanline lengths (aligns to 4 bytes)
	INT32 RawScanlineLength = Hdr.SizeX * Hdr.Depth;	// in bits
	INT32 ScanlineLength = ((RawScanlineLength + 31) / 32) * 4;

	// set up offsets of current line
	INT32 SourceOffset;
	
	if(Greyscale)
	{
		SourceOffset = cdrfBitmapGreyscaleImageStart;
	}
	else
	{
		SourceOffset = sizeof(cdrfBitmapHeader) + Hdr.ImageOffset - cdrfBitmapHeaderImageOffsetCorrect;
	}

	// grab the image data, it's in the same sort of format as a DIB file. Helpfully
//	if(!RIFF->GetChunkData((ADDR)Image, ScanlineLength * Hdr.SizeY, SourceOffset))
//	{
//		FreeDIB(ImageHeader, Image);
//		return 0;
//	}
	INT32 SizeLeftToGet = ScanlineLength * Hdr.SizeY;
	INT32 Size, Got = 0;

	while(SizeLeftToGet > 0)
	{
		if(SizeLeftToGet > PROGRESS_BLOCKSIZE)
			Size = PROGRESS_BLOCKSIZE;
		else
			Size = SizeLeftToGet;
		
		if(!RIFF->GetChunkData((ADDR)Image + Got, Size, SourceOffset + Got))
		{
			FreeDIB(ImageHeader, Image);
			return 0;
		}
	
		SizeLeftToGet -= Size;
		Got += Size;

		C->UpdateProgress(TRUE);
	}

	// OK, it's all filled in. Create a KernelBitmap from it.
	// first of all, get ourself a nice OIL bitmap
	WinBitmap *WinB = new WinBitmap(ImageHeader, Image);

	if(WinB == 0)
	{
		FreeDIB(ImageHeader, Image);
		return 0;
	}

	// get it to cache some interesting stuff
	WinB->CacheGeometry();

	// and now get a KernelBitmap
	KernelBitmap *KerB = new KernelBitmap(WinB);

	if(KerB == 0)
	{
		delete WinB;
		return 0;
	}

	// and that's it for now, folks
	return KerB;
}
Exemple #6
0
KernelBitmap *CDRBitmap::ConvertPattern(RIFFFile *RIFF, DWORD *Reference, CDRFilter *C)
{
TRACEUSER( "Ben", _T("Converting pattern\n"));
	// check various things
	ERROR3IF(RIFF->GetObjChunkType() != cdrT_bmpf, "ConvertPattern called for non-pattern RIFF chunk");
	ERROR3IF(RIFF->GetObjType() != RIFFOBJECTTYPE_CHUNK, "ConvertPattern called for a non-chunk RIFF object");

	if(RIFF->GetObjSize() < sizeof(cdrfPatternBitmapHeader))
	{
		// Empty 'if' statement
		// Anyone's guess if this was intended
		// Changed to this form to remove a compiler warning
		// Markn 19/3/99
	}

	// get some data from the RIFF file
	cdrfPatternBitmapHeader Hdr;

	// get the header from offset 0
	if(!RIFF->GetChunkData((ADDR)&Hdr, sizeof(Hdr), 0))
		return 0;

	// check the header...
	if(((Hdr.SizeX * Hdr.SizeY) / 8) > Hdr.DataSize || Hdr.DataSize > (DWORD)RIFF->GetObjSize())
	{
TRACEUSER( "Ben", _T("Header in CDR pattern doesn't check out\n"));
		return 0;
	}

	// store the reference
TRACEUSER( "Ben", _T("Pattern reference = %X\n"), Hdr.Reference);
	*Reference = Hdr.Reference;

	// OK, create a bitmap...
	// it's always a 1 bpp bitmap
	LPBYTE Image;
	LPBITMAPINFO ImageHeader;
	ImageHeader = AllocDIB(Hdr.SizeX, Hdr.SizeX, 1, &Image);

	if(ImageHeader == 0)
		return 0;

	// check and then fill in the image data
	if(ImageHeader->bmiHeader.biSizeImage < (Hdr.DataSize - (sizeof(DWORD) * 3)))
	{
		FreeDIB(ImageHeader, Image);
		return 0;
	}

	// set some palette data
	ImageHeader->bmiColors[0].rgbBlue = 0;
	ImageHeader->bmiColors[0].rgbGreen = 0;
	ImageHeader->bmiColors[0].rgbRed = 0;
	ImageHeader->bmiColors[0].rgbReserved = 0;
	ImageHeader->bmiColors[1].rgbBlue = 0xff;
	ImageHeader->bmiColors[1].rgbGreen = 0xff;
	ImageHeader->bmiColors[1].rgbRed = 0xff;
	ImageHeader->bmiColors[1].rgbReserved = 0;

	// corel bitmaps align the scanlines to the nearest byte, not the nearest word
	// how long is a corel scanline
	INT32 SourceScanlineLength = (Hdr.SizeX + 7)	/ 8;
	
	// how long is the destination scanline?
	INT32 DestScanlineLength = ((Hdr.SizeX + 31) / 32) * 4;

	// sanity check
	ERROR3IF(DestScanlineLength < SourceScanlineLength, "Problem with scanline length calculations");
	
	// set up offsets of current line
	INT32 SourceOffset = Hdr.DataOffset + (sizeof(DWORD) * 3);
	INT32 DestOffset = ImageHeader->bmiHeader.biSizeImage - DestScanlineLength;
	
	// grab the image data, backwards
	INT32 Line;
	for(Line = 0; Line < (INT32)Hdr.SizeY; Line++)
	{
		if(!RIFF->GetChunkData(((ADDR)Image) + DestOffset,
				SourceScanlineLength, SourceOffset))
		{
			FreeDIB(ImageHeader, Image);
			return 0;
		}

		SourceOffset += SourceScanlineLength;
		DestOffset -= DestScanlineLength;

		if((Line & 0xf) == 0)
			C->UpdateProgress(TRUE);
	}

	// OK, it's all filled in. Create a KernelBitmap from it.
	// first of all, get ourself a nice OIL bitmap
	WinBitmap *WinB = new WinBitmap(ImageHeader, Image);

	if(WinB == 0)
	{
		FreeDIB(ImageHeader, Image);
		return 0;
	}

	// and now get a KernelBitmap
	KernelBitmap *KerB = new KernelBitmap(WinB);

	if(KerB == 0)
	{
		delete WinB;
		return 0;
	}

	// and that's it for now, folks
	return KerB;
}
Exemple #7
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;
}
Exemple #8
0
LPBITMAPINFO GRenderWinG::GetLPBits( INT32 Width, INT32 Height, INT32 Depth, LPBYTE*lplpBits)
{
	// get a bitmap header with no bits
	const LPBITMAPINFO bmInfo = AllocDIB( Width, Height, Depth, NULL );
	if (!bmInfo)
		return NULL;

	// tell it the sort of palette we want - we want Gavin's
	if (Depth==8)
	{
	#if 0
		RGBQUAD *rgb = bmInfo->bmiColors;
		LPPALETTEENTRY lpPal = GetRecommendedPalette()->palPalEntry;

		size_t i ;
		for ( i=0 ; i<256 ; i++ )
		{
			rgb->rgbRed = lpPal->peRed;
			rgb->rgbGreen = lpPal->peGreen;
			rgb->rgbBlue = lpPal->peBlue;
			rgb->rgbReserved = 0;
			rgb ++;
			lpPal++;
		}
	#else

		GetSystemPaletteEntries (
			RenderDC->m_hDC, 0, 256, (LPPALETTEENTRY) bmInfo->bmiColors
		) ;
		RGBQUAD *rgb = bmInfo->bmiColors ;					// Swap R and B.
		size_t i ;
		for ( i=0 ; i<256 ; i++ )
		{
			BYTE t = rgb->rgbRed ;
			rgb->rgbRed = rgb->rgbBlue ;
			rgb->rgbBlue = t ;
			rgb ++ ;
		}
	#endif
	}

	// if WinG wants it upside-down then go for it
	if (RecommendedDIB.biHeight == -1)
	{
		Inverted = TRUE;
		bmInfo->bmiHeader.biHeight = -bmInfo->bmiHeader.biHeight;
	}
	else
		Inverted = FALSE;

	// now get a lovely WinG bitmap
	WinGBitmap = pWinGCreateBitmap( OffScreenDC, bmInfo, (void FAR* FAR *)lplpBits );
	if (WinGBitmap==NULL)
	{
		TRACE( _T("WinGCreateBitmap failed\n"));
		FreeDIB( bmInfo, NULL );
		return NULL;
	}

	// turn it back the other way else Gavin is likely to get confused
	if (Inverted)
		bmInfo->bmiHeader.biHeight = -bmInfo->bmiHeader.biHeight;

	//TRACE( _T("WinG Alloc %lx=%lx:%lx\n"), this, bmInfo, *lplpBits);
	return bmInfo;
}
Exemple #9
0
// Destruktor 
CBildObjekt :: ~CBildObjekt (void) 
{
	FreeDIB ();     // alles freigeben
}