2
* iffdrv.c - Create an Amiga IFF file.
5
* Marco van den Heuvel <blackystardust68@yahoo.com>
7
* This file is part of VICE, the Versatile Commodore Emulator.
8
* See README for copyright notice.
10
* This program is free software; you can redistribute it and/or modify
11
* it under the terms of the GNU General Public License as published by
12
* the Free Software Foundation; either version 2 of the License, or
13
* (at your option) any later version.
15
* This program is distributed in the hope that it will be useful,
16
* but WITHOUT ANY WARRANTY; without even the implied warranty of
17
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
* GNU General Public License for more details.
20
* You should have received a copy of the GNU General Public License
21
* along with this program; if not, write to the Free Software
22
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
37
#include "gfxoutput.h"
39
#include "screenshot.h"
44
typedef struct gfxoutputdrv_data_s
52
} gfxoutputdrv_data_t;
54
static gfxoutputdrv_t iff_drv;
56
static BYTE powers[8]= { 1,2,4,8,16,32,64,128 };
58
static int iffdrv_write_file_header(screenshot_t *screenshot)
60
gfxoutputdrv_data_t *sdata;
65
memset(header, 0, sizeof(header));
67
sdata = screenshot->gfxoutputdrv_data;
69
sdata->iff_rowbytes=((screenshot->width+15)>>4)<<1;
71
totalsize=828+(sdata->iff_rowbytes*screenshot->height*8);
77
util_dword_to_be_buf(&header[4], totalsize);
86
util_dword_to_be_buf(&header[16], 20);
87
util_word_to_be_buf(&header[20],screenshot->width);
88
util_word_to_be_buf(&header[22],screenshot->height);
90
util_word_to_be_buf(&header[36],screenshot->width);
91
util_word_to_be_buf(&header[38],screenshot->height);
96
util_dword_to_be_buf(&header[44],3*256);
98
for (i = 0; i < 256; i++)
100
header[48+(i*3)]=screenshot->palette->entries[i].red;
101
header[49+(i*3)]=screenshot->palette->entries[i].green;
102
header[50+(i*3)]=screenshot->palette->entries[i].blue;
108
util_dword_to_be_buf(&header[820],4);
114
util_dword_to_be_buf(&header[832],sdata->iff_rowbytes*screenshot->height*8);
116
if (fwrite(header,836,1,sdata->fd)<1)
122
static int iffdrv_open(screenshot_t *screenshot, const char *filename)
124
gfxoutputdrv_data_t *sdata;
126
if (screenshot->palette->num_entries > 256)
128
log_error(LOG_DEFAULT, "Max 256 colors supported.");
132
sdata = (gfxoutputdrv_data_t *)lib_malloc(sizeof(gfxoutputdrv_data_t));
133
screenshot->gfxoutputdrv_data = sdata;
135
sdata->ext_filename=util_add_extension_const(filename, iff_drv.default_extension);
136
sdata->fd = fopen(filename, "wb");
140
lib_free(sdata->ext_filename);
145
if (iffdrv_write_file_header(screenshot)<0)
148
lib_free(sdata->ext_filename);
153
sdata->data = (BYTE *)lib_malloc(sdata->iff_rowbytes*8);
154
sdata->iff_data = (BYTE *)lib_malloc(sdata->iff_rowbytes);
159
static void iff_c2p(BYTE *chunky, BYTE *planar, int amount, int plane)
163
for (i=0; i<amount; i++)
165
planar[i]=((chunky[i*8]&powers[plane])/powers[plane]*128)+
166
((chunky[(i*8)+1]&powers[plane])/powers[plane]*64)+
167
((chunky[(i*8)+2]&powers[plane])/powers[plane]*32)+
168
((chunky[(i*8)+3]&powers[plane])/powers[plane]*16)+
169
((chunky[(i*8)+4]&powers[plane])/powers[plane]*8)+
170
((chunky[(i*8)+5]&powers[plane])/powers[plane]*4)+
171
((chunky[(i*8)+6]&powers[plane])/powers[plane]*2)+
172
(chunky[(i*8)+7]&powers[plane])/powers[plane];
176
static int iffdrv_write(screenshot_t *screenshot)
178
gfxoutputdrv_data_t *sdata;
181
sdata = screenshot->gfxoutputdrv_data;
182
(screenshot->convert_line)(screenshot, sdata->data, sdata->line, SCREENSHOT_MODE_PALETTE);
183
for (j = 0; j<8; j++)
185
iff_c2p(sdata->data,sdata->iff_data,sdata->iff_rowbytes,j);
186
if (fwrite(sdata->iff_data, sdata->iff_rowbytes, 1, sdata->fd)<1)
192
static int iffdrv_close(screenshot_t *screenshot)
194
gfxoutputdrv_data_t *sdata;
196
sdata = screenshot->gfxoutputdrv_data;
199
lib_free(sdata->data);
200
lib_free(sdata->iff_data);
201
lib_free(sdata->ext_filename);
207
static int iffdrv_save(screenshot_t *screenshot, const char *filename)
209
if (iffdrv_open(screenshot, filename) < 0)
212
for (screenshot->gfxoutputdrv_data->line = 0;
213
screenshot->gfxoutputdrv_data->line < screenshot->height;
214
(screenshot->gfxoutputdrv_data->line)++)
216
iffdrv_write(screenshot);
219
if (iffdrv_close(screenshot) < 0)
225
static gfxoutputdrv_t iff_drv =
237
void gfxoutput_init_iff(void)
239
gfxoutput_register(&iff_drv);