Exemplo n.º 1
0
int process_segment(void)
{
    word marker;
    int err;
    
    marker = fetch_word();
    if (marker == 0xFFD9)
    {
		iceenv.eoi = 1;
#ifdef _JPEG_DEBUG
        printf("EOI detected! Done.\n");
#endif
        return ERR_OK;
    }
    
    iceenv.cur_segment_len = fetch_word();
    
    switch (marker)
    {
        case 0xFFE0:
            err = process_app0();
            break;
        case 0xFFDB:
            err = process_dqt();
            break;
        case 0xFFC0:
            err = process_sof0();
            break;
        case 0xFFC4:
            err = process_dht();
            break;
        case 0xFFDD:
            err = process_dri();
            break;
        case 0xFFDA:
            err = gen_huffman_tables();
            err = process_sos();
            err = decode_scan();
            err = upsample();
            err = create_image();
            break;
		case 0xFFC1:
		case 0xFFC2:
		case 0xFFC3:
		case 0xFFC5:
		case 0xFFC6:
		case 0xFFC7:
		case 0xFFC9:
		case 0xFFCA:
		case 0xFFCB:
		case 0xFFCD:
		case 0xFFCE:
		case 0xFFCF:
			err = ERR_NOT_BASELINE;
			break;
		default:
#ifdef _JPEG_DEBUG
            printf("Skipping unknown segment %X\n", marker & 0xFF);
#endif
            iceenv.buf_pos += iceenv.cur_segment_len - 2;
            err = ERR_OK;
            break;
    }
    
    return err;
}
Exemplo n.º 2
0
	JPEGLoader::JPEGLoader(const IODevicePtr &iodevice)
		: progressive(false), scan_count(0), mcu_x(0), mcu_y(0), mcu_width(0), mcu_height(0), restart_interval(0), eobrun(0), is_jfif_jpeg(false), is_adobe_jpeg(false), adobe_app14_transform(1)
	{
		JPEGFileReader reader(iodevice);

		JPEGMarker marker = reader.read_marker();
		if (marker != marker_soi)
			throw Exception("Not a JPEG file");

		marker = reader.read_marker();
		while (marker != marker_eoi)
		{
			if (marker == marker_app0)
			{
				process_app0(reader);
			}
			else if (marker == marker_app14)
			{
				process_app14(reader);
			}
			else if ((marker >= marker_sof0 && marker <= marker_sof3) || (marker >= marker_sof5 && marker <= marker_sof15))
			{
				process_sof(marker, reader);
			}
			else if (marker == marker_dht)
			{
				process_dht(reader);
			}
			else if (marker == marker_dqt)
			{
				process_dqt(reader);
			}
			else if (marker == marker_dri)
			{
				restart_interval = reader.read_dri();
			}
			else if (marker == marker_sos)
			{
				/*try
				{*/
				process_sos(reader);
				/*}
				catch (...)
				{
				char buffer[16*1024];
				while (reader.read_entropy_data(buffer, 16*1024) != 0);
				}*/
			}
			else if (marker == marker_dnl)
			{
				process_dnl(reader);
			}
			else
			{
				reader.skip_unknown();
			}

			marker = reader.read_marker();
		}

		if (scan_count == 0 || start_of_frame.height == 0)
			throw Exception("Invalid JPEG Image");
	}