-
Notifications
You must be signed in to change notification settings - Fork 0
/
image.cpp
56 lines (44 loc) · 1.41 KB
/
image.cpp
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
#include "image.h"
#include <osbind.h>
#include <utility>
#include <cstdio>
#include <cstdlib>
namespace AtariGraphics {
Image::Image(const char *filename) : image(fix_address(&oa_image)) {
short fh;
int32_t length = 0;
fh = Fopen(filename, 2);
if (fh > 0) {
length = Fread(fh, sizeof(DegasPicture), image);
Fclose(fh);
}
if (fh < 0 || length != sizeof(DegasPicture)) {
(void) Cconws("Error: image ");
(void) Cconws(filename);
(void) Cconws(" could not be loaded\r\n");
exit(1);
}
save_palette();
set_palette(image->palette);
}
Image::~Image() {
restore_palette();
}
void Image::save_palette(void) {
volatile uint16_t (*colreg)[16] = (volatile uint16_t (*)[16]) 0xffff8240;
// transfer color registers into saved_palette
for (int i = 0; i < 16; i++)
saved_palette[i] = (*colreg)[i];
}
void Image::set_palette(uint16_t palette[]) {
volatile uint16_t (*colreg)[16] = (volatile uint16_t (*)[16]) 0xffff8240;
for (int i = 0; i < 16; i++)
(*colreg)[i] = palette[i];
}
void Image::restore_palette(void) {
set_palette(saved_palette);
}
const uint8_t * Image::image_data(void) {
return reinterpret_cast<uint8_t *>(image->picture_data);
}
}