mirror of
https://github.com/nunuhara/xsystem4.git
synced 2026-10-03 12:28:01 +03:00
Implement SACT2.CG_GetMetrics
This commit is contained in:
@@ -43,6 +43,23 @@ static enum cg_type check_cgformat(uint8_t *data)
|
||||
return ALCG_UNKNOWN;
|
||||
}
|
||||
|
||||
bool cg_get_metrics(int no, struct cg_metrics *dst)
|
||||
{
|
||||
struct archive_data *dfile;
|
||||
|
||||
if (!(dfile = ald_get(ald[ALDFILE_CG], no)))
|
||||
return false;
|
||||
|
||||
switch (check_cgformat(dfile->data)) {
|
||||
case ALCG_QNT:
|
||||
qnt_get_metrics(dfile->data, dst);
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void _cg_free(struct cg *cg)
|
||||
{
|
||||
if (!cg)
|
||||
|
||||
@@ -43,7 +43,18 @@ struct cg {
|
||||
SDL_Surface *s;
|
||||
};
|
||||
|
||||
struct cg_metrics {
|
||||
int w;
|
||||
int h;
|
||||
int bpp;
|
||||
bool has_pixel;
|
||||
bool has_alpha;
|
||||
int pixel_pitch;
|
||||
int alpha_pitch;
|
||||
};
|
||||
|
||||
bool cg_exists(int no);
|
||||
bool cg_get_metrics(int no, struct cg_metrics *dst);
|
||||
bool cg_load(struct cg *cg, int no);
|
||||
struct cg *cg_init(void);
|
||||
void cg_reinit(struct cg *cg);
|
||||
|
||||
+1
-1
@@ -384,7 +384,7 @@ hll_defun_inline(Timer_Get, vm_time());
|
||||
// int CG_IsExist(int nCG)
|
||||
hll_defun_inline(CG_IsExist, cg_exists(a[0].i - 1));
|
||||
// int CG_GetMetrics(int nCG, ref struct cm)
|
||||
hll_unimplemented(SACT2, CG_GetMetrics);
|
||||
hll_defun_inline(CG_GetMetrics, sact_CG_GetMetrics(a[0].i - 1, heap[a[1].i].page->values));
|
||||
// int CSV_Load(string pIStringFileName)
|
||||
hll_unimplemented(SACT2, CSV_Load);
|
||||
// int CSV_Save(void)
|
||||
|
||||
@@ -46,14 +46,6 @@
|
||||
*/
|
||||
#define ZLIBBUF_MARGIN 5*1024
|
||||
|
||||
/*
|
||||
static methods
|
||||
*/
|
||||
static struct qnt_header *extract_header(uint8_t *b);
|
||||
static void extract_pixel(struct qnt_header *qnt, uint8_t *pic, uint8_t *b);
|
||||
static void extract_alpha(struct qnt_header *qnt, uint8_t *pic, uint8_t *b);
|
||||
|
||||
|
||||
/*
|
||||
* Get information from header
|
||||
*
|
||||
@@ -61,9 +53,8 @@ static void extract_alpha(struct qnt_header *qnt, uint8_t *pic, uint8_t *b);
|
||||
*
|
||||
* return: acquired qnt information object
|
||||
*/
|
||||
static struct qnt_header *extract_header(uint8_t *b)
|
||||
static void extract_header(uint8_t *b, struct qnt_header *qnt)
|
||||
{
|
||||
struct qnt_header *qnt = malloc(sizeof(struct qnt_header));
|
||||
int rsv0;
|
||||
|
||||
rsv0 = LittleEndian_getDW(b, 4);
|
||||
@@ -90,8 +81,6 @@ static struct qnt_header *extract_header(uint8_t *b)
|
||||
}
|
||||
if (qnt->bpp != 24)
|
||||
ERROR("Unsupported bits-per-pixel: %d", qnt->bpp);
|
||||
|
||||
return qnt;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -239,6 +228,20 @@ bool qnt_checkfmt(uint8_t *data)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool qnt_get_metrics(uint8_t *data, struct cg_metrics *dst)
|
||||
{
|
||||
struct qnt_header qnt;
|
||||
extract_header(data, &qnt);
|
||||
dst->w = qnt.width;
|
||||
dst->h = qnt.height;
|
||||
dst->bpp = qnt.bpp;
|
||||
dst->has_pixel = qnt.pixel_size > 0;
|
||||
dst->has_alpha = qnt.alpha_size > 0;
|
||||
dst->pixel_pitch = qnt.width * (qnt.bpp / 8);
|
||||
dst->alpha_pitch = 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* Extract qnt header and pixel
|
||||
*
|
||||
@@ -248,19 +251,20 @@ bool qnt_checkfmt(uint8_t *data)
|
||||
*/
|
||||
SDL_Surface *qnt_extract(uint8_t *data)
|
||||
{
|
||||
struct qnt_header *qnt = extract_header(data);
|
||||
uint8_t *pixels = malloc(sizeof(uint8_t) * ((qnt->width+10) * (qnt->height+10) * 3));
|
||||
extract_pixel(qnt, pixels, data + qnt->hdr_size);
|
||||
struct qnt_header qnt;
|
||||
extract_header(data, &qnt);
|
||||
uint8_t *pixels = malloc(sizeof(uint8_t) * ((qnt.width+10) * (qnt.height+10) * 3));
|
||||
extract_pixel(&qnt, pixels, data + qnt.hdr_size);
|
||||
|
||||
if (!qnt->alpha_size)
|
||||
return SDL_CreateRGBSurfaceWithFormatFrom(pixels, qnt->width, qnt->height, 24,
|
||||
qnt->width * 3, SDL_PIXELFORMAT_RGB24);
|
||||
if (!qnt.alpha_size)
|
||||
return SDL_CreateRGBSurfaceWithFormatFrom(pixels, qnt.width, qnt.height, 24,
|
||||
qnt.width * 3, SDL_PIXELFORMAT_RGB24);
|
||||
|
||||
// combine color/alpha data
|
||||
uint8_t *alpha = malloc(sizeof(uint8_t) * ((qnt->width+10) * (qnt->height+10)));
|
||||
uint8_t *tmp = malloc((qnt->width+10) * (qnt->height+10) * 4);
|
||||
extract_alpha(qnt, alpha, data + qnt->hdr_size + qnt->pixel_size);
|
||||
for (int src_i = 0, dst_i = 0, p = 0; p < qnt->width * qnt->height; p++) {
|
||||
uint8_t *alpha = malloc(sizeof(uint8_t) * ((qnt.width+10) * (qnt.height+10)));
|
||||
uint8_t *tmp = malloc((qnt.width+10) * (qnt.height+10) * 4);
|
||||
extract_alpha(&qnt, alpha, data + qnt.hdr_size + qnt.pixel_size);
|
||||
for (int src_i = 0, dst_i = 0, p = 0; p < qnt.width * qnt.height; p++) {
|
||||
tmp[dst_i++] = alpha[p];
|
||||
tmp[dst_i++] = pixels[src_i++];
|
||||
tmp[dst_i++] = pixels[src_i++];
|
||||
@@ -270,6 +274,6 @@ SDL_Surface *qnt_extract(uint8_t *data)
|
||||
free(pixels);
|
||||
pixels = tmp;
|
||||
|
||||
return SDL_CreateRGBSurfaceWithFormatFrom(pixels, qnt->width, qnt->height, 32,
|
||||
qnt->width * 4, SDL_PIXELFORMAT_ARGB32);
|
||||
return SDL_CreateRGBSurfaceWithFormatFrom(pixels, qnt.width, qnt.height, 32,
|
||||
qnt.width * 4, SDL_PIXELFORMAT_ARGB32);
|
||||
}
|
||||
|
||||
@@ -44,6 +44,7 @@ struct qnt_header {
|
||||
};
|
||||
|
||||
bool qnt_checkfmt(uint8_t *data);
|
||||
bool qnt_get_metrics(uint8_t *data, struct cg_metrics *dst);
|
||||
SDL_Surface *qnt_extract(uint8_t *data);
|
||||
|
||||
#endif /* __QNT_H__ */
|
||||
|
||||
@@ -59,6 +59,7 @@ int sact_SP_ExistsAlpha(int sp_no);
|
||||
int sact_SP_TextDraw(int sp_no, struct string *text, union vm_value *tm);
|
||||
int sact_SP_TextClear(int sp_no);
|
||||
int sact_SP_TextCopy(int dno, int sno);
|
||||
int sact_CG_GetMetrics(int cg_no, union vm_value *cgm);
|
||||
|
||||
void DrawGraph_Copy(int dno, int dx, int dy, int sno, int sx, int sy, int w, int h);
|
||||
void DrawGraph_CopyBright(int dno, int dx, int dy, int sno, int sx, int sy, int w, int h, int rate);
|
||||
|
||||
@@ -283,6 +283,21 @@ int sact_SP_TextCopy(int dno, int sno)
|
||||
return 1;
|
||||
}
|
||||
|
||||
int sact_CG_GetMetrics(int cg_no, union vm_value *cgm)
|
||||
{
|
||||
struct cg_metrics metrics;
|
||||
if (!cg_get_metrics(cg_no, &metrics))
|
||||
return 0;
|
||||
cgm[0].i = metrics.w;
|
||||
cgm[1].i = metrics.h;
|
||||
cgm[2].i = metrics.bpp;
|
||||
cgm[3].i = metrics.has_pixel;
|
||||
cgm[4].i = metrics.has_alpha;
|
||||
cgm[5].i = metrics.pixel_pitch;
|
||||
cgm[6].i = metrics.alpha_pitch;
|
||||
return 1;
|
||||
}
|
||||
|
||||
//
|
||||
// --- DrawGraph.dll ---
|
||||
//
|
||||
|
||||
Reference in New Issue
Block a user