Exemplo n.º 1
0
bool ieJpegDecoder::ParseScanHeader()
// Read the start of a scan (everything through the SOS marker).
// Return true if find SOS, false if find EOI.
{
	// Process markers until SOS or EOI
	int c = ParseTables();
	if (c == M_ERROR) return false;

	switch (c) {
	case M_SOS:
		return GetSOS();

	case M_EOI:
		iScanNumber = 0;
		return true;

	default:
		return false;
	}
}
Exemplo n.º 2
0
// parse and load a DXF file
// currently pretty limited, but knows enough to handle 3DFACEs and LINEs
bool DXFRenderer::Load(wxInputStream& stream)
{
    Clear();
    wxTextInputStream text(stream);

    wxString line1, line2;
    while (stream.CanRead())
    {
        GetLines(text, line1, line2);
        if (line1 == "999") // comment
            continue;
        else if (line1 == "0" && line2 == "SECTION")
        {
            GetLines(text, line1, line2);
            if (line1 == "2")
            {
                if (line2 == "HEADER")
                {
                    if (!ParseHeader(stream))
                        return false;
                }
                else if (line2 == "TABLES")
                {
                    if (!ParseTables(stream))
                        return false;
                }
                else if (line2 == "ENTITIES")
                {
                    if (!ParseEntities(stream))
                        return false;
                }
            }
        }
    }

    NormalizeEntities();
    m_loaded = true;
    return true;
}
Exemplo n.º 3
0
ieResult ieJpegDecoder::ParseHeaders()
// Initialize and read the file header (everything through the SOF marker).
{
	// Demand an SOI marker at the start of the file --- otherwise it's
	// probably not a JPEG file at all.  If the user interface wants to support
	// nonstandard headers in front of the SOI, it must skip over them itself
	// before calling jpeg_decompress().
	if (GetWord() != 0xFFD8) return IE_E_CORRUPTEDFILE;

	// OK, process SOI
	GetSOI();

	// Process markers until SOF
	int	c = ParseTables();

	bArithCoding = false;
	bLosslessDPCM = false;
	bProgressive = false;

	switch (c) {

    case M_ERROR:
    	return IE_E_CORRUPTEDFILE;

	case M_SOF0:     	// Baseline sequential Huffman
	case M_SOF1:      	// Extended sequential Huffman
		break;
	case M_SOF2:     	// Progressive Huffman
        bProgressive = true;
		break;

	case M_SOF5:		// Differential sequential Huffman
		bLosslessDPCM = true;
		break;
	case M_SOF6:		// Differential progressive Huffman
        bProgressive = true;
		bLosslessDPCM = true;
		break;

	case M_SOF9:  	    // Extended sequential arithmetic
		bArithCoding = true;
		break;
	case M_SOF10:  	    // Progressive arithmetic
		bArithCoding = true;
        bProgressive = true;
		break;

	case M_SOF13:		// Differential sequential arithmetic
		bArithCoding = true;
		bLosslessDPCM = true;
		break;

	case M_SOF14:		// Differential progressive arithmetic
        bProgressive = true;
		bArithCoding = true;
		bLosslessDPCM = true;
		break;

	//case M_SOF3:     	// Spatial Huffman
	//case M_SOF7:		// Differential spatial Huffman
	//case M_JPG:		// Reserved for JPEG extensions
	//case M_SOF11:		// Spatial arithmetic
	//case M_SOF15:		// Differential lossless, arithmetic
	//case M_EOI:		// No image data?
	default:
		return IE_E_UNSUPSUBFORMAT;
	}

    if (!GetSOF(c)) return IE_E_CORRUPTEDFILE;
    iScanNumber = 0;

	// Figure out what colorspace we have:
	// (too bad the JPEG committee didn't provide a real way to specify this)
	if (eColorSpace == ieColorSpace::Count) switch (nComps) {
	case 1:
		eColorSpace = ieColorSpace::L;
		break;
	case 3:
		if ((aComps[0].iId == 1) && (aComps[1].iId == 2) && (aComps[2].iId == 3))
			eColorSpace = ieColorSpace::YCbCr;
		else if ((aComps[0].iId == 82) && (aComps[1].iId == 71) && (aComps[2].iId == 66))
			eColorSpace = ieColorSpace::RGB;
		else
			eColorSpace = ieColorSpace::YCbCr;
		break;
	case 4:
		if ((aComps[0].iId == 67) && (aComps[1].iId == 77) && (aComps[2].iId == 89) && (aComps[3].iId == 75))
			eColorSpace = ieColorSpace::CMYL;	// Adobe CMYK
		else
			eColorSpace = ieColorSpace::CMYK;
		break;
	}

	// Compute maximum sampling factors; check factor validity
	iMaxXSamp = 1;
	iMaxYSamp = 1;
	for (int ci = 0; ci < nComps; ci++) {
		jdCompInfo &co = aComps[ci];
		if (	(co.iXSamp <= 0) || (co.iXSamp > IE_JPEG_MAX_SAMP) ||
				(co.iYSamp <= 0) || (co.iYSamp > IE_JPEG_MAX_SAMP)	)
			 return IE_E_CORRUPTEDFILE;
		if (co.iXSamp > iMaxXSamp) iMaxXSamp = co.iXSamp;
		if (co.iYSamp > iMaxYSamp) iMaxYSamp = co.iYSamp;
	}

	// Compute logical dimensions of components
	nXRes = ie_RoundUp(nRealXRes, iMaxXSamp * DCTSIZE);
	nYRes = ie_RoundUp(nRealYRes, iMaxYSamp * DCTSIZE);

	return IE_S_OK;
}