Example #1
0
/* Return when an SOI, EOI, SOFn, or SOS is found */
PUBLIC JPEG_MARKER_E ProcessTables(JPEG_DEC_INPUT_PARA_T  *jpeg_dec_input)
{
	uint32 c = 0;

	while (TRUE)/*lint !e716*/
	{
		if(!GetNextMarker(&c))
		{
			return M_ERROR;
		}

		switch (c) 
		{
			case M_SOF0:
			case M_SOF1:
				if(GetSOF(FALSE, jpeg_dec_input) != JPEG_SUCCESS)
				{
					return M_ERROR;
				}
				break;
			case M_SOF2:
				if(GetSOF(TRUE, jpeg_dec_input) != JPEG_SUCCESS)
				{
					return M_ERROR;
				}
				JPEG_TRACE("Sorry, we can not support the Progressive image!\n");
				break;
				//return M_ERROR;
			case M_SOI:
			case M_EOI:
			case M_SOS:
				return c;

			case M_DHT:
				if(GetHuffTbl() != JPEG_SUCCESS)
				{
					return M_ERROR;
				}
				break;

			case M_DQT:
				if(GetQuantTbl() != JPEG_SUCCESS)
				{
					return M_ERROR;
				}
				break;

			case M_APP0:
				if(GetAPP0() != JPEG_SUCCESS)
				{
					return M_ERROR;
				}
				break;

			case M_DRI:
				if(GetDRI() != JPEG_SUCCESS)
				{
					return M_ERROR;
				}
				break;

		//	case M_SOF1:
			case M_SOF3:
			case M_SOF5:
			case M_SOF6:
			case M_SOF7:
			case M_JPG:
			case M_SOF9:
			case M_SOF10:
			case M_SOF11:
			case M_SOF13:
			case M_SOF14:
			case M_SOF15:
			case M_DAC:
			case M_RST0:
			case M_RST1:
			case M_RST2:
			case M_RST3:
			case M_RST4:
			case M_RST5:
			case M_RST6:
			case M_RST7:
			case M_TEM:
	 			JPEG_TRACE("Unexpected marker 0x%02x\n", c);
				return M_ERROR;

			default:	/* must be DNL, DHP, EXP, APPn, JPGn, COM, or RESn */
				if(SkipVariable(jpeg_dec_input) != JPEG_SUCCESS)
				{
					return M_ERROR;
				}
				break;
		}
	}
}
Example #2
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;
}