Esempio n. 1
0
static int generate_from_avi(const char *aviname)
{
	UINT32 line12 = 0, line13 = 0, line14 = 0, framenum = 0, chapternum = 0;
	const avi_movie_info *info;
	bitmap_t *bitmap;
	avi_error avierr;
	avi_file *avi;
	int white = 0;
	int frame;

	/* open the file */
	avierr = avi_open(aviname, &avi);
	if (avierr != AVIERR_NONE)
	{
		fprintf(stderr, "Error opening AVI file: %s\n", avi_error_string(avierr));
		return 1;
	}

	/* extract movie info */
	info = avi_get_movie_info(avi);
	fprintf(stderr, "%dx%d - %d frames total\n", info->video_width, info->video_height, info->video_numsamples);
	if (info->video_height != 39)
	{
		fprintf(stderr, "Unknown VANC capture format: expected 39 rows\n");
		return 1;
	}

	/* allocate a bitmap to hold it */
	bitmap = bitmap_alloc(info->video_width, info->video_height, BITMAP_FORMAT_YUY16);
	if (bitmap == NULL)
	{
		fprintf(stderr, "Out of memory allocating %dx%d bitmap\n", info->video_width, info->video_height);
		return 1;
	}

	/* loop over frames */
	for (frame = 0; frame < info->video_numsamples; frame++)
	{
		int field;
		UINT8 bits[24];

		/* read the frame */
		avierr = avi_read_video_frame_yuy16(avi, frame, bitmap);
		if (avierr != AVIERR_NONE)
		{
			fprintf(stderr, "Error reading AVI frame %d: %s\n", frame, avi_error_string(avierr));
			break;
		}

		/* loop over two fields */
		for (field = 0; field < 2; field++)
		{
			int prevwhite = white;
			int i;

			/* line 7 contains the white flag */
			white = 0;
			if (*BITMAP_ADDR16(bitmap, 20 * field + 7, bitmap->width / 2) > 0x8000)
				white = 1;

			/* output metadata for *previous* field */
			if (frame > 0 || field > 0)
			{
				int flags = 0;

				if (!prevwhite) flags |= 0x01;
				if (!white) flags |= 0x02;
				output_meta(flags, prevwhite, line12, line13, line14, framenum, chapternum);
			}

			/* line 12 contains stop code and other interesting bits */
			line12 = 0;
			if (parse_line(bitmap, 20 * field + 12, 24, bits) == 24)
				for (i = 0; i < 24; i++)
					line12 = (line12 << 1) | bits[i];

			/* line 13 and 14 contain frame/chapter/lead in/out encodings */
			line13 = 0;
			if (parse_line(bitmap, 20 * field + 13, 24, bits) == 24)
				for (i = 0; i < 24; i++)
					line13 = (line13 << 1) | bits[i];

			line14 = 0;
			if (parse_line(bitmap, 20 * field + 14, 24, bits) == 24)
				for (i = 0; i < 24; i++)
					line14 = (line14 << 1) | bits[i];

			/* the two lines must match */
//          if (line13 != 0 && line14 != 0 && line13 != line14)
//              line13 = line14 = 0;

			/* is this a frame number? */
			if ((line13 & 0xf00000) == 0xf00000)
				framenum = line13 & 0x7ffff;
			if ((line13 & 0xf00fff) == 0x800ddd)
				chapternum = (line13 >> 12) & 0x7f;
		}
	}

	/* output metadata for *previous* field */
	{
		int flags = 0;

		if (!white) flags |= 0x01;
		output_meta(flags, white, line12, line13, line14, framenum, chapternum);
	}

	bitmap_free(bitmap);
	return 0;
}
Esempio n. 2
0
static int generate_from_pattern(pattern_data *pattern, int patcount)
{
	pattern_data *curpat = pattern;
	int framenum = 0, bcdframenum = 0;

	/* loop until we exceed the pattern frame count */
	while (1)
	{
		UINT32 line16, line17, line18;
		int flags = 0;

		/* handle special codes for line 16 */
		line16 = curpat->line16;
		if (line16 == INSERT_FRAME_CODE_INC)
		{
			framenum++;
			bcdframenum = (((framenum / 10000) % 10) << 16) | (((framenum / 1000) % 10) << 12) | (((framenum / 100) % 10) << 8) | (((framenum / 10) % 10) << 4) | (framenum % 10);
		}
		if (line16 == INSERT_FRAME_CODE || line16 == INSERT_FRAME_CODE_INC)
			line16 = 0xf80000 | bcdframenum;

		/* handle special codes for line 17 */
		line17 = curpat->line17;
		if (line17 == INSERT_FRAME_CODE_INC)
		{
			framenum++;
			bcdframenum = (((framenum / 10000) % 10) << 16) | (((framenum / 1000) % 10) << 12) | (((framenum / 100) % 10) << 8) | (((framenum / 10) % 10) << 4) | (framenum % 10);
		}
		if (line17 == INSERT_FRAME_CODE || line17 == INSERT_FRAME_CODE_INC)
			line17 = 0xf80000 | bcdframenum;

		/* handle special codes for line 18 */
		line18 = curpat->line18;
		if (line18 == INSERT_FRAME_CODE_INC)
		{
			framenum++;
			bcdframenum = (((framenum / 10000) % 10) << 16) | (((framenum / 1000) % 10) << 12) | (((framenum / 100) % 10) << 8) | (((framenum / 10) % 10) << 4) | (framenum % 10);
		}
		if (line18 == INSERT_FRAME_CODE || line18 == INSERT_FRAME_CODE_INC)
			line18 = 0xf80000 | bcdframenum;

		/* bail if we passed the end */
		if (framenum > patcount)
			return 0;

		/* if we don't have a white flag, the previous frame must match us */
		if (!curpat->white) flags |= 0x01;

		/* advance to the next pattern piece */
		curpat = curpat->next;
		if (curpat == NULL)
			curpat = pattern;

		/* if the new field doesn't have a white flag, it must match our current frame */
		if (!curpat->white) flags |= 0x02;

		/* output the result */
		output_meta(flags, curpat->white, line16, line17, line18, bcdframenum, 0);
	}

	return 0;
}
Esempio n. 3
0
void output_key (Key *k)
{
	// output_meta will print endline
	printf ("key: %s, string: %s", keyName(k), keyString(k));
	output_meta(k);
}