Beispiel #1
0
Dynamic PreCallback_obj::__Field(const ::String &inName,bool inCallProp)
{
	switch(inName.length) {
	case 4:
		if (HX_FIELD_EQ(inName,"int2") ) { return get_int2(); }
		if (HX_FIELD_EQ(inName,"int1") ) { return get_int1(); }
		break;
	case 7:
		if (HX_FIELD_EQ(inName,"swapped") ) { return get_swapped(); }
		if (HX_FIELD_EQ(inName,"arbiter") ) { return get_arbiter(); }
		break;
	case 8:
		if (HX_FIELD_EQ(inName,"toString") ) { return toString_dyn(); }
		if (HX_FIELD_EQ(inName,"get_int2") ) { return get_int2_dyn(); }
		if (HX_FIELD_EQ(inName,"get_int1") ) { return get_int1_dyn(); }
		break;
	case 11:
		if (HX_FIELD_EQ(inName,"get_swapped") ) { return get_swapped_dyn(); }
		if (HX_FIELD_EQ(inName,"get_arbiter") ) { return get_arbiter_dyn(); }
	}
	return super::__Field(inName,inCallProp);
}
Beispiel #2
0
/* returns 0 in case of failure */
static unsigned int guess_mjpeg_type(unsigned char *data, unsigned int size,
		int d_height) {
	unsigned int p;
	int marker, length, height, i, hf[3], vf[3];
	unsigned int app0 = 0, header = 0;

	/* The initial marker must be SIO */
	if (size < 2) {
		ERROR("JPEG data too short (%d bytes)\n", size);
		return 0;
	}

	if (data[0] != 0xFF || data[1] != M_SOI) {
		ERROR("JPEG data must start with FFD8, but doesn't\n");
		return 0;
	}

	p = 2; /* pointer within jpeg data */

	while (p < size) {
		/* search 0xFF */
		while(data[p] != 0xFF) {
			p++;
			if (p >= size) return 0;
		}

		/* get marker code, skip duplicate FF's */
		while(data[p] == 0xFF) {
			p++;
			if (p >= size) return 0;
		}

		marker = data[p++];

		/* marker may have an associated length */
		if (p <= size - 2) length = get_int2(data+p);
		else length = 0;

		switch (marker) {
			case M_SOF0:
			case M_SOF1:
				header = p-2;
				VERBOSE("found offset of header %u\n",
						header);
				break;
			case M_SOS:
				size = 0;
				continue;
			case M_APP0:
				app0 = p-2;
				VERBOSE("found offset of APP0 %u\n",
						app0);
				break;
		}

		/* these markers shouldn't have parameters,
		 * i.e. we don't need to skip anaything */
		if (marker == 0 || marker == 1 ||
				(marker >= 0xd0 && marker < 0xd8))
			continue;

		if  (p + length <= size) p += length;
		else {
			ERROR("input JPEG too short, data missing\n");
			return 0;
		}
	}

	if (!header) {
		ERROR("JPEG header (with resolution and sampling factors) not found\n");
		return 0;
	}

	if (data[header + 9] != 3) {
		ERROR("JPEG has wrong number of components\n");
		return 0;
	}

	/* get the horizontal and vertical sample factors */
	for (i = 0; i < 3; i++) {
		hf[i] = data[header + 10 + 3*i + 1]>>4;
		vf[i] = data[header + 10 + 3*i + 1]&0x0F;
	}

	if (hf[0] != 2 || hf[1] != 1 || hf[2] != 1 ||
			vf[0] != 1 || vf[1] != 1 || vf[2] != 1) {
		ERROR("JPEG has wrong internal image format\n");
	} else VERBOSE("JPEG has colorspace YUV422 with minimal sampling factors (good)\n");

	height = get_int2(data + header + 5);
	if (height == d_height) {
		VERBOSE("data is non interlaced\n");
		return IMGFMT_ZRMJPEGNI;
	}

	if (2*height != d_height) {
		ERROR("something very inconsistent happened\n");
		return 0;
	}


	if (app0 && get_int2(data + app0 + 2) >= 5 &&
			strncasecmp((char*)(data + app0 + 4), "AVI1", 4) == 0) {
		if (data[app0+8] == 1) {
			VERBOSE("data is interlaced, APP0: top-first (1)\n");
			return IMGFMT_ZRMJPEGIT;
		} else {
			VERBOSE("data is interlaced, APP0: bottom-first (%d)\n",
					data[app0+8]);
			return IMGFMT_ZRMJPEGIB;
		}
	} else {
		VERBOSE("data is interlaced, no (valid) APP0 marker, "
				"guessing top-first\n");
		return IMGFMT_ZRMJPEGIT;
	}


	return 0;
}