summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/imagedev/picture.cpp
blob: f80bfb2885ed5400883a7c4c12c6c22539449094 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// license:BSD-3-Clause
// copyright-holders:R. Belmont
/*********************************************************************

    picture.cpp

    Image device for still pictures.

*********************************************************************/

#include "emu.h"
#include "picture.h"
#include "png.h"

/***************************************************************************
    TYPE DEFINITIONS
***************************************************************************/

// device type definition
DEFINE_DEVICE_TYPE(IMAGE_PICTURE, picture_image_device, "picture_image", "Still Image")

//-------------------------------------------------
//  picture_image_device - constructor
//-------------------------------------------------

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)
{
}

//-------------------------------------------------
//  picture_image_device - destructor
//-------------------------------------------------

picture_image_device::~picture_image_device()
{
	if (m_picture)
	{
		delete m_picture;
		m_picture = nullptr;
	}
}


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;
	}

	return image_init_result::PASS;
}

void picture_image_device::call_unload()
{
	if (m_picture)
	{
		delete m_picture;
		m_picture = nullptr;
	}
}