summaryrefslogtreecommitdiffstatshomepage
path: root/src/tools
diff options
context:
space:
mode:
author Aaron Giles <aaron@aarongiles.com>2011-12-31 21:26:25 +0000
committer Aaron Giles <aaron@aarongiles.com>2011-12-31 21:26:25 +0000
commit0fb2402169d60ebe944a741408cc7268fd22ca80 (patch)
tree539623a3359126d497d4dfcea4314b66b103c0fa /src/tools
parent4241eec6b8041446c2a822b945167f57b4ddbc4f (diff)
Fix tools to work with new bitmap_t semantics.
Diffstat (limited to 'src/tools')
-rw-r--r--src/tools/chdman.c67
-rw-r--r--src/tools/ldresample.c3
-rw-r--r--src/tools/ldverify.c19
-rw-r--r--src/tools/regrep.c52
4 files changed, 63 insertions, 78 deletions
diff --git a/src/tools/chdman.c b/src/tools/chdman.c
index da19cde8312..08b71cd858a 100644
--- a/src/tools/chdman.c
+++ b/src/tools/chdman.c
@@ -49,6 +49,7 @@
#include <stdio.h>
#include <time.h>
#include <ctype.h>
+#include <new>
/***************************************************************************
@@ -878,13 +879,10 @@ static avi_error read_avi_frame(avi_file *avi, UINT32 framenum, UINT32 first_sam
}
/* build the fake bitmap */
- bitmap_clone_existing(avconfig->video, fullbitmap);
- if (interlaced)
- {
- avconfig->video->base = BITMAP_ADDR16(avconfig->video, framenum % interlace_factor, 0);
- avconfig->video->rowpixels *= 2;
- avconfig->video->height /= 2;
- }
+ if (!interlaced)
+ avconfig->video->clone_existing(*fullbitmap);
+ else
+ avconfig->video = new(avconfig->video) bitmap_t(&fullbitmap->pix16(framenum % interlace_factor), fullbitmap->width(), fullbitmap->height() / 2, fullbitmap->rowpixels() * 2, fullbitmap->format());
cleanup:
return avierr;
@@ -948,30 +946,27 @@ static avi_error fake_avi_frame(avi_file *avi, UINT32 framenum, UINT32 first_sam
}
/* build the fake bitmap */
- bitmap_clone_existing(avconfig->video, fullbitmap);
- if (interlaced)
- {
- avconfig->video->base = BITMAP_ADDR16(avconfig->video, framenum % interlace_factor, 0);
- avconfig->video->rowpixels *= 2;
- avconfig->video->height /= 2;
- }
+ if (!interlaced)
+ avconfig->video->clone_existing(*fullbitmap);
+ else
+ avconfig->video = new(avconfig->video) bitmap_t(&fullbitmap->pix16(framenum % interlace_factor), fullbitmap->width(), fullbitmap->height() / 2, fullbitmap->rowpixels() * 2, fullbitmap->format());
/* 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 = BITMAP_ADDR16(avconfig->video, y, 0);
+ 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)
@@ -991,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;
}
}
@@ -1122,7 +1117,7 @@ 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 = bitmap_alloc(width, height * (interlaced ? 2 : 1), BITMAP_FORMAT_YUY16);
+ 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");
@@ -1204,7 +1199,7 @@ static int do_createav(int argc, char *argv[], int param)
{
/* parse the data and pack it */
vbi_metadata vbi;
- vbi_parse_all((const UINT16 *)avconfig.video->base, avconfig.video->rowpixels, avconfig.video->width, 8, &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);
}
@@ -1244,8 +1239,7 @@ cleanup:
for (chnum = 0; chnum < ARRAY_LENGTH(avconfig.audio); chnum++)
if (avconfig.audio[chnum] != NULL)
free(avconfig.audio[chnum]);
- if (fullbitmap != NULL)
- bitmap_free(fullbitmap);
+ delete fullbitmap;
if (ldframedata != NULL)
free(ldframedata);
if (err != CHDERR_NONE)
@@ -1878,7 +1872,7 @@ static int do_extractav(int argc, char *argv[], int param)
numframes = MIN(totalframes - firstframe, numframes);
/* allocate a video buffer */
- fullbitmap = bitmap_alloc(width, height, BITMAP_FORMAT_YUY16);
+ fullbitmap = new(std::nothrow) bitmap_t(width, height, BITMAP_FORMAT_YUY16);
if (fullbitmap == NULL)
{
fprintf(stderr, "Out of memory allocating temporary bitmap\n");
@@ -1941,13 +1935,10 @@ static int do_extractav(int argc, char *argv[], int param)
progress(framenum == 0, "Extracting hunk %d/%d... \r", framenum, numframes);
/* set up the fake bitmap for this frame */
- bitmap_clone_existing(avconfig.video, fullbitmap);
- if (interlaced)
- {
- avconfig.video->base = BITMAP_ADDR16(avconfig.video, framenum % 2, 0);
- avconfig.video->rowpixels *= 2;
- avconfig.video->height /= 2;
- }
+ 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);
@@ -1991,8 +1982,7 @@ cleanup:
for (chnum = 0; chnum < ARRAY_LENGTH(avconfig.audio); chnum++)
if (avconfig.audio[chnum] != NULL)
free(avconfig.audio[chnum]);
- if (fullbitmap != NULL)
- bitmap_free(fullbitmap);
+ delete fullbitmap;
if (chd != NULL)
chd_close(chd);
if (err != CHDERR_NONE)
@@ -2228,7 +2218,7 @@ static int do_fixavdata(int argc, char *argv[], int param)
}
/* allocate a video buffer */
- fullbitmap = bitmap_alloc(width, height, BITMAP_FORMAT_YUY16);
+ fullbitmap = new(std::nothrow) bitmap_t(width, height, BITMAP_FORMAT_YUY16);
if (fullbitmap == NULL)
{
fprintf(stderr, "Out of memory allocating temporary bitmap\n");
@@ -2272,7 +2262,7 @@ static int do_fixavdata(int argc, char *argv[], int param)
progress(framenum == 0, "Processing hunk %d/%d... \r", framenum, header.totalhunks);
/* set up the fake bitmap for this frame */
- bitmap_clone_existing(avconfig.video, fullbitmap);
+ avconfig.video->clone_existing(*fullbitmap);
/* configure the decompressor for this frame */
chd_codec_config(chd, AV_CODEC_DECOMPRESS_CONFIG, &avconfig);
@@ -2289,7 +2279,7 @@ static int do_fixavdata(int argc, char *argv[], int param)
vbi_metadata_unpack(&origvbi, &vbiframe, &vbidata[framenum * VBI_PACKED_BYTES]);
/* parse the video data */
- vbi_parse_all((const UINT16 *)avconfig.video->base, avconfig.video->rowpixels, avconfig.video->width, 8, &vbi);
+ 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)
@@ -2379,8 +2369,7 @@ static int do_fixavdata(int argc, char *argv[], int param)
cleanup:
/* clean up our mess */
- if (fullbitmap != NULL)
- bitmap_free(fullbitmap);
+ delete fullbitmap;
if (vbidata != NULL)
free(vbidata);
if (chd != NULL)
diff --git a/src/tools/ldresample.c b/src/tools/ldresample.c
index deace44d3d4..58f019561d7 100644
--- a/src/tools/ldresample.c
+++ b/src/tools/ldresample.c
@@ -41,6 +41,7 @@
#include <ctype.h>
#include <stdlib.h>
#include <math.h>
+#include <new>
#include "bitmap.h"
#include "chd.h"
#include "vbiparse.h"
@@ -150,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 = bitmap_alloc(info->width, info->height, BITMAP_FORMAT_YUY16);
+ info->bitmap = new(std::nothrow) bitmap_t(info->width, info->height, BITMAP_FORMAT_YUY16);
if (info->bitmap == NULL)
{
fprintf(stderr, "Out of memory creating %dx%d bitmap\n", info->width, info->height);
diff --git a/src/tools/ldverify.c b/src/tools/ldverify.c
index eead12de0bd..b8161384bf9 100644
--- a/src/tools/ldverify.c
+++ b/src/tools/ldverify.c
@@ -40,6 +40,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
+#include <new>
#include "aviio.h"
#include "bitmap.h"
#include "chd.h"
@@ -271,13 +272,9 @@ 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 */
- bitmap_clone_existing(&fakebitmap, bitmap);
- fakebitmap.base = BITMAP_ADDR16(&fakebitmap, fieldnum, 0);
- fakebitmap.rowpixels *= interlace_factor;
- fakebitmap.height /= interlace_factor;
+ avconfig.video = new(&fakebitmap) bitmap_t(&bitmap->pix16(fieldnum), bitmap->width(), bitmap->height() / interlace_factor, bitmap->rowpixels() * interlace_factor, bitmap->format());
/* configure the codec */
- avconfig.video = &fakebitmap;
avconfig.maxsamples = 48000;
avconfig.actsamples = &numsamples;
avconfig.audio[0] = &lsound[*samples];
@@ -366,7 +363,7 @@ static void verify_video(video_info *video, int frame, bitmap_t *bitmap)
fprintf(stderr, "%6d.%d...\r", frame, fieldnum);
/* parse the VBI data */
- vbi_parse_all(BITMAP_ADDR16(bitmap, fieldnum, 0), bitmap->rowpixels * 2, bitmap->width, 8, &metadata);
+ vbi_parse_all(&bitmap->pix16(fieldnum), bitmap->rowpixels() * 2, bitmap->width(), 8, &metadata);
/* if we have data in both 17 and 18, it should match */
if (metadata.line17 != 0 && metadata.line18 != 0 && metadata.line17 != metadata.line18)
@@ -522,7 +519,7 @@ static void verify_video(video_info *video, int frame, bitmap_t *bitmap)
/* now examine the active video signal */
pixels = 0;
- for (y = 22*2 + fieldnum; y < bitmap->height; y += 2)
+ for (y = 22*2 + fieldnum; y < bitmap->height(); y += 2)
{
for (x = 16; x < 720 - 16; x++)
{
@@ -618,7 +615,7 @@ static void verify_video(video_info *video, int frame, bitmap_t *bitmap)
static void verify_video_final(video_info *video, int frame, bitmap_t *bitmap)
{
- int fields_per_frame = (bitmap->height >= 288) ? 2 : 1;
+ int fields_per_frame = (bitmap->height() >= 288) ? 2 : 1;
int field = frame * fields_per_frame;
/* did we ever see any white flags? */
@@ -803,7 +800,7 @@ int main(int argc, char *argv[])
printf("WARNING: Unexpected sampele rate (should be 48000Hz)\n");
/* allocate a bitmap */
- bitmap = bitmap_alloc(info.width, info.height, BITMAP_FORMAT_YUY16);
+ bitmap = new(std::nothrow) bitmap_t(info.width, info.height, BITMAP_FORMAT_YUY16);
if (bitmap == NULL)
{
isavi ? close_avi(file) : close_chd(file);
@@ -817,7 +814,7 @@ int main(int argc, char *argv[])
if (lsound == NULL || rsound == NULL)
{
isavi ? close_avi(file) : close_chd(file);
- bitmap_free(bitmap);
+ delete bitmap;
if (rsound != NULL)
free(rsound);
if (lsound != NULL)
@@ -843,7 +840,7 @@ int main(int argc, char *argv[])
verify_audio_final(&audio);
/* free memory */
- bitmap_free(bitmap);
+ delete bitmap;
free(lsound);
free(rsound);
diff --git a/src/tools/regrep.c b/src/tools/regrep.c
index 03bf037b05f..a8fb8fa79f0 100644
--- a/src/tools/regrep.c
+++ b/src/tools/regrep.c
@@ -39,6 +39,7 @@
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
+#include <new>
#include "osdcore.h"
#include "png.h"
@@ -779,7 +780,7 @@ static void output_report(const astring *dirname, const astring *tempheader, con
static int compare_screenshots(summary_file *curfile)
{
- bitmap_t *bitmaps[MAX_COMPARES];
+ bitmap_t *bitmaps[MAX_COMPARES] = { NULL };
int unique[MAX_COMPARES];
int numunique = 0;
int listnum;
@@ -837,19 +838,19 @@ static int compare_screenshots(summary_file *curfile)
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);
+ 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 (y = 0; y < this_bitmap->height() && !bitmaps_differ; y++)
{
- UINT32 *base = BITMAP_ADDR32(base_bitmap, y, 0);
- UINT32 *curr = BITMAP_ADDR32(this_bitmap, y, 0);
+ UINT32 *base = &base_bitmap->pix32(y);
+ UINT32 *curr = &this_bitmap->pix32(y);
/* scan the scanline */
- for (x = 0; x < this_bitmap->width; 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 */
@@ -876,8 +877,7 @@ static int compare_screenshots(summary_file *curfile)
/* free the bitmaps */
for (listnum = 0; listnum < list_count; listnum++)
- if (bitmaps[listnum] != NULL)
- bitmap_free(bitmaps[listnum]);
+ delete bitmaps[listnum];
/* if all screenshots matched, we're good */
if (numunique == 1)
@@ -942,24 +942,24 @@ static int generate_png_diff(const summary_file *curfile, const astring *destdir
/* 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 = bitmap_alloc(width, height, BITMAP_FORMAT_ARGB32);
+ finalbitmap = new(std::nothrow) bitmap_t(width, height, BITMAP_FORMAT_ARGB32);
if (finalbitmap == NULL)
goto error;
@@ -969,33 +969,33 @@ static int generate_png_diff(const summary_file *curfile, const astring *destdir
{
bitmap_t *bitmap1 = bitmaps[0];
bitmap_t *bitmap2 = bitmaps[bmnum];
- int curheight = MAX(bitmap1->height, bitmap2->height);
+ 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) ? BITMAP_ADDR32(bitmap1, y, 0) : NULL;
- UINT32 *src2 = (y < bitmap2->height) ? BITMAP_ADDR32(bitmap2, y, 0) : NULL;
- UINT32 *dst1 = BITMAP_ADDR32(finalbitmap, starty + y, 0);
- UINT32 *dst2 = BITMAP_ADDR32(finalbitmap, starty + y, bitmap1->width + BITMAP_SPACE);
- UINT32 *dstdiff = BITMAP_ADDR32(finalbitmap, 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 */
@@ -1011,11 +1011,9 @@ static int generate_png_diff(const summary_file *curfile, const astring *destdir
error = 0;
error:
- if (finalbitmap != NULL)
- bitmap_free(finalbitmap);
+ delete finalbitmap;
for (bmnum = 0; bmnum < bitmapcount; bmnum++)
- if (bitmaps[bmnum] != NULL)
- bitmap_free(bitmaps[bmnum]);
+ delete bitmaps[bmnum];
if (error)
osd_rmfile(astring_c(dstfilename));
astring_free(dstfilename);