Files
nunuhara_xsystem4/cg.c
T
Nunuhara Cabbage a9de3b76fb Implement SACT2.Update()
Really lazy implementation for now, just draws all sprites every frame.
In the future should implement proper compositing with damage tracking.

All CG types other than QNT are removed. From what I've seen, System 4
games use QNT, PNG, AJP (encrypted JPEG) and DCF (seems to be a format
for partial CG updates). QNT is by far the most common format.
2019-11-17 21:44:16 -08:00

122 lines
2.4 KiB
C

/* Copyright (C) 2019 Nunuhara Cabbage <nunuhara@haniwa.technology>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://gnu.org/licenses/>.
*/
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <SDL.h>
#include "system4.h"
#include "ald.h"
#include "cg.h"
#include "qnt.h"
#include "graphics.h"
bool cg_exists(int no)
{
return ald[ALDFILE_CG] && ald_data_exists(ald[ALDFILE_CG], no);
}
/*
* Identify cg format
* data: pointer to compressed data
* return: cg type
*/
static enum cg_type check_cgformat(uint8_t *data)
{
if (qnt_checkfmt(data)) {
return ALCG_QNT;
}
WARNING("Unknown CG type");
return ALCG_UNKNOWN;
}
/*
* Free CG data
* cg: object to free
*/
void cg_free(struct cg *cg)
{
if (!cg)
return;
if (cg->s) {
if (cg->no < 0)
free(cg->s->pixels);
SDL_FreeSurface(cg->s);
}
free(cg);
}
/*
* Load cg data from file or cache
* no: file no ( >= 0)
* return: cg object(extracted)
*/
bool cg_load(struct cg *cg, int no)
{
struct archive_data *dfile;
int type, possibly_unused size = 0;
if (!(dfile = ald_get(ald[ALDFILE_CG], no))) {
WARNING("Failed to load CG %d", no);
return false;
}
// check loaded cg format
type = check_cgformat(dfile->data);
// extract cg
// size is only pixel data size
switch(type) {
case ALCG_QNT:
qnt_extract(cg, dfile->data);
size = (cg->rect.w * cg->rect.h) * 3;
break;
case ALCG_AJP:
// TODO
break;
case ALCG_PNG:
// TODO
break;
default:
break;
}
// ok to free
ald_free_data(dfile);
cg->no = no;
return true;
}
struct cg *cg_init(int width, int height, uint8_t r, uint8_t g, uint8_t b, uint8_t a)
{
struct cg *cg = calloc(1, sizeof(struct cg));
*cg = (struct cg) {
.no = -1,
.rect = {
.w = width,
.h = height
},
.color = {
.r = r,
.g = g,
.b = b,
.a = a
}
};
return cg;
}