Move load_cg_with_file to cg.c

This commit is contained in:
kichikuou
2023-02-18 09:27:21 +09:00
parent 70a940b216
commit e88dfcdaa1
3 changed files with 37 additions and 39 deletions
+37 -2
View File
@@ -35,7 +35,7 @@
#include "qnt.h"
#include "jpeg.h"
#include "ald_manager.h"
#include "savedata.h"
#include "filecheck.h"
#include "cache.h"
/* VSPのパレット展開バンク */
@@ -391,6 +391,41 @@ void cg_load_with_alpha(int cgno, int shadowno) {
clear_display_loc();
}
static uint8_t* load_cg_from_file(char *fname_utf8, int *status, long *filesize) {
int size;
FILE *fp;
static uint8_t *tmp;
*status = 0;
if (NULL == (fp = fc_open(fname_utf8, 'r'))) {
*status = SAVE_LOADERR; return NULL;
}
fseek(fp, 0L, SEEK_END);
*filesize = ftell(fp);
if (*filesize == 0) {
*status = SAVE_LOADERR; return NULL;
}
tmp = (char *)malloc(*filesize);
if (tmp == NULL) {
WARNING("Out of memory");
*status = SAVE_LOADERR; return NULL;
}
fseek(fp, 0L, SEEK_SET);
size = fread(tmp, 1, *filesize,fp);
if (size != *filesize) {
*status = SAVE_LOADSHORTAGE;
} else {
*status = SAVE_LOADOK;
}
fclose(fp);
return tmp;
}
/*
* Load and display cg from file 'name' (not cached right now)
* name: file name to be read
@@ -405,7 +440,7 @@ int cg_load_with_filename(char *fname_utf8, int x, int y) {
cgdata *cg = NULL;
MyPoint p;
data = load_cg_with_file(fname_utf8, &status, &filesize);
data = load_cg_from_file(fname_utf8, &status, &filesize);
if (data == NULL) return status;
cg_set_display_location(x, y, OFFSET_ABSOLUTE_GC);
-36
View File
@@ -688,39 +688,3 @@ static int saveGameData(int no, char *buf, int size) {
scheduleSync();
return status;
}
/* 指定ファイルからの画像の読み込み thanx tajiru@wizard */
uint8_t* load_cg_with_file(char *fname_utf8, int *status, long *filesize){
int size;
FILE *fp;
static uint8_t *tmp;
*status = 0;
if (NULL == (fp = fc_open(fname_utf8, 'r'))) {
*status = SAVE_LOADERR; return NULL;
}
fseek(fp, 0L, SEEK_END);
*filesize = ftell(fp);
if (*filesize == 0) {
*status = SAVE_LOADERR; return NULL;
}
tmp = (char *)malloc(*filesize);
if (tmp == NULL) {
WARNING("Out of memory");
*status = SAVE_LOADERR; return NULL;
}
fseek(fp, 0L, SEEK_SET);
size = fread(tmp, 1, *filesize,fp);
if (size != *filesize) {
*status = SAVE_LOADSHORTAGE;
} else {
*status = SAVE_LOADOK;
}
fclose(fp);
return tmp;
}
-1
View File
@@ -121,7 +121,6 @@ extern int save_vars_to_file(char *fname_utf8, struct VarRef *src, int cnt);
extern int load_vars_from_file(char *fname_utf8, struct VarRef *dest, int cnt);
extern int save_save_str_with_file(char *fname_utf8, int start, int cnt);
extern int save_load_str_with_file(char *fname_utf8, int start, int cnt);
extern uint8_t* load_cg_with_file(char *fname_utf8, int *status, long *filesize);
extern const char *save_get_file(int index);
extern int save_delete_file(int index);