summaryrefslogtreecommitdiffstatshomepage
path: root/src/tools
diff options
context:
space:
mode:
author Aaron Giles <aaron@aarongiles.com>2012-01-12 21:19:49 +0000
committer Aaron Giles <aaron@aarongiles.com>2012-01-12 21:19:49 +0000
commite4238fb654d6ce33993877476566d42846fba9a0 (patch)
tree2f635b3572bebf756f7cd5015d7c6a950bade249 /src/tools
parent6a8a2afd4aed4bacfde0824259d47ce960c0983c (diff)
Major bitmap-related changes throughout the system. There are
almost certainly some regressions lurking. Let me know if something seems busted. Bitmaps are now strongly typed based on format. bitmap_t still exists as an abstract base class, but it is almost never used. Instead, format-specific bitmap classes are provided: bitmap_ind8 == 8bpp indexed bitmap_ind16 == 16bpp indexed bitmap_ind32 == 32bpp indexed bitmap_ind64 == 64bpp indexed bitmap_rgb32 == 32bpp RGB bitmap_argb32 == 32bpp ARGB bitmap_yuy16 == 16bpp YUY For each format, a generic pix() method is provided which references pixels of the correct type. The old pix8/pix16/pix32/ pix64 methods still exist in the short term, but the only one available is the one that matches the bitmap's pixel size. Note also that the old RGB15 format bitmaps are no longer supported at all. Converted model1, megadriv, and stv drivers away from the RGB15 format bitmaps. New auto_bitmap_<type>_alloc() macros are provided for allocating the appropriate type of bitmap. Screen update functions now must specify the correct bitmap type as their input parameters. For static update functions the SCREEN_UPDATE macro is now replaced with SCREEN_UPDATE_RGB32 and SCREEN_UPDATE_IND16 macros. All existing drivers have been updated to use the correct macros. Screen update functions are now required for all screens; there is no longer any default behavior of copying a "default" bitmap to the screen (in fact the default bitmap has been deprecated). Use one of the following to specify your screen_update callback: MCFG_SCREEN_UPDATE_STATIC(name) - static functions MCFG_SCREEN_UPDATE_DRIVER(class, func) - driver members MCFG_SCREEN_UPDATE_DEVICE(tag, class, func) - device members Because the target bitmap format can now be deduced from the screen update function itself, the MCFG_SCREEN_FORMAT macro is no longer necessary, and has been removed. If you specify a screen update callback that takes a bitmap_ind16, then the screen will be configured to use a 16bpp indexed bitmap, and if you specify a callback that takes a bitmap_rgb32, then a 32bpp RGB bitmap will be provided. Extended the bitmap classes to support wrapping a subregion of another bitmap, and cleaner allocation/resetting. The preferred use of bitmaps now is to define them directly in drivers/devices and use allocate() or wrap() to set them up, rather than allocating them via auto_bitmap_*_alloc(). Several common devices needed overhauls or changes as a result of the above changes: * Reorganized the laserdisc base driver and all the laserdisc drivers as modern C++ devices, cleaning the code up considerably. Merged ldsound device into the laserdsc device since modern devices are flexible enough to handle it. * Reorganized the v9938 device as a modern C++ device. Removed v9938mod.c in favor of template functions in v9938.c directly. * Added independent ind16 and rgb32 callbacks for TMS340x0 devices. * All video devices are now hard-coded to either ind16 or rgb32 bitmaps. The most notable is the mc6845 which is rgb32, and required changes to a number of consumers. * Added screen_update methods to most video devices so they can be directly called via MCFG_SCREEN_UPDATE_DEVICE instead of creating tons of stub functions.
Diffstat (limited to 'src/tools')
-rw-r--r--src/tools/chdman.c628
-rw-r--r--src/tools/ldresample.c15
-rw-r--r--src/tools/ldverify.c206
-rw-r--r--src/tools/regrep.c80
4 files changed, 447 insertions, 482 deletions
diff --git a/src/tools/chdman.c b/src/tools/chdman.c
index 4ed70853c95..18775497311 100644
--- a/src/tools/chdman.c
+++ b/src/tools/chdman.c
@@ -854,7 +854,7 @@ cleanup:
read_avi_frame - read an AVI frame
-------------------------------------------------*/
-static avi_error read_avi_frame(avi_file *avi, UINT32 framenum, UINT32 first_sample, bitmap_t *fullbitmap, int interlaced, av_codec_compress_config *avconfig)
+static avi_error read_avi_frame(avi_file *avi, UINT32 framenum, UINT32 first_sample, bitmap_yuy16 &fullbitmap, int interlaced, av_codec_compress_config *avconfig)
{
const avi_movie_info *info = avi_get_movie_info(avi);
int interlace_factor = interlaced ? 2 : 1;
@@ -873,16 +873,16 @@ static avi_error read_avi_frame(avi_file *avi, UINT32 framenum, UINT32 first_sam
/* read the video data when we hit a new frame */
if (framenum % interlace_factor == 0)
{
- avierr = avi_read_video_frame_yuy16(avi, framenum / interlace_factor, *fullbitmap);
+ avierr = avi_read_video_frame(avi, framenum / interlace_factor, fullbitmap);
if (avierr != AVIERR_NONE)
goto cleanup;
}
/* build the fake bitmap */
if (!interlaced)
- avconfig->video->clone_existing(*fullbitmap);
+ avconfig->video.wrap(fullbitmap, fullbitmap.cliprect());
else
- avconfig->video = new(avconfig->video) bitmap_t(&fullbitmap->pix16(framenum % interlace_factor), fullbitmap->width(), fullbitmap->height() / 2, fullbitmap->rowpixels() * 2, fullbitmap->format());
+ avconfig->video.wrap(&fullbitmap.pix16(framenum % interlace_factor), fullbitmap.width(), fullbitmap.height() / 2, fullbitmap.rowpixels() * 2);
cleanup:
return avierr;
@@ -893,7 +893,7 @@ cleanup:
fake_avi_frame - fake an AVI frame
-------------------------------------------------*/
-static avi_error fake_avi_frame(avi_file *avi, UINT32 framenum, UINT32 first_sample, bitmap_t *fullbitmap, int interlaced, av_codec_compress_config *avconfig)
+static avi_error fake_avi_frame(avi_file *avi, UINT32 framenum, UINT32 first_sample, bitmap_yuy16 &fullbitmap, int interlaced, av_codec_compress_config *avconfig)
{
static int framecounter = 0;
int leftsamp = (framenum % 200 < 10) ? 10000 : 0;
@@ -947,26 +947,26 @@ static avi_error fake_avi_frame(avi_file *avi, UINT32 framenum, UINT32 first_sam
/* build the fake bitmap */
if (!interlaced)
- avconfig->video->clone_existing(*fullbitmap);
+ avconfig->video.wrap(fullbitmap, fullbitmap.cliprect());
else
- avconfig->video = new(avconfig->video) bitmap_t(&fullbitmap->pix16(framenum % interlace_factor), fullbitmap->width(), fullbitmap->height() / 2, fullbitmap->rowpixels() * 2, fullbitmap->format());
+ avconfig->video.wrap(&fullbitmap.pix16(framenum % interlace_factor), fullbitmap.width(), fullbitmap.height() / 2, fullbitmap.rowpixels() * 2);
/* loop over the data and copy it to the cache */
- for (y = 0; y < avconfig->video->height(); y++)
+ for (y = 0; y < avconfig->video.height(); y++)
{
- UINT16 *dest = &avconfig->video->pix16(y);
+ UINT16 *dest = &avconfig->video.pix16(y);
/* white flag? */
if (y == 11 && whiteflag)
{
for (x = 0; x < AVI_FAKE_WIDTH; x++)
- *dest++ = (x > 10 && x < avconfig->video->width() - 10) ? 0xff80 : 0x0080;
+ *dest++ = (x > 10 && x < avconfig->video.width() - 10) ? 0xff80 : 0x0080;
}
/* line 17/18 */
else if ((y == 17 || y == 18) && line1718 != 0)
{
- for (x = 0; x < avconfig->video->width(); x++)
+ for (x = 0; x < avconfig->video.width(); x++)
{
UINT16 pixel = 0x0080;
if (x >= 20)
@@ -986,14 +986,14 @@ static avi_error fake_avi_frame(avi_file *avi, UINT32 framenum, UINT32 first_sam
/* anything else in VBI-land */
else if (y < 22)
{
- for (x = 0; x < avconfig->video->width(); x++)
+ for (x = 0; x < avconfig->video.width(); x++)
*dest++ = 0x0080;
}
/* everything else */
else
{
- for (x = 0; x < avconfig->video->width(); x++)
+ for (x = 0; x < avconfig->video.width(); x++)
*dest++ = framenum;
}
}
@@ -1011,15 +1011,13 @@ static int do_createav(int argc, char *argv[], int param)
{
UINT32 fps_times_1million, width, height, interlaced, channels, rate, totalframes;
UINT32 max_samples_per_frame, bytes_per_frame, firstframe, numframes;
- av_codec_compress_config avconfig = { 0 };
+ av_codec_compress_config avconfig;
const char *inputfile, *outputfile;
- bitmap_t *fullbitmap = NULL;
const avi_movie_info *info;
UINT8 *ldframedata = NULL;
const chd_header *header;
chd_file *chd = NULL;
avi_file *avi = NULL;
- bitmap_t fakebitmap;
double ratio = 1.0;
char metadata[256];
avi_error avierr;
@@ -1117,119 +1115,115 @@ static int do_createav(int argc, char *argv[], int param)
bytes_per_frame = 12 + channels * max_samples_per_frame * 2 + width * height * 2;
/* allocate a video buffer */
- fullbitmap = new(std::nothrow) bitmap_t(width, height * (interlaced ? 2 : 1), BITMAP_FORMAT_YUY16);
- if (fullbitmap == NULL)
{
- fprintf(stderr, "Out of memory allocating temporary bitmap\n");
- err = CHDERR_OUT_OF_MEMORY;
- goto cleanup;
- }
- avconfig.video = &fakebitmap;
+ bitmap_yuy16 fullbitmap(width, height * (interlaced ? 2 : 1));
+ avconfig.video.wrap(fullbitmap, fullbitmap.cliprect());
- /* allocate audio buffers */
- avconfig.channels = channels;
- for (chnum = 0; chnum < channels; chnum++)
- {
- avconfig.audio[chnum] = (INT16 *)malloc(max_samples_per_frame * 2);
- if (avconfig.audio[chnum] == NULL)
+ /* allocate audio buffers */
+ avconfig.channels = channels;
+ for (chnum = 0; chnum < channels; chnum++)
{
- fprintf(stderr, "Out of memory allocating temporary audio buffer\n");
- err = CHDERR_OUT_OF_MEMORY;
+ avconfig.audio[chnum] = (INT16 *)malloc(max_samples_per_frame * 2);
+ if (avconfig.audio[chnum] == NULL)
+ {
+ fprintf(stderr, "Out of memory allocating temporary audio buffer\n");
+ err = CHDERR_OUT_OF_MEMORY;
+ goto cleanup;
+ }
+ }
+
+ /* create the new CHD */
+ err = chd_create(outputfile, (UINT64)numframes * (UINT64)bytes_per_frame, bytes_per_frame, CHDCOMPRESSION_AV, NULL);
+ if (err != CHDERR_NONE)
+ {
+ fprintf(stderr, "Error creating CHD file: %s\n", chd_error_string(err));
goto cleanup;
}
- }
- /* create the new CHD */
- err = chd_create(outputfile, (UINT64)numframes * (UINT64)bytes_per_frame, bytes_per_frame, CHDCOMPRESSION_AV, NULL);
- if (err != CHDERR_NONE)
- {
- fprintf(stderr, "Error creating CHD file: %s\n", chd_error_string(err));
- goto cleanup;
- }
+ /* open the new CHD */
+ err = chd_open(outputfile, CHD_OPEN_READWRITE, NULL, &chd);
+ if (err != CHDERR_NONE)
+ {
+ fprintf(stderr, "Error opening new CHD file: %s\n", chd_error_string(err));
+ goto cleanup;
+ }
+ header = chd_get_header(chd);
- /* open the new CHD */
- err = chd_open(outputfile, CHD_OPEN_READWRITE, NULL, &chd);
- if (err != CHDERR_NONE)
- {
- fprintf(stderr, "Error opening new CHD file: %s\n", chd_error_string(err));
- goto cleanup;
- }
- header = chd_get_header(chd);
+ /* write the metadata */
+ sprintf(metadata, AV_METADATA_FORMAT, fps_times_1million / 1000000, fps_times_1million % 1000000, width, height, interlaced, channels, rate);
+ err = chd_set_metadata(chd, AV_METADATA_TAG, 0, metadata, strlen(metadata) + 1, CHD_MDFLAGS_CHECKSUM);
+ if (err != CHDERR_NONE)
+ {
+ fprintf(stderr, "Error adding AV metadata: %s\n", chd_error_string(err));
+ goto cleanup;
+ }
- /* write the metadata */
- sprintf(metadata, AV_METADATA_FORMAT, fps_times_1million / 1000000, fps_times_1million % 1000000, width, height, interlaced, channels, rate);
- err = chd_set_metadata(chd, AV_METADATA_TAG, 0, metadata, strlen(metadata) + 1, CHD_MDFLAGS_CHECKSUM);
- if (err != CHDERR_NONE)
- {
- fprintf(stderr, "Error adding AV metadata: %s\n", chd_error_string(err));
- goto cleanup;
- }
+ /* begin compressing */
+ err = chd_compress_begin(chd);
+ if (err != CHDERR_NONE)
+ goto cleanup;
- /* begin compressing */
- err = chd_compress_begin(chd);
- if (err != CHDERR_NONE)
- goto cleanup;
+ /* loop over source hunks until we run out */
+ for (framenum = 0; framenum < numframes; framenum++)
+ {
+ int effframe = firstframe + framenum;
+ UINT32 first_sample;
- /* loop over source hunks until we run out */
- for (framenum = 0; framenum < numframes; framenum++)
- {
- int effframe = firstframe + framenum;
- UINT32 first_sample;
+ /* progress */
+ progress(framenum == 0, "Compressing hunk %d/%d... (ratio=%d%%) \r", framenum, header->totalhunks, (int)(100.0 * ratio));
- /* progress */
- progress(framenum == 0, "Compressing hunk %d/%d... (ratio=%d%%) \r", framenum, header->totalhunks, (int)(100.0 * ratio));
+ /* compute the number of samples in this frame */
+ first_sample = ((UINT64)rate * (UINT64)effframe * (UINT64)1000000 + fps_times_1million - 1) / (UINT64)fps_times_1million;
+ avconfig.samples = ((UINT64)rate * (UINT64)(effframe + 1) * (UINT64)1000000 + fps_times_1million - 1) / (UINT64)fps_times_1million - first_sample;
- /* compute the number of samples in this frame */
- first_sample = ((UINT64)rate * (UINT64)effframe * (UINT64)1000000 + fps_times_1million - 1) / (UINT64)fps_times_1million;
- avconfig.samples = ((UINT64)rate * (UINT64)(effframe + 1) * (UINT64)1000000 + fps_times_1million - 1) / (UINT64)fps_times_1million - first_sample;
+ /* read the frame into its proper format in the cache */
+ if (IS_FAKE_AVI_FILE(avi))
+ avierr = fake_avi_frame(avi, effframe, first_sample, fullbitmap, interlaced, &avconfig);
+ else
+ avierr = read_avi_frame(avi, effframe, first_sample, fullbitmap, interlaced, &avconfig);
+ if (avierr != AVIERR_NONE)
+ {
+ fprintf(stderr, "Error reading frame %d from AVI file: %s\n", effframe, avi_error_string(avierr));
+ err = CHDERR_COMPRESSION_ERROR;
+ }
- /* read the frame into its proper format in the cache */
- if (IS_FAKE_AVI_FILE(avi))
- avierr = fake_avi_frame(avi, effframe, first_sample, fullbitmap, interlaced, &avconfig);
- else
- avierr = read_avi_frame(avi, effframe, first_sample, fullbitmap, interlaced, &avconfig);
- if (avierr != AVIERR_NONE)
- {
- fprintf(stderr, "Error reading frame %d from AVI file: %s\n", effframe, avi_error_string(avierr));
- err = CHDERR_COMPRESSION_ERROR;
+ /* update metadata for this frame */
+ if (ldframedata != NULL)
+ {
+ /* parse the data and pack it */
+ vbi_metadata vbi;
+ vbi_parse_all(&avconfig.video.pix16(0), avconfig.video.rowpixels(), avconfig.video.width(), 8, &vbi);
+ vbi_metadata_pack(&ldframedata[framenum * VBI_PACKED_BYTES], framenum, &vbi);
+ }
+
+ /* configure the compressor for this frame */
+ chd_codec_config(chd, AV_CODEC_COMPRESS_CONFIG, &avconfig);
+
+ /* append the data */
+ err = chd_compress_hunk(chd, NULL, &ratio);
+ if (err != CHDERR_NONE)
+ goto cleanup;
}
- /* update metadata for this frame */
+ /* write the final metadata */
if (ldframedata != NULL)
{
- /* parse the data and pack it */
- vbi_metadata vbi;
- vbi_parse_all(&avconfig.video->pix16(0), avconfig.video->rowpixels(), avconfig.video->width(), 8, &vbi);
- vbi_metadata_pack(&ldframedata[framenum * VBI_PACKED_BYTES], framenum, &vbi);
+ err = chd_set_metadata(chd, AV_LD_METADATA_TAG, 0, ldframedata, numframes * VBI_PACKED_BYTES, CHD_MDFLAGS_CHECKSUM);
+ if (err != CHDERR_NONE)
+ {
+ fprintf(stderr, "Error adding AVLD metadata: %s\n", chd_error_string(err));
+ goto cleanup;
+ }
}
- /* configure the compressor for this frame */
- chd_codec_config(chd, AV_CODEC_COMPRESS_CONFIG, &avconfig);
-
- /* append the data */
- err = chd_compress_hunk(chd, NULL, &ratio);
- if (err != CHDERR_NONE)
- goto cleanup;
- }
-
- /* write the final metadata */
- if (ldframedata != NULL)
- {
- err = chd_set_metadata(chd, AV_LD_METADATA_TAG, 0, ldframedata, numframes * VBI_PACKED_BYTES, CHD_MDFLAGS_CHECKSUM);
+ /* finish compression */
+ err = chd_compress_finish(chd, TRUE);
if (err != CHDERR_NONE)
- {
- fprintf(stderr, "Error adding AVLD metadata: %s\n", chd_error_string(err));
goto cleanup;
- }
+ else
+ progress(TRUE, "Compression complete ... final ratio = %d%% \n", (int)(100.0 * ratio));
}
- /* finish compression */
- err = chd_compress_finish(chd, TRUE);
- if (err != CHDERR_NONE)
- goto cleanup;
- else
- progress(TRUE, "Compression complete ... final ratio = %d%% \n", (int)(100.0 * ratio));
-
cleanup:
/* close everything down */
if (avi != NULL && !IS_FAKE_AVI_FILE(avi))
@@ -1239,7 +1233,6 @@ cleanup:
for (chnum = 0; chnum < ARRAY_LENGTH(avconfig.audio); chnum++)
if (avconfig.audio[chnum] != NULL)
free(avconfig.audio[chnum]);
- delete fullbitmap;
if (ldframedata != NULL)
free(ldframedata);
if (err != CHDERR_NONE)
@@ -1804,16 +1797,14 @@ cleanup:
static int do_extractav(int argc, char *argv[], int param)
{
int fps, fpsfrac, width, height, interlaced, channels, rate, totalframes;
- av_codec_decompress_config avconfig = { 0 };
+ av_codec_decompress_config avconfig;
const char *inputfile, *outputfile;
UINT32 firstframe, numframes;
- bitmap_t *fullbitmap = NULL;
UINT32 framenum, numsamples;
UINT32 fps_times_1million;
const chd_header *header;
chd_file *chd = NULL;
avi_file *avi = NULL;
- bitmap_t fakebitmap;
avi_movie_info info;
char metadata[256];
avi_error avierr;
@@ -1872,108 +1863,104 @@ static int do_extractav(int argc, char *argv[], int param)
numframes = MIN(totalframes - firstframe, numframes);
/* allocate a video buffer */
- fullbitmap = new(std::nothrow) bitmap_t(width, height, BITMAP_FORMAT_YUY16);
- if (fullbitmap == NULL)
{
- fprintf(stderr, "Out of memory allocating temporary bitmap\n");
- err = CHDERR_OUT_OF_MEMORY;
- goto cleanup;
- }
- avconfig.video = &fakebitmap;
+ bitmap_yuy16 fullbitmap(width, height);
+ avconfig.video.wrap(fullbitmap, fullbitmap.cliprect());
- /* allocate audio buffers */
- avconfig.maxsamples = ((UINT64)rate * 1000000 + fps_times_1million - 1) / fps_times_1million;
- avconfig.actsamples = &numsamples;
- for (chnum = 0; chnum < channels; chnum++)
- {
- avconfig.audio[chnum] = (INT16 *)malloc(avconfig.maxsamples * 2);
- if (avconfig.audio[chnum] == NULL)
+ /* allocate audio buffers */
+ avconfig.maxsamples = ((UINT64)rate * 1000000 + fps_times_1million - 1) / fps_times_1million;
+ avconfig.actsamples = &numsamples;
+ for (chnum = 0; chnum < channels; chnum++)
{
- fprintf(stderr, "Out of memory allocating temporary audio buffer\n");
- err = CHDERR_OUT_OF_MEMORY;
- goto cleanup;
+ avconfig.audio[chnum] = (INT16 *)malloc(avconfig.maxsamples * 2);
+ if (avconfig.audio[chnum] == NULL)
+ {
+ fprintf(stderr, "Out of memory allocating temporary audio buffer\n");
+ err = CHDERR_OUT_OF_MEMORY;
+ goto cleanup;
+ }
}
- }
-
- /* print some of it */
- printf("Use frames: %d-%d\n", firstframe, firstframe + numframes - 1);
- printf("Frame rate: %d.%06d\n", fps_times_1million / 1000000, fps_times_1million % 1000000);
- printf("Frame size: %d x %d %s\n", width, height, interlaced ? "interlaced" : "non-interlaced");
- printf("Audio: %d channels at %d Hz\n", channels, rate);
- printf("Total frames: %d (%02d:%02d:%02d)\n", totalframes,
- (UINT32)((UINT64)totalframes * 1000000 / fps_times_1million / 60 / 60),
- (UINT32)(((UINT64)totalframes * 1000000 / fps_times_1million / 60) % 60),
- (UINT32)(((UINT64)totalframes * 1000000 / fps_times_1million) % 60));
-
- /* build up the movie info */
- info.video_format = FORMAT_YUY2;
- info.video_timescale = fps_times_1million;
- info.video_sampletime = 1000000;
- info.video_width = width;
- info.video_height = height;
- info.video_depth = 16;
- info.audio_format = 0;
- info.audio_timescale = rate;
- info.audio_sampletime = 1;
- info.audio_channels = channels;
- info.audio_samplebits = 16;
- info.audio_samplerate = rate;
- /* create the output file */
- avierr = avi_create(outputfile, &info, &avi);
- if (avierr != AVIERR_NONE)
- {
- fprintf(stderr, "Error opening output file '%s': %s\n", outputfile, avi_error_string(avierr));
- err = CHDERR_CANT_CREATE_FILE;
- goto cleanup;
- }
-
- /* loop over hunks, reading and writing */
- for (framenum = 0; framenum < numframes; framenum++)
- {
- /* progress */
- progress(framenum == 0, "Extracting hunk %d/%d... \r", framenum, numframes);
-
- /* set up the fake bitmap for this frame */
- if (!interlaced)
- avconfig.video->clone_existing(*fullbitmap);
- else
- avconfig.video = new(avconfig.video) bitmap_t(&fullbitmap->pix16(framenum % 2), fullbitmap->width(), fullbitmap->height() / 2, fullbitmap->rowpixels() * 2, fullbitmap->format());
-
- /* configure the decompressor for this frame */
- chd_codec_config(chd, AV_CODEC_DECOMPRESS_CONFIG, &avconfig);
-
- /* read the hunk into the buffers */
- err = chd_read(chd, firstframe + framenum, NULL);
- if (err != CHDERR_NONE)
+ /* print some of it */
+ printf("Use frames: %d-%d\n", firstframe, firstframe + numframes - 1);
+ printf("Frame rate: %d.%06d\n", fps_times_1million / 1000000, fps_times_1million % 1000000);
+ printf("Frame size: %d x %d %s\n", width, height, interlaced ? "interlaced" : "non-interlaced");
+ printf("Audio: %d channels at %d Hz\n", channels, rate);
+ printf("Total frames: %d (%02d:%02d:%02d)\n", totalframes,
+ (UINT32)((UINT64)totalframes * 1000000 / fps_times_1million / 60 / 60),
+ (UINT32)(((UINT64)totalframes * 1000000 / fps_times_1million / 60) % 60),
+ (UINT32)(((UINT64)totalframes * 1000000 / fps_times_1million) % 60));
+
+ /* build up the movie info */
+ info.video_format = FORMAT_YUY2;
+ info.video_timescale = fps_times_1million;
+ info.video_sampletime = 1000000;
+ info.video_width = width;
+ info.video_height = height;
+ info.video_depth = 16;
+ info.audio_format = 0;
+ info.audio_timescale = rate;
+ info.audio_sampletime = 1;
+ info.audio_channels = channels;
+ info.audio_samplebits = 16;
+ info.audio_samplerate = rate;
+
+ /* create the output file */
+ avierr = avi_create(outputfile, &info, &avi);
+ if (avierr != AVIERR_NONE)
{
- fprintf(stderr, "Error reading hunk %d from CHD file: %s\n", firstframe + framenum, chd_error_string(err));
+ fprintf(stderr, "Error opening output file '%s': %s\n", outputfile, avi_error_string(avierr));
+ err = CHDERR_CANT_CREATE_FILE;
goto cleanup;
}
- /* write audio */
- for (chnum = 0; chnum < channels; chnum++)
+ /* loop over hunks, reading and writing */
+ for (framenum = 0; framenum < numframes; framenum++)
{
- avierr = avi_append_sound_samples(avi, chnum, avconfig.audio[chnum], numsamples, 0);
- if (avierr != AVIERR_NONE)
+ /* progress */
+ progress(framenum == 0, "Extracting hunk %d/%d... \r", framenum, numframes);
+
+ /* set up the fake bitmap for this frame */
+ if (!interlaced)
+ avconfig.video.wrap(fullbitmap, fullbitmap.cliprect());
+ else
+ avconfig.video.wrap(&fullbitmap.pix16(framenum % 2), fullbitmap.width(), fullbitmap.height() / 2, fullbitmap.rowpixels() * 2);
+
+ /* configure the decompressor for this frame */
+ chd_codec_config(chd, AV_CODEC_DECOMPRESS_CONFIG, &avconfig);
+
+ /* read the hunk into the buffers */
+ err = chd_read(chd, firstframe + framenum, NULL);
+ if (err != CHDERR_NONE)
{
- fprintf(stderr, "Error writing samples for hunk %d to AVI file: %s\n", firstframe + framenum, avi_error_string(avierr));
+ fprintf(stderr, "Error reading hunk %d from CHD file: %s\n", firstframe + framenum, chd_error_string(err));
goto cleanup;
}
- }
- /* write video */
- if (!interlaced || (firstframe + framenum) % 2 == 1)
- {
- avierr = avi_append_video_frame_yuy16(avi, *fullbitmap);
- if (avierr != AVIERR_NONE)
+ /* write audio */
+ for (chnum = 0; chnum < channels; chnum++)
{
- fprintf(stderr, "Error writing video for hunk %d to AVI file: %s\n", firstframe + framenum, avi_error_string(avierr));
- goto cleanup;
+ avierr = avi_append_sound_samples(avi, chnum, avconfig.audio[chnum], numsamples, 0);
+ if (avierr != AVIERR_NONE)
+ {
+ fprintf(stderr, "Error writing samples for hunk %d to AVI file: %s\n", firstframe + framenum, avi_error_string(avierr));
+ goto cleanup;
+ }
+ }
+
+ /* write video */
+ if (!interlaced || (firstframe + framenum) % 2 == 1)
+ {
+ avierr = avi_append_video_frame(avi, fullbitmap);
+ if (avierr != AVIERR_NONE)
+ {
+ fprintf(stderr, "Error writing video for hunk %d to AVI file: %s\n", firstframe + framenum, avi_error_string(avierr));
+ goto cleanup;
+ }
}
}
+ progress(TRUE, "Extraction complete! \n");
}
- progress(TRUE, "Extraction complete! \n");
cleanup:
/* clean up our mess */
@@ -1982,7 +1969,6 @@ cleanup:
for (chnum = 0; chnum < ARRAY_LENGTH(avconfig.audio); chnum++)
if (avconfig.audio[chnum] != NULL)
free(avconfig.audio[chnum]);
- delete fullbitmap;
if (chd != NULL)
chd_close(chd);
if (err != CHDERR_NONE)
@@ -2159,13 +2145,12 @@ cleanup:
static int do_fixavdata(int argc, char *argv[], int param)
{
int fps, fpsfrac, width, height, interlaced, channels, rate;
- av_codec_decompress_config avconfig = { 0 };
- bitmap_t *fullbitmap = NULL;
+ av_codec_decompress_config avconfig;
const char *inputfile;
UINT8 *vbidata = NULL;
int writeable = FALSE;
chd_file *chd = NULL;
- bitmap_t fakebitmap;
+ bitmap_yuy16 fakebitmap;
char metadata[256];
chd_header header;
UINT32 actlength;
@@ -2218,158 +2203,153 @@ static int do_fixavdata(int argc, char *argv[], int param)
}
/* allocate a video buffer */
- fullbitmap = new(std::nothrow) bitmap_t(width, height, BITMAP_FORMAT_YUY16);
- if (fullbitmap == NULL)
- {
- fprintf(stderr, "Out of memory allocating temporary bitmap\n");
- err = CHDERR_OUT_OF_MEMORY;
- goto cleanup;
- }
- avconfig.video = &fakebitmap;
-
- /* allocate memory for VBI data */
- vbidata = (UINT8 *)malloc(header.totalhunks * VBI_PACKED_BYTES);
- if (vbidata == NULL)
{
- fprintf(stderr, "Out of memory allocating VBI data\n");
- err = CHDERR_OUT_OF_MEMORY;
- goto cleanup;
- }
-
- /* read the metadata */
- err = chd_get_metadata(chd, AV_LD_METADATA_TAG, 0, vbidata, header.totalhunks * VBI_PACKED_BYTES, &actlength, NULL, NULL);
- if (err != CHDERR_NONE)
- {
- fprintf(stderr, "Error getting VBI metadata: %s\n", chd_error_string(err));
- memset(vbidata, 0, header.totalhunks * VBI_PACKED_BYTES);
- fixes++;
- }
- if (actlength != header.totalhunks * VBI_PACKED_BYTES)
- {
- fprintf(stderr, "VBI metadata incorrect size\n");
- memset(vbidata, 0, header.totalhunks * VBI_PACKED_BYTES);
- fixes++;
- }
-
- /* loop over hunks, reading */
- for (framenum = 0; framenum < header.totalhunks; framenum++)
- {
- vbi_metadata origvbi;
- vbi_metadata vbi;
- UINT32 vbiframe;
-
- /* progress */
- progress(framenum == 0, "Processing hunk %d/%d... \r", framenum, header.totalhunks);
-
- /* set up the fake bitmap for this frame */
- avconfig.video->clone_existing(*fullbitmap);
+ bitmap_yuy16 fullbitmap(width, height);
+ avconfig.video.wrap(fullbitmap, fullbitmap.cliprect());
- /* configure the decompressor for this frame */
- chd_codec_config(chd, AV_CODEC_DECOMPRESS_CONFIG, &avconfig);
+ /* allocate memory for VBI data */
+ vbidata = (UINT8 *)malloc(header.totalhunks * VBI_PACKED_BYTES);
+ if (vbidata == NULL)
+ {
+ fprintf(stderr, "Out of memory allocating VBI data\n");
+ err = CHDERR_OUT_OF_MEMORY;
+ goto cleanup;
+ }
- /* read the hunk into the buffers */
- err = chd_read(chd, framenum, NULL);
+ /* read the metadata */
+ err = chd_get_metadata(chd, AV_LD_METADATA_TAG, 0, vbidata, header.totalhunks * VBI_PACKED_BYTES, &actlength, NULL, NULL);
if (err != CHDERR_NONE)
{
- fprintf(stderr, "Error reading hunk %d from CHD file: %s\n", framenum, chd_error_string(err));
- goto cleanup;
+ fprintf(stderr, "Error getting VBI metadata: %s\n", chd_error_string(err));
+ memset(vbidata, 0, header.totalhunks * VBI_PACKED_BYTES);
+ fixes++;
+ }
+ if (actlength != header.totalhunks * VBI_PACKED_BYTES)
+ {
+ fprintf(stderr, "VBI metadata incorrect size\n");
+ memset(vbidata, 0, header.totalhunks * VBI_PACKED_BYTES);
+ fixes++;
}
- /* unpack the current data for this frame */
- vbi_metadata_unpack(&origvbi, &vbiframe, &vbidata[framenum * VBI_PACKED_BYTES]);
+ /* loop over hunks, reading */
+ for (framenum = 0; framenum < header.totalhunks; framenum++)
+ {
+ vbi_metadata origvbi;
+ vbi_metadata vbi;
+ UINT32 vbiframe;
- /* parse the video data */
- vbi_parse_all(&avconfig.video->pix16(0), avconfig.video->rowpixels(), avconfig.video->width(), 8, &vbi);
+ /* progress */
+ progress(framenum == 0, "Processing hunk %d/%d... \r", framenum, header.totalhunks);
- /* verify the data */
- if (vbiframe != 0 || origvbi.white != 0 || origvbi.line16 != 0 || origvbi.line17 != 0 || origvbi.line18 != 0 || origvbi.line1718 != 0)
- {
- int errors = 0;
+ /* set up the fake bitmap for this frame */
+ avconfig.video.wrap(fullbitmap, fullbitmap.cliprect());
- if (vbiframe != framenum)
- {
- fprintf(stderr, "%d:Frame mismatch in VBI data (%d, should be %d)\n", framenum, vbiframe, framenum);
- errors++;
- }
- if (vbi.white != origvbi.white)
- {
- fprintf(stderr, "%d:White flag mismatch in VBI data (%d, should be %d)\n", framenum, origvbi.white, vbi.white);
- errors++;
- }
- if (vbi.line16 != origvbi.line16)
- {
- fprintf(stderr, "%d:Line 16 mismatch in VBI data (%06X, should be %06X)\n", framenum, origvbi.line16, vbi.line16);
- errors++;
- }
- if (vbi.line17 != origvbi.line17)
- {
- fprintf(stderr, "%d:Line 17 mismatch in VBI data (%06X, should be %06X)\n", framenum, origvbi.line17, vbi.line17);
- errors++;
- }
- if (vbi.line18 != origvbi.line18)
+ /* configure the decompressor for this frame */
+ chd_codec_config(chd, AV_CODEC_DECOMPRESS_CONFIG, &avconfig);
+
+ /* read the hunk into the buffers */
+ err = chd_read(chd, framenum, NULL);
+ if (err != CHDERR_NONE)
{
- fprintf(stderr, "%d:Line 18 mismatch in VBI data (%06X, should be %06X)\n", framenum, origvbi.line18, vbi.line18);
- errors++;
+ fprintf(stderr, "Error reading hunk %d from CHD file: %s\n", framenum, chd_error_string(err));
+ goto cleanup;
}
- if (vbi.line1718 != origvbi.line1718)
+
+ /* unpack the current data for this frame */
+ vbi_metadata_unpack(&origvbi, &vbiframe, &vbidata[framenum * VBI_PACKED_BYTES]);
+
+ /* parse the video data */
+ vbi_parse_all(&avconfig.video.pix16(0), avconfig.video.rowpixels(), avconfig.video.width(), 8, &vbi);
+
+ /* verify the data */
+ if (vbiframe != 0 || origvbi.white != 0 || origvbi.line16 != 0 || origvbi.line17 != 0 || origvbi.line18 != 0 || origvbi.line1718 != 0)
{
- fprintf(stderr, "%d:Line 17/18 mismatch in VBI data (%06X, should be %06X)\n", framenum, origvbi.line1718, vbi.line1718);
- errors++;
+ int errors = 0;
+
+ if (vbiframe != framenum)
+ {
+ fprintf(stderr, "%d:Frame mismatch in VBI data (%d, should be %d)\n", framenum, vbiframe, framenum);
+ errors++;
+ }
+ if (vbi.white != origvbi.white)
+ {
+ fprintf(stderr, "%d:White flag mismatch in VBI data (%d, should be %d)\n", framenum, origvbi.white, vbi.white);
+ errors++;
+ }
+ if (vbi.line16 != origvbi.line16)
+ {
+ fprintf(stderr, "%d:Line 16 mismatch in VBI data (%06X, should be %06X)\n", framenum, origvbi.line16, vbi.line16);
+ errors++;
+ }
+ if (vbi.line17 != origvbi.line17)
+ {
+ fprintf(stderr, "%d:Line 17 mismatch in VBI data (%06X, should be %06X)\n", framenum, origvbi.line17, vbi.line17);
+ errors++;
+ }
+ if (vbi.line18 != origvbi.line18)
+ {
+ fprintf(stderr, "%d:Line 18 mismatch in VBI data (%06X, should be %06X)\n", framenum, origvbi.line18, vbi.line18);
+ errors++;
+ }
+ if (vbi.line1718 != origvbi.line1718)
+ {
+ fprintf(stderr, "%d:Line 17/18 mismatch in VBI data (%06X, should be %06X)\n", framenum, origvbi.line1718, vbi.line1718);
+ errors++;
+ }
+ fixes += errors;
+ fixframes += (errors != 0);
}
- fixes += errors;
- fixframes += (errors != 0);
+
+ /* pack the new data */
+ vbi_metadata_pack(&vbidata[framenum * VBI_PACKED_BYTES], framenum, &vbi);
}
+ progress(TRUE, "Processing complete! \n");
- /* pack the new data */
- vbi_metadata_pack(&vbidata[framenum * VBI_PACKED_BYTES], framenum, &vbi);
- }
- progress(TRUE, "Processing complete! \n");
+ /* print final results */
+ if (fixes == 0)
+ printf("\nNo fixes required\n");
+ else
+ printf("\nFound %d errors on %d frames\n", fixes, fixframes);
- /* print final results */
- if (fixes == 0)
- printf("\nNo fixes required\n");
- else
- printf("\nFound %d errors on %d frames\n", fixes, fixframes);
+ /* close the drive */
+ chd_close(chd);
+ chd = NULL;
- /* close the drive */
- chd_close(chd);
- chd = NULL;
+ /* apply fixes */
+ if (fixes > 0)
+ {
+ /* mark the CHD writeable */
+ header.flags |= CHDFLAGS_IS_WRITEABLE;
+ err = chd_set_header(inputfile, &header);
+ if (err != CHDERR_NONE)
+ fprintf(stderr, "Error writing new header: %s\n", chd_error_string(err));
+ header.flags &= ~CHDFLAGS_IS_WRITEABLE;
+ writeable = TRUE;
- /* apply fixes */
- if (fixes > 0)
- {
- /* mark the CHD writeable */
- header.flags |= CHDFLAGS_IS_WRITEABLE;
- err = chd_set_header(inputfile, &header);
- if (err != CHDERR_NONE)
- fprintf(stderr, "Error writing new header: %s\n", chd_error_string(err));
- header.flags &= ~CHDFLAGS_IS_WRITEABLE;
- writeable = TRUE;
+ /* open the file */
+ err = chd_open(inputfile, CHD_OPEN_READWRITE, NULL, &chd);
+ if (err != CHDERR_NONE)
+ {
+ fprintf(stderr, "Error opening CHD file '%s': %s\n", inputfile, chd_error_string(err));
+ goto cleanup;
+ }
- /* open the file */
- err = chd_open(inputfile, CHD_OPEN_READWRITE, NULL, &chd);
- if (err != CHDERR_NONE)
- {
- fprintf(stderr, "Error opening CHD file '%s': %s\n", inputfile, chd_error_string(err));
- goto cleanup;
- }
+ /* write new metadata */
+ err = chd_set_metadata(chd, AV_LD_METADATA_TAG, 0, vbidata, header.totalhunks * VBI_PACKED_BYTES, CHD_MDFLAGS_CHECKSUM);
+ if (err != CHDERR_NONE)
+ {
+ fprintf(stderr, "Error adding AVLD metadata: %s\n", chd_error_string(err));
+ goto cleanup;
+ }
+ else
+ printf("Updated metadata written successfully\n");
- /* write new metadata */
- err = chd_set_metadata(chd, AV_LD_METADATA_TAG, 0, vbidata, header.totalhunks * VBI_PACKED_BYTES, CHD_MDFLAGS_CHECKSUM);
- if (err != CHDERR_NONE)
- {
- fprintf(stderr, "Error adding AVLD metadata: %s\n", chd_error_string(err));
- goto cleanup;
+ /* allow cleanup code to close the file and revert the header */
}
- else
- printf("Updated metadata written successfully\n");
-
- /* allow cleanup code to close the file and revert the header */
}
cleanup:
/* clean up our mess */
- delete fullbitmap;
if (vbidata != NULL)
free(vbidata);
if (chd != NULL)
diff --git a/src/tools/ldresample.c b/src/tools/ldresample.c
index 58f019561d7..10e04e1ca83 100644
--- a/src/tools/ldresample.c
+++ b/src/tools/ldresample.c
@@ -82,7 +82,7 @@ struct _movie_info
int samplerate;
int channels;
int interlaced;
- bitmap_t * bitmap;
+ bitmap_yuy16 *bitmap;
INT16 * lsound;
INT16 * rsound;
UINT32 samples;
@@ -151,7 +151,7 @@ INLINE UINT32 sample_number_to_field(const movie_info *info, UINT32 samplenum, U
static int chd_allocate_buffers(movie_info *info)
{
/* allocate a bitmap */
- info->bitmap = new(std::nothrow) bitmap_t(info->width, info->height, BITMAP_FORMAT_YUY16);
+ info->bitmap = new(std::nothrow) bitmap_yuy16(info->width, info->height);
if (info->bitmap == NULL)
{
fprintf(stderr, "Out of memory creating %dx%d bitmap\n", info->width, info->height);
@@ -177,8 +177,7 @@ static int chd_allocate_buffers(movie_info *info)
static void chd_free_buffers(movie_info *info)
{
- if (info->bitmap != NULL)
- free(info->bitmap);
+ delete info->bitmap;
if (info->lsound != NULL)
free(info->lsound);
if (info->rsound != NULL)
@@ -294,11 +293,11 @@ static chd_file *create_chd(const char *filename, chd_file *source, const movie_
static int read_chd(chd_file *file, UINT32 field, movie_info *info, UINT32 soundoffs)
{
- av_codec_decompress_config avconfig = { 0 };
+ av_codec_decompress_config avconfig;
chd_error chderr;
/* configure the codec */
- avconfig.video = info->bitmap;
+ avconfig.video.wrap(*info->bitmap, info->bitmap->cliprect());
avconfig.maxsamples = 48000;
avconfig.actsamples = &info->samples;
avconfig.audio[0] = info->lsound + soundoffs;
@@ -322,11 +321,11 @@ static int read_chd(chd_file *file, UINT32 field, movie_info *info, UINT32 sound
static int write_chd(chd_file *file, UINT32 field, movie_info *info)
{
- av_codec_compress_config avconfig = { 0 };
+ av_codec_compress_config avconfig;
chd_error chderr;
/* configure the codec */
- avconfig.video = info->bitmap;
+ avconfig.video.wrap(*info->bitmap, info->bitmap->cliprect());
avconfig.channels = 2;
avconfig.samples = info->samples;
avconfig.audio[0] = info->lsound;
diff --git a/src/tools/ldverify.c b/src/tools/ldverify.c
index 081e8a8a1a6..45fe9f4dbf5 100644
--- a/src/tools/ldverify.c
+++ b/src/tools/ldverify.c
@@ -159,7 +159,7 @@ static void *open_avi(const char *filename, movie_info *info)
read_avi - read a frame from an AVI file
-------------------------------------------------*/
-static int read_avi(void *file, int frame, bitmap_t &bitmap, INT16 *lsound, INT16 *rsound, int *samples)
+static int read_avi(void *file, int frame, bitmap_yuy16 &bitmap, INT16 *lsound, INT16 *rsound, int *samples)
{
const avi_movie_info *aviinfo = avi_get_movie_info((avi_file *)file);
UINT32 firstsample = ((UINT64)aviinfo->audio_samplerate * (UINT64)frame * (UINT64)aviinfo->video_sampletime + aviinfo->video_timescale - 1) / (UINT64)aviinfo->video_timescale;
@@ -167,7 +167,7 @@ static int read_avi(void *file, int frame, bitmap_t &bitmap, INT16 *lsound, INT1
avi_error avierr;
/* read the frame */
- avierr = avi_read_video_frame_yuy16((avi_file *)file, frame, bitmap);
+ avierr = avi_read_video_frame((avi_file *)file, frame, bitmap);
if (avierr != AVIERR_NONE)
return FALSE;
@@ -258,11 +258,11 @@ static void *open_chd(const char *filename, movie_info *info)
read_chd - read a frame from a CHD file
-------------------------------------------------*/
-static int read_chd(void *file, int frame, bitmap_t &bitmap, INT16 *lsound, INT16 *rsound, int *samples)
+static int read_chd(void *file, int frame, bitmap_yuy16 &bitmap, INT16 *lsound, INT16 *rsound, int *samples)
{
- av_codec_decompress_config avconfig = { 0 };
+ av_codec_decompress_config avconfig;
int interlace_factor = chdinterlaced ? 2 : 1;
- bitmap_t fakebitmap;
+ bitmap_yuy16 fakebitmap;
UINT32 numsamples;
chd_error chderr;
int fieldnum;
@@ -272,7 +272,7 @@ static int read_chd(void *file, int frame, bitmap_t &bitmap, INT16 *lsound, INT1
for (fieldnum = 0; fieldnum < interlace_factor; fieldnum++)
{
/* make a fake bitmap for this field */
- avconfig.video = new(&fakebitmap) bitmap_t(&bitmap.pix16(fieldnum), bitmap.width(), bitmap.height() / interlace_factor, bitmap.rowpixels() * interlace_factor, bitmap.format());
+ avconfig.video.wrap(&bitmap.pix16(fieldnum), bitmap.width(), bitmap.height() / interlace_factor, bitmap.rowpixels() * interlace_factor);
/* configure the codec */
avconfig.maxsamples = 48000;
@@ -342,7 +342,7 @@ static void init_video(video_info *video)
verify_video - verify video frame
-------------------------------------------------*/
-static void verify_video(video_info *video, int frame, bitmap_t &bitmap)
+static void verify_video(video_info *video, int frame, bitmap_yuy16 &bitmap)
{
const int fields_per_frame = 2;
int fieldnum;
@@ -613,7 +613,7 @@ static void verify_video(video_info *video, int frame, bitmap_t &bitmap)
verify_video_final - final verification
-------------------------------------------------*/
-static void verify_video_final(video_info *video, int frame, bitmap_t &bitmap)
+static void verify_video_final(video_info *video, int frame, bitmap_yuy16 &bitmap)
{
int fields_per_frame = (bitmap.height() >= 288) ? 2 : 1;
int field = frame * fields_per_frame;
@@ -741,108 +741,108 @@ static int usage(void)
int main(int argc, char *argv[])
{
- movie_info info = { 0 };
- INT16 *lsound, *rsound;
- const char *srcfile;
- bitmap_t *bitmap;
- int srcfilelen;
- int samples = 0;
- void *file;
- int isavi;
- int frame;
- audio_info audio;
- video_info video;
-
- /* init globals */
- init_audio(&audio);
- init_video(&video);
-
- /* verify arguments */
- if (argc < 2)
- return usage();
- srcfile = argv[1];
-
- /* check extension of file */
- srcfilelen = strlen(srcfile);
- if (srcfilelen < 4)
- return usage();
- if (tolower((UINT8)srcfile[srcfilelen-3]) == 'a' && tolower((UINT8)srcfile[srcfilelen-2]) == 'v' && tolower((UINT8)srcfile[srcfilelen-1]) == 'i')
- isavi = TRUE;
- else if (tolower((UINT8)srcfile[srcfilelen-3]) == 'c' && tolower((UINT8)srcfile[srcfilelen-2]) == 'h' && tolower((UINT8)srcfile[srcfilelen-1]) == 'd')
- isavi = FALSE;
- else
- return usage();
-
- /* open the file */
- printf("Processing file: %s\n", srcfile);
- file = isavi ? open_avi(srcfile, &info) : open_chd(srcfile, &info);
- if (file == NULL)
+ try
{
- fprintf(stderr, "Unable to open file '%s'\n", srcfile);
- return 1;
- }
+ movie_info info = { 0 };
+ INT16 *lsound, *rsound;
+ const char *srcfile;
+ bitmap_yuy16 bitmap;
+ int srcfilelen;
+ int samples = 0;
+ void *file;
+ int isavi;
+ int frame;
+ audio_info audio;
+ video_info video;
+
+ /* init globals */
+ init_audio(&audio);
+ init_video(&video);
+
+ /* verify arguments */
+ if (argc < 2)
+ return usage();
+ srcfile = argv[1];
+
+ /* check extension of file */
+ srcfilelen = strlen(srcfile);
+ if (srcfilelen < 4)
+ return usage();
+ if (tolower((UINT8)srcfile[srcfilelen-3]) == 'a' && tolower((UINT8)srcfile[srcfilelen-2]) == 'v' && tolower((UINT8)srcfile[srcfilelen-1]) == 'i')
+ isavi = TRUE;
+ else if (tolower((UINT8)srcfile[srcfilelen-3]) == 'c' && tolower((UINT8)srcfile[srcfilelen-2]) == 'h' && tolower((UINT8)srcfile[srcfilelen-1]) == 'd')
+ isavi = FALSE;
+ else
+ return usage();
+
+ /* open the file */
+ printf("Processing file: %s\n", srcfile);
+ file = isavi ? open_avi(srcfile, &info) : open_chd(srcfile, &info);
+ if (file == NULL)
+ {
+ fprintf(stderr, "Unable to open file '%s'\n", srcfile);
+ return 1;
+ }
- /* comment on the video dimensions */
- printf("Video dimensions: %dx%d\n", info.width, info.height);
- if (info.width != 720)
- printf("WARNING: Unexpected video width (should be 720)\n");
- if (info.height != 524)
- printf("WARNING: Unexpected video height (should be 262 or 524)\n");
-
- /* comment on the video frame rate */
- printf("Video frame rate: %.2fHz\n", info.framerate);
- if ((int)(info.framerate * 100.0 + 0.5) != 2997)
- printf("WARNING: Unexpected frame rate (should be 29.97Hz)\n");
-
- /* comment on the sample rate */
- printf("Sample rate: %dHz\n", info.samplerate);
- if (info.samplerate != 48000)
- printf("WARNING: Unexpected sampele rate (should be 48000Hz)\n");
-
- /* allocate a bitmap */
- bitmap = new(std::nothrow) bitmap_t(info.width, info.height, BITMAP_FORMAT_YUY16);
- if (bitmap == NULL)
- {
- isavi ? close_avi(file) : close_chd(file);
- fprintf(stderr, "Out of memory creating %dx%d bitmap\n", info.width, info.height);
- return 1;
- }
+ /* comment on the video dimensions */
+ printf("Video dimensions: %dx%d\n", info.width, info.height);
+ if (info.width != 720)
+ printf("WARNING: Unexpected video width (should be 720)\n");
+ if (info.height != 524)
+ printf("WARNING: Unexpected video height (should be 262 or 524)\n");
+
+ /* comment on the video frame rate */
+ printf("Video frame rate: %.2fHz\n", info.framerate);
+ if ((int)(info.framerate * 100.0 + 0.5) != 2997)
+ printf("WARNING: Unexpected frame rate (should be 29.97Hz)\n");
+
+ /* comment on the sample rate */
+ printf("Sample rate: %dHz\n", info.samplerate);
+ if (info.samplerate != 48000)
+ printf("WARNING: Unexpected sampele rate (should be 48000Hz)\n");
+
+ /* allocate a bitmap */
+ bitmap.allocate(info.width, info.height);
+
+ /* allocate sound buffers */
+ lsound = (INT16 *)malloc(info.samplerate * sizeof(*lsound));
+ rsound = (INT16 *)malloc(info.samplerate * sizeof(*rsound));
+ if (lsound == NULL || rsound == NULL)
+ {
+ isavi ? close_avi(file) : close_chd(file);
+ if (rsound != NULL)
+ free(rsound);
+ if (lsound != NULL)
+ free(lsound);
+ fprintf(stderr, "Out of memory allocating sound buffers of %d bytes\n", (INT32)(info.samplerate * sizeof(*rsound)));
+ return 1;
+ }
- /* allocate sound buffers */
- lsound = (INT16 *)malloc(info.samplerate * sizeof(*lsound));
- rsound = (INT16 *)malloc(info.samplerate * sizeof(*rsound));
- if (lsound == NULL || rsound == NULL)
- {
+ /* loop over frames */
+ frame = 0;
+ while (isavi ? read_avi(file, frame, bitmap, lsound, rsound, &samples) : read_chd(file, frame, bitmap, lsound, rsound, &samples))
+ {
+ verify_video(&video, frame, bitmap);
+ verify_audio(&audio, lsound, rsound, samples);
+ frame++;
+ }
+
+ /* close the files */
isavi ? close_avi(file) : close_chd(file);
- delete bitmap;
- if (rsound != NULL)
- free(rsound);
- if (lsound != NULL)
- free(lsound);
- fprintf(stderr, "Out of memory allocating sound buffers of %d bytes\n", (INT32)(info.samplerate * sizeof(*rsound)));
- return 1;
- }
- /* loop over frames */
- frame = 0;
- while (isavi ? read_avi(file, frame, *bitmap, lsound, rsound, &samples) : read_chd(file, frame, *bitmap, lsound, rsound, &samples))
+ /* final output */
+ verify_video_final(&video, frame, bitmap);
+ verify_audio_final(&audio);
+
+ /* free memory */
+ free(lsound);
+ free(rsound);
+ }
+ catch (std::bad_alloc &)
{
- verify_video(&video, frame, *bitmap);
- verify_audio(&audio, lsound, rsound, samples);
- frame++;
+ fprintf(stderr, "Out of memory allocating memory\n");
+ return 1;
}
- /* close the files */
- isavi ? close_avi(file) : close_chd(file);
-
- /* final output */
- verify_video_final(&video, frame, *bitmap);
- verify_audio_final(&audio);
-
- /* free memory */
- delete bitmap;
- free(lsound);
- free(rsound);
-
return 0;
}
diff --git a/src/tools/regrep.c b/src/tools/regrep.c
index f0995d47c88..99be3a84f88 100644
--- a/src/tools/regrep.c
+++ b/src/tools/regrep.c
@@ -767,15 +767,13 @@ static void output_report(astring &dirname, astring &tempheader, astring &tempfo
static int compare_screenshots(summary_file *curfile)
{
- bitmap_t *bitmaps[MAX_COMPARES] = { NULL };
+ bitmap_argb32 bitmaps[MAX_COMPARES];
int unique[MAX_COMPARES];
int numunique = 0;
int listnum;
/* iterate over all files and load their bitmaps */
for (listnum = 0; listnum < list_count; listnum++)
- {
- bitmaps[listnum] = NULL;
if (curfile->status[listnum] == STATUS_SUCCESS)
{
astring fullname;
@@ -801,42 +799,39 @@ static int compare_screenshots(summary_file *curfile)
/* if that worked, load the file */
if (filerr == FILERR_NONE)
{
- png_read_bitmap(file, &bitmaps[listnum]);
+ png_read_bitmap(file, bitmaps[listnum]);
core_fclose(file);
}
}
- }
/* now find all the different bitmap types */
for (listnum = 0; listnum < list_count; listnum++)
{
curfile->matchbitmap[listnum] = 0xff;
- if (bitmaps[listnum] != NULL)
+ if (bitmaps[listnum].valid())
{
- bitmap_t *this_bitmap = bitmaps[listnum];
- int compnum;
+ bitmap_argb32 &this_bitmap = bitmaps[listnum];
/* compare against all unique bitmaps */
+ int compnum;
for (compnum = 0; compnum < numunique; compnum++)
{
- bitmap_t *base_bitmap = bitmaps[unique[compnum]];
- int bitmaps_differ;
- int x, y;
-
/* if the sizes are different, we differ; otherwise start off assuming we are the same */
- bitmaps_differ = (this_bitmap->width() != base_bitmap->width() || this_bitmap->height() != base_bitmap->height());
+ bitmap_argb32 &base_bitmap = bitmaps[unique[compnum]];
+ bool bitmaps_differ = (this_bitmap.width() != base_bitmap.width() || this_bitmap.height() != base_bitmap.height());
/* compare scanline by scanline */
- for (y = 0; y < this_bitmap->height() && !bitmaps_differ; y++)
+ for (int y = 0; y < this_bitmap.height() && !bitmaps_differ; y++)
{
- UINT32 *base = &base_bitmap->pix32(y);
- UINT32 *curr = &this_bitmap->pix32(y);
+ UINT32 *base = &base_bitmap.pix32(y);
+ UINT32 *curr = &this_bitmap.pix32(y);
/* scan the scanline */
- for (x = 0; x < this_bitmap->width(); x++)
+ int x;
+ for (x = 0; x < this_bitmap.width(); x++)
if (*base++ != *curr++)
break;
- bitmaps_differ = (x != this_bitmap->width());
+ bitmaps_differ = (x != this_bitmap.width());
}
/* if we matched, remember which listnum index we matched, and stop */
@@ -861,10 +856,6 @@ static int compare_screenshots(summary_file *curfile)
}
}
- /* free the bitmaps */
- for (listnum = 0; listnum < list_count; listnum++)
- delete bitmaps[listnum];
-
/* if all screenshots matched, we're good */
if (numunique == 1)
return BUCKET_GOOD;
@@ -886,11 +877,11 @@ static int compare_screenshots(summary_file *curfile)
static int generate_png_diff(const summary_file *curfile, astring &destdir, const char *destname)
{
- bitmap_t *bitmaps[MAX_COMPARES] = { NULL };
+ bitmap_argb32 bitmaps[MAX_COMPARES];
astring srcimgname;
astring dstfilename;
astring tempname;
- bitmap_t *finalbitmap = NULL;
+ bitmap_argb32 finalbitmap;
int width, height, maxwidth;
int bitmapcount = 0;
int listnum, bmnum;
@@ -916,7 +907,7 @@ static int generate_png_diff(const summary_file *curfile, astring &destdir, cons
goto error;
/* load the source image */
- pngerr = png_read_bitmap(file, &bitmaps[bitmapcount++]);
+ pngerr = png_read_bitmap(file, bitmaps[bitmapcount++]);
core_fclose(file);
if (pngerr != PNGERR_NONE)
goto error;
@@ -928,67 +919,65 @@ static int generate_png_diff(const summary_file *curfile, astring &destdir, cons
/* determine the size of the final bitmap */
height = width = 0;
- maxwidth = bitmaps[0]->width();
+ maxwidth = bitmaps[0].width();
for (bmnum = 1; bmnum < bitmapcount; bmnum++)
{
int curwidth;
/* determine the maximal width */
- maxwidth = MAX(maxwidth, bitmaps[bmnum]->width());
- curwidth = bitmaps[0]->width() + BITMAP_SPACE + maxwidth + BITMAP_SPACE + maxwidth;
+ maxwidth = MAX(maxwidth, bitmaps[bmnum].width());
+ curwidth = bitmaps[0].width() + BITMAP_SPACE + maxwidth + BITMAP_SPACE + maxwidth;
width = MAX(width, curwidth);
/* add to the height */
- height += MAX(bitmaps[0]->height(), bitmaps[bmnum]->height());
+ height += MAX(bitmaps[0].height(), bitmaps[bmnum].height());
if (bmnum != 1)
height += BITMAP_SPACE;
}
/* allocate the final bitmap */
- finalbitmap = new(std::nothrow) bitmap_t(width, height, BITMAP_FORMAT_ARGB32);
- if (finalbitmap == NULL)
- goto error;
+ finalbitmap.allocate(width, height);
/* now copy and compare each set of bitmaps */
starty = 0;
for (bmnum = 1; bmnum < bitmapcount; bmnum++)
{
- bitmap_t *bitmap1 = bitmaps[0];
- bitmap_t *bitmap2 = bitmaps[bmnum];
- int curheight = MAX(bitmap1->height(), bitmap2->height());
+ bitmap_argb32 &bitmap1 = bitmaps[0];
+ bitmap_argb32 &bitmap2 = bitmaps[bmnum];
+ int curheight = MAX(bitmap1.height(), bitmap2.height());
int x, y;
/* iterate over rows in these bitmaps */
for (y = 0; y < curheight; y++)
{
- UINT32 *src1 = (y < bitmap1->height()) ? &bitmap1->pix32(y) : NULL;
- UINT32 *src2 = (y < bitmap2->height()) ? &bitmap2->pix32(y) : NULL;
- UINT32 *dst1 = &finalbitmap->pix32(starty + y, 0);
- UINT32 *dst2 = &finalbitmap->pix32(starty + y, bitmap1->width() + BITMAP_SPACE);
- UINT32 *dstdiff = &finalbitmap->pix32(starty + y, bitmap1->width() + BITMAP_SPACE + maxwidth + BITMAP_SPACE);
+ UINT32 *src1 = (y < bitmap1.height()) ? &bitmap1.pix32(y) : NULL;
+ UINT32 *src2 = (y < bitmap2.height()) ? &bitmap2.pix32(y) : NULL;
+ UINT32 *dst1 = &finalbitmap.pix32(starty + y, 0);
+ UINT32 *dst2 = &finalbitmap.pix32(starty + y, bitmap1.width() + BITMAP_SPACE);
+ UINT32 *dstdiff = &finalbitmap.pix32(starty + y, bitmap1.width() + BITMAP_SPACE + maxwidth + BITMAP_SPACE);
/* now iterate over columns */
for (x = 0; x < maxwidth; x++)
{
int pix1 = -1, pix2 = -2;
- if (src1 != NULL && x < bitmap1->width())
+ if (src1 != NULL && x < bitmap1.width())
pix1 = dst1[x] = src1[x];
- if (src2 != NULL && x < bitmap2->width())
+ if (src2 != NULL && x < bitmap2.width())
pix2 = dst2[x] = src2[x];
dstdiff[x] = (pix1 != pix2) ? 0xffffffff : 0xff000000;
}
}
/* update the starting Y position */
- starty += BITMAP_SPACE + MAX(bitmap1->height(), bitmap2->height());
+ starty += BITMAP_SPACE + MAX(bitmap1.height(), bitmap2.height());
}
/* write the final PNG */
filerr = core_fopen(dstfilename, OPEN_FLAG_WRITE | OPEN_FLAG_CREATE, &file);
if (filerr != FILERR_NONE)
goto error;
- pngerr = png_write_bitmap(file, NULL, *finalbitmap, 0, NULL);
+ pngerr = png_write_bitmap(file, NULL, finalbitmap, 0, NULL);
core_fclose(file);
if (pngerr != PNGERR_NONE)
goto error;
@@ -997,9 +986,6 @@ static int generate_png_diff(const summary_file *curfile, astring &destdir, cons
error = 0;
error:
- delete finalbitmap;
- for (bmnum = 0; bmnum < bitmapcount; bmnum++)
- delete bitmaps[bmnum];
if (error)
osd_rmfile(dstfilename);
return error;