diff options
Diffstat (limited to 'src/devices/imagedev')
-rw-r--r-- | src/devices/imagedev/cassette.cpp | 53 | ||||
-rw-r--r-- | src/devices/imagedev/cassette.h | 15 | ||||
-rw-r--r-- | src/devices/imagedev/floppy.cpp | 34 | ||||
-rw-r--r-- | src/devices/imagedev/floppy.h | 4 | ||||
-rw-r--r-- | src/devices/imagedev/mfmhd.cpp | 23 | ||||
-rw-r--r-- | src/devices/imagedev/mfmhd.h | 4 | ||||
-rw-r--r-- | src/devices/imagedev/midiin.cpp | 18 | ||||
-rw-r--r-- | src/devices/imagedev/midiin.h | 2 | ||||
-rw-r--r-- | src/devices/imagedev/midiout.cpp | 14 | ||||
-rw-r--r-- | src/devices/imagedev/midiout.h | 2 | ||||
-rw-r--r-- | src/devices/imagedev/picture.cpp | 41 | ||||
-rw-r--r-- | src/devices/imagedev/picture.h | 4 |
12 files changed, 98 insertions, 116 deletions
diff --git a/src/devices/imagedev/cassette.cpp b/src/devices/imagedev/cassette.cpp index c6e20ba66dd..5d17f822e60 100644 --- a/src/devices/imagedev/cassette.cpp +++ b/src/devices/imagedev/cassette.cpp @@ -26,8 +26,8 @@ DEFINE_DEVICE_TYPE(CASSETTE, cassette_image_device, "cassette_image", "Cassette" // cassette_image_device - constructor //------------------------------------------------- -cassette_image_device::cassette_image_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) - : device_t(mconfig, CASSETTE, tag, owner, clock), +cassette_image_device::cassette_image_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) : + device_t(mconfig, CASSETTE, tag, owner, clock), device_image_interface(mconfig, *this), device_sound_interface(mconfig, *this), m_cassette(nullptr), @@ -83,13 +83,13 @@ void cassette_image_device::update() switch (int(m_state & CASSETTE_MASK_UISTATE)) // cast to int to suppress unhandled enum value warning { case CASSETTE_RECORD: - cassette_put_sample(m_cassette, m_channel, m_position, new_position - m_position, m_value); + m_cassette->put_sample(m_channel, m_position, new_position - m_position, m_value); break; case CASSETTE_PLAY: if (m_cassette) { - cassette_get_sample(m_cassette, m_channel, new_position, 0.0, &m_value); + m_cassette->get_sample(m_channel, new_position, 0.0, &m_value); // See if reached end of tape double length = get_length(); if (new_position > length) @@ -167,9 +167,7 @@ double cassette_image_device::get_position() double cassette_image_device::get_length() { - struct CassetteInfo info; - - cassette_get_info(m_cassette, &info); + cassette_image::Info info = m_cassette->get_info(); return ((double) info.sample_count) / info.sample_frequency; } @@ -236,7 +234,7 @@ void cassette_image_device::device_start() m_state = m_default_state; m_value = 0; - stream_alloc_legacy(0, (m_stereo? 2:1), machine().sample_rate()); + stream_alloc(0, m_stereo? 2:1, machine().sample_rate()); } image_init_result cassette_image_device::call_create(int format_type, util::option_resolution *format_options) @@ -258,7 +256,7 @@ image_init_result cassette_image_device::internal_load(bool is_create) if (is_create || (length()==0)) // empty existing images are fine to write over. { // creating an image - err = cassette_create((void *)image, &image_ioprocs, &wavfile_format, m_create_opts, CASSETTE_FLAG_READWRITE|CASSETTE_FLAG_SAVEONEXIT, &m_cassette); + err = cassette_image::create((void *)image, &image_ioprocs, &cassette_image::wavfile_format, m_create_opts, cassette_image::FLAG_READWRITE|cassette_image::FLAG_SAVEONEXIT, m_cassette); if (err != cassette_image::error::SUCCESS) goto error; } @@ -273,9 +271,9 @@ image_init_result cassette_image_device::internal_load(bool is_create) // try opening the cassette int cassette_flags = is_readonly() - ? CASSETTE_FLAG_READONLY - : (CASSETTE_FLAG_READWRITE | CASSETTE_FLAG_SAVEONEXIT); - err = cassette_open_choices((void *)image, &image_ioprocs, filetype(), m_formats, cassette_flags, &m_cassette); + ? cassette_image::FLAG_READONLY + : (cassette_image::FLAG_READWRITE | cassette_image::FLAG_SAVEONEXIT); + err = cassette_image::open_choices((void *)image, &image_ioprocs, filetype(), m_formats, cassette_flags, m_cassette); // special case - if we failed due to readwrite not being supported, make the image be read only and retry if (err == cassette_image::error::READ_WRITE_UNSUPPORTED) @@ -337,8 +335,7 @@ void cassette_image_device::call_unload() update(); /* close out the cassette */ - cassette_close(m_cassette); - m_cassette = nullptr; + m_cassette.reset(); /* set to default state, but only change the UI state */ change_state(CASSETTE_STOPPED, CASSETTE_MASK_UISTATE); @@ -404,37 +401,29 @@ std::string cassette_image_device::call_display() // Cassette sound //------------------------------------------------- -void cassette_image_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) +void cassette_image_device::sound_stream_update(sound_stream &stream, std::vector<read_stream_view> const &inputs, std::vector<write_stream_view> &outputs) { - stream_sample_t *left_buffer = outputs[0]; - stream_sample_t *right_buffer = nullptr; - - if (m_stereo) - right_buffer = outputs[1]; - cassette_state state = get_state() & (CASSETTE_MASK_UISTATE | CASSETTE_MASK_MOTOR | CASSETTE_MASK_SPEAKER); if (exists() && (state == (CASSETTE_PLAY | CASSETTE_MOTOR_ENABLED | CASSETTE_SPEAKER_ENABLED))) { cassette_image *cassette = get_image(); double time_index = get_position(); - double duration = ((double) samples) / machine().sample_rate(); + double duration = ((double) outputs[0].samples()) / outputs[0].sample_rate(); - cassette_get_samples(cassette, 0, time_index, duration, samples, 2, left_buffer, CASSETTE_WAVEFORM_16BIT); - if (m_stereo) - cassette_get_samples(cassette, 1, time_index, duration, samples, 2, right_buffer, CASSETTE_WAVEFORM_16BIT); + if (m_samples.size() < outputs[0].samples()) + m_samples.resize(outputs[0].samples()); - for (int i = samples - 1; i >= 0; i--) + for (int ch = 0; ch < outputs.size(); ch++) { - left_buffer[i] = ((int16_t *) left_buffer)[i]; - if (m_stereo) - right_buffer[i] = ((int16_t *) right_buffer)[i]; + cassette->get_samples(0, time_index, duration, outputs[0].samples(), 2, &m_samples[0], cassette_image::WAVEFORM_16BIT); + for (int sampindex = 0; sampindex < outputs[ch].samples(); sampindex++) + outputs[ch].put_int(sampindex, m_samples[sampindex], 32768); } } else { - memset(left_buffer, 0, sizeof(*left_buffer) * samples); - if (m_stereo) - memset(right_buffer, 0, sizeof(*right_buffer) * samples); + for (int ch = 0; ch < outputs.size(); ch++) + outputs[ch].fill(0); } } diff --git a/src/devices/imagedev/cassette.h b/src/devices/imagedev/cassette.h index a661e8312a8..e36b61d688d 100644 --- a/src/devices/imagedev/cassette.h +++ b/src/devices/imagedev/cassette.h @@ -53,8 +53,8 @@ public: cassette_image_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock = 0); virtual ~cassette_image_device(); - void set_formats(const struct CassetteFormat* const *formats) { m_formats = formats; } - void set_create_opts(const struct CassetteOptions *create_opts) { m_create_opts = create_opts; } + void set_formats(const cassette_image::Format* const *formats) { m_formats = formats; } + void set_create_opts(const cassette_image::Options *create_opts) { m_create_opts = create_opts; } void set_default_state(cassette_state default_state) { m_default_state = default_state; } void set_interface(const char *interface) { m_interface = interface; } @@ -92,7 +92,7 @@ public: void set_speaker(int state) { change_state(state ? CASSETTE_SPEAKER_ENABLED : CASSETTE_SPEAKER_MUTED, CASSETTE_MASK_SPEAKER); } int speaker_on() { return ((m_state & CASSETTE_MASK_SPEAKER) == CASSETTE_SPEAKER_ENABLED) ? 1 : 0; } - cassette_image *get_image() { return m_cassette; } + cassette_image *get_image() { return m_cassette.get(); } double get_position(); double get_length(); void set_speed(double speed); @@ -102,7 +102,7 @@ public: void seek(double time, int origin); // sound stream update overrides - void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; + virtual void sound_stream_update(sound_stream &stream, std::vector<read_stream_view> const &inputs, std::vector<write_stream_view> &outputs) override; device_sound_interface& set_stereo() { m_stereo = true; return *this; } protected: @@ -117,7 +117,7 @@ protected: void update(); private: - cassette_image *m_cassette; + cassette_image::ptr m_cassette; cassette_state m_state; double m_position; double m_position_time; @@ -126,13 +126,14 @@ private: double m_speed; // speed multiplier for tape speeds other than standard 1.875ips (used in adam driver) int m_direction; // direction select char m_extension_list[256]; - const struct CassetteFormat* const *m_formats; - const struct CassetteOptions *m_create_opts; + const cassette_image::Format* const *m_formats; + const cassette_image::Options *m_create_opts; cassette_state m_default_state; const char * m_interface; image_init_result internal_load(bool is_create); bool m_stereo; + std::vector<s16> m_samples; }; // device type definition diff --git a/src/devices/imagedev/floppy.cpp b/src/devices/imagedev/floppy.cpp index 3dd96644f1a..cf3ffefd524 100644 --- a/src/devices/imagedev/floppy.cpp +++ b/src/devices/imagedev/floppy.cpp @@ -178,7 +178,7 @@ floppy_image_device::floppy_image_device(const machine_config &mconfig, device_t device_image_interface(mconfig, *this), input_format(nullptr), output_format(nullptr), - image(nullptr), + image(), fif_list(nullptr), index_timer(nullptr), tracks(0), @@ -307,7 +307,7 @@ void floppy_image_device::commit_image() if (err != osd_file::error::NONE) popmessage("Error, unable to truncate image: %d", int(err)); - output_format->save(&io, image); + output_format->save(&io, image.get()); } //------------------------------------------------- @@ -459,7 +459,7 @@ image_init_result floppy_image_device::call_load() io.filler = 0xff; int best = 0; floppy_image_format_t *best_format = nullptr; - for(floppy_image_format_t *format = fif_list; format; format = format->next) { + for (floppy_image_format_t *format = fif_list; format; format = format->next) { int score = format->identify(&io, form_factor); if(score > best) { best = score; @@ -467,18 +467,15 @@ image_init_result floppy_image_device::call_load() } } - if(!best_format) - { + if (!best_format) { seterror(IMAGE_ERROR_INVALIDIMAGE, "Unable to identify the image format"); return image_init_result::FAIL; } - image = global_alloc(floppy_image(tracks, sides, form_factor)); - if (!best_format->load(&io, form_factor, image)) - { + image = std::make_unique<floppy_image>(tracks, sides, form_factor); + if (!best_format->load(&io, form_factor, image.get())) { seterror(IMAGE_ERROR_UNSUPPORTED, "Incompatible image format or corrupted data"); - global_free(image); - image = nullptr; + image.reset(); return image_init_result::FAIL; } output_format = is_readonly() ? nullptr : best_format; @@ -501,8 +498,7 @@ void floppy_image_device::call_unload() if (image) { if(image_dirty) commit_image(); - global_free(image); - image = nullptr; + image.reset(); } wpt = 1; // disk sleeve is covering the sensor @@ -526,7 +522,7 @@ void floppy_image_device::call_unload() image_init_result floppy_image_device::call_create(int format_type, util::option_resolution *format_options) { - image = global_alloc(floppy_image(tracks, sides, form_factor)); + image = std::make_unique<floppy_image>(tracks, sides, form_factor); output_format = nullptr; // search for a suitable format based on the extension @@ -1248,7 +1244,7 @@ void floppy_sound_device::device_start() // If we don't have all samples, don't allocate a stream or access sample data. if (m_loaded) { - m_sound = stream_alloc_legacy(0, 1, clock()); // per-floppy stream + m_sound = stream_alloc(0, 1, clock()); // per-floppy stream } register_for_save_states(); } @@ -1369,21 +1365,21 @@ void floppy_sound_device::step(int zone) } //------------------------------------------------- -// sound_stream_update_legacy - update the sound stream +// sound_stream_update - update the sound stream //------------------------------------------------- -void floppy_sound_device::sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) +void floppy_sound_device::sound_stream_update(sound_stream &stream, std::vector<read_stream_view> const &inputs, std::vector<write_stream_view> &outputs) { // We are using only one stream, unlike the parent class // Also, there is no need for interpolation, as we only expect // one sample rate of 44100 for all samples int16_t out; - stream_sample_t *samplebuffer = outputs[0]; + auto &samplebuffer = outputs[0]; int idx = 0; int sampleend = 0; - while (samples-- > 0) + for (int sampindex = 0; sampindex < samplebuffer.samples(); sampindex++) { out = 0; @@ -1477,7 +1473,7 @@ void floppy_sound_device::sound_stream_update_legacy(sound_stream &stream, strea } // Write to the stream buffer - *(samplebuffer++) = out; + samplebuffer.put_int(sampindex, out, 32768); } } diff --git a/src/devices/imagedev/floppy.h b/src/devices/imagedev/floppy.h index d07a12c146c..b163b0b6a42 100644 --- a/src/devices/imagedev/floppy.h +++ b/src/devices/imagedev/floppy.h @@ -154,7 +154,7 @@ protected: floppy_image_format_t *input_format; floppy_image_format_t *output_format; - floppy_image *image; + std::unique_ptr<floppy_image> image; char extension_list[256]; floppy_image_format_t *fif_list; emu_timer *index_timer; @@ -294,7 +294,7 @@ protected: private: // device_sound_interface overrides - void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override; + virtual void sound_stream_update(sound_stream &stream, std::vector<read_stream_view> const &inputs, std::vector<write_stream_view> &outputs) override; sound_stream* m_sound; int m_step_base; diff --git a/src/devices/imagedev/mfmhd.cpp b/src/devices/imagedev/mfmhd.cpp index a90cf75ea54..61eabb12217 100644 --- a/src/devices/imagedev/mfmhd.cpp +++ b/src/devices/imagedev/mfmhd.cpp @@ -366,7 +366,7 @@ void mfm_harddisk_device::device_start() m_current_cylinder = m_landing_zone; // Park position m_spinup_timer->adjust(attotime::from_msec(m_spinupms)); - m_cache = global_alloc(mfmhd_trackimage_cache(machine())); + m_cache = std::make_unique<mfmhd_trackimage_cache>(machine()); // In 5 second periods, check whether the cache has dirty lines m_cache_timer->adjust(attotime::from_msec(5000), 0, attotime::from_msec(5000)); @@ -411,7 +411,7 @@ void mfm_harddisk_device::device_reset() void mfm_harddisk_device::device_stop() { - if (m_cache!=nullptr) global_free(m_cache); + m_cache.reset(); } /* @@ -1010,9 +1010,8 @@ mfmhd_trackimage_cache::~mfmhd_trackimage_cache() while (current != nullptr) { - global_free_array(current->encdata); mfmhd_trackimage* currenttmp = current->next; - global_free(current); + delete current; current = currenttmp; } } @@ -1025,7 +1024,7 @@ void mfmhd_trackimage_cache::write_back_one() { if (current->dirty) { - m_mfmhd->write_track(current->encdata, current->cylinder, current->head); + m_mfmhd->write_track(current->encdata.get(), current->cylinder, current->head); current->dirty = false; break; } @@ -1045,7 +1044,7 @@ void mfmhd_trackimage_cache::cleanup() if (TRACE_CACHE) m_machine.logerror("[%s:cache] MFM HD cache: evict line cylinder=%d head=%d\n", m_mfmhd->tag(), current->cylinder, current->head); if (current->dirty) { - m_mfmhd->write_track(current->encdata, current->cylinder, current->head); + m_mfmhd->write_track(current->encdata.get(), current->cylinder, current->head); current->dirty = false; } mfmhd_trackimage* currenttmp = current->next; @@ -1087,11 +1086,11 @@ void mfmhd_trackimage_cache::init(mfm_harddisk_device* mfmhd, int tracksize, int { if (TRACE_DETAIL) m_machine.logerror("[%s:cache] MFM HD allocate cache slot\n", mfmhd->tag()); previous = current; - current = global_alloc(mfmhd_trackimage); - current->encdata = global_alloc_array(uint16_t, tracksize); + current = new mfmhd_trackimage; + current->encdata = std::make_unique<uint16_t []>(tracksize); // Load the first tracks into the slots - state = m_mfmhd->load_track(current->encdata, cylinder, head); + state = m_mfmhd->load_track(current->encdata.get(), cylinder, head); if (state != CHDERR_NONE) throw emu_fatalerror("Cannot load (c=%d,h=%d) from hard disk", cylinder, head); current->dirty = false; @@ -1148,7 +1147,7 @@ uint16_t* mfmhd_trackimage_cache::get_trackimage(int cylinder, int head) current->next = m_tracks; // put the previous head into the next field m_tracks = current; // set this line as new head } - return current->encdata; + return current->encdata.get(); } else { @@ -1168,11 +1167,11 @@ uint16_t* mfmhd_trackimage_cache::get_trackimage(int cylinder, int head) if (current->dirty) { - m_mfmhd->write_track(current->encdata, current->cylinder, current->head); + m_mfmhd->write_track(current->encdata.get(), current->cylinder, current->head); current->dirty = false; } - state = m_mfmhd->load_track(current->encdata, cylinder, head); + state = m_mfmhd->load_track(current->encdata.get(), cylinder, head); current->dirty = false; current->cylinder = cylinder; diff --git a/src/devices/imagedev/mfmhd.h b/src/devices/imagedev/mfmhd.h index 2d689a168cb..007be4be420 100644 --- a/src/devices/imagedev/mfmhd.h +++ b/src/devices/imagedev/mfmhd.h @@ -27,7 +27,7 @@ public: bool dirty; int cylinder; int head; - uint16_t* encdata; // MFM encoding per byte + std::unique_ptr<uint16_t []> encdata; // MFM encoding per byte mfmhd_trackimage* next; }; @@ -152,7 +152,7 @@ private: attotime m_settle_time; attotime m_step_time; - mfmhd_trackimage_cache* m_cache; + std::unique_ptr<mfmhd_trackimage_cache> m_cache; mfmhd_image_format_t* m_format; void head_move(); diff --git a/src/devices/imagedev/midiin.cpp b/src/devices/imagedev/midiin.cpp index 6086cb48a3e..62c7cba52a1 100644 --- a/src/devices/imagedev/midiin.cpp +++ b/src/devices/imagedev/midiin.cpp @@ -26,7 +26,7 @@ midiin_device::midiin_device(const machine_config &mconfig, const char *tag, dev : device_t(mconfig, MIDIIN, tag, owner, clock), device_image_interface(mconfig, *this), device_serial_interface(mconfig, *this), - m_midi(nullptr), + m_midi(), m_timer(nullptr), m_input_cb(*this), m_xmit_read(0), @@ -43,7 +43,7 @@ void midiin_device::device_start() { m_input_cb.resolve_safe(); m_timer = timer_alloc(0); - m_midi = nullptr; + m_midi.reset(); m_timer->enable(false); } @@ -68,7 +68,7 @@ void midiin_device::device_timer(emu_timer &timer, device_timer_id id, int param uint8_t buf[8192*4]; int bytesRead; - if (m_midi == nullptr) { + if (!m_midi) { return; } @@ -91,14 +91,13 @@ void midiin_device::device_timer(emu_timer &timer, device_timer_id id, int param call_load -------------------------------------------------*/ -image_init_result midiin_device::call_load(void) +image_init_result midiin_device::call_load() { m_midi = machine().osd().create_midi_device(); if (!m_midi->open_input(filename())) { - global_free(m_midi); - m_midi = nullptr; + m_midi.reset(); return image_init_result::FAIL; } @@ -111,15 +110,14 @@ image_init_result midiin_device::call_load(void) call_unload -------------------------------------------------*/ -void midiin_device::call_unload(void) +void midiin_device::call_unload() { if (m_midi) { m_midi->close(); - global_free(m_midi); } - m_timer->enable(false); - m_midi = nullptr; + m_midi.reset(); + m_timer->enable(false); } void midiin_device::tra_complete() diff --git a/src/devices/imagedev/midiin.h b/src/devices/imagedev/midiin.h index ad9eeabf236..dbebdfd71fc 100644 --- a/src/devices/imagedev/midiin.h +++ b/src/devices/imagedev/midiin.h @@ -60,7 +60,7 @@ private: void xmit_char(uint8_t data); - osd_midi_device *m_midi; + std::unique_ptr<osd_midi_device> m_midi; emu_timer *m_timer; devcb_write_line m_input_cb; uint8_t m_xmitring[XMIT_RING_SIZE]; diff --git a/src/devices/imagedev/midiout.cpp b/src/devices/imagedev/midiout.cpp index 3c0613e2015..e9551a50d17 100644 --- a/src/devices/imagedev/midiout.cpp +++ b/src/devices/imagedev/midiout.cpp @@ -26,7 +26,7 @@ midiout_device::midiout_device(const machine_config &mconfig, const char *tag, d : device_t(mconfig, MIDIOUT, tag, owner, clock), device_image_interface(mconfig, *this), device_serial_interface(mconfig, *this), - m_midi(nullptr) + m_midi() { } @@ -36,7 +36,7 @@ midiout_device::midiout_device(const machine_config &mconfig, const char *tag, d void midiout_device::device_start() { - m_midi = nullptr; + m_midi.reset(); } void midiout_device::device_reset() @@ -51,14 +51,13 @@ void midiout_device::device_reset() call_load -------------------------------------------------*/ -image_init_result midiout_device::call_load(void) +image_init_result midiout_device::call_load() { m_midi = machine().osd().create_midi_device(); if (!m_midi->open_output(filename())) { - global_free(m_midi); - m_midi = nullptr; + m_midi.reset(); return image_init_result::FAIL; } @@ -69,13 +68,12 @@ image_init_result midiout_device::call_load(void) call_unload -------------------------------------------------*/ -void midiout_device::call_unload(void) +void midiout_device::call_unload() { if (m_midi) { m_midi->close(); - global_free(m_midi); - m_midi = nullptr; + m_midi.reset(); } } diff --git a/src/devices/imagedev/midiout.h b/src/devices/imagedev/midiout.h index 2b182e0273d..20bc87131c5 100644 --- a/src/devices/imagedev/midiout.h +++ b/src/devices/imagedev/midiout.h @@ -53,7 +53,7 @@ protected: virtual void rcv_complete() override; // Rx completed receiving byte private: - osd_midi_device *m_midi; + std::unique_ptr<osd_midi_device> m_midi; }; // device type definition diff --git a/src/devices/imagedev/picture.cpp b/src/devices/imagedev/picture.cpp index f80bfb2885e..e6736fb10c9 100644 --- a/src/devices/imagedev/picture.cpp +++ b/src/devices/imagedev/picture.cpp @@ -10,7 +10,7 @@ #include "emu.h" #include "picture.h" -#include "png.h" +#include "rendutil.h" /*************************************************************************** TYPE DEFINITIONS @@ -25,8 +25,7 @@ DEFINE_DEVICE_TYPE(IMAGE_PICTURE, picture_image_device, "picture_image", "Still picture_image_device::picture_image_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) : device_t(mconfig, IMAGE_PICTURE, tag, owner, clock), - device_image_interface(mconfig, *this), - m_picture(nullptr) + device_image_interface(mconfig, *this) { } @@ -36,11 +35,6 @@ picture_image_device::picture_image_device(const machine_config &mconfig, const picture_image_device::~picture_image_device() { - if (m_picture) - { - delete m_picture; - m_picture = nullptr; - } } @@ -50,24 +44,31 @@ void picture_image_device::device_start() image_init_result picture_image_device::call_load() { - m_picture = new bitmap_argb32; - if (png_read_bitmap(image_core_file(), *m_picture) != PNGERR_NONE) - { - delete m_picture; - m_picture = nullptr; - - // todo: try JPEG here. - return image_init_result::FAIL; + switch (render_detect_image(image_core_file())) + { + case RENDUTIL_IMGFORMAT_PNG: + render_load_png(m_picture, image_core_file()); + break; + + case RENDUTIL_IMGFORMAT_JPEG: + render_load_jpeg(m_picture, image_core_file()); + break; + + case RENDUTIL_IMGFORMAT_MSDIB: + render_load_msdib(m_picture, image_core_file()); + break; + + default: + m_picture.reset(); } - return image_init_result::PASS; + return m_picture.valid() ? image_init_result::PASS : image_init_result::FAIL; } void picture_image_device::call_unload() { - if (m_picture) + if (m_picture.valid()) { - delete m_picture; - m_picture = nullptr; + m_picture.reset(); } } diff --git a/src/devices/imagedev/picture.h b/src/devices/imagedev/picture.h index f8601345a89..1780a563318 100644 --- a/src/devices/imagedev/picture.h +++ b/src/devices/imagedev/picture.h @@ -41,14 +41,14 @@ public: virtual bool is_reset_on_load() const noexcept override { return false; } virtual const char *file_extensions() const noexcept override { return "png"; } - bitmap_argb32 &get_bitmap() { return *m_picture; } + const bitmap_argb32 &get_bitmap() { return m_picture; } protected: // device-level overrides virtual void device_start() override; private: - bitmap_argb32 *m_picture; + bitmap_argb32 m_picture; }; |