indent
svn-id: r13698
This commit is contained in:
parent
ae9f6dd86a
commit
1d649b1c06
5 changed files with 75 additions and 266 deletions
|
@ -20,13 +20,8 @@
|
|||
* $Header$
|
||||
*
|
||||
*/
|
||||
/*
|
||||
Description:
|
||||
|
||||
"I Have No Mouth" Intro sequence scene procedures
|
||||
|
||||
Notes:
|
||||
*/
|
||||
// "I Have No Mouth" Intro sequence scene procedures
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
@ -36,9 +31,6 @@
|
|||
|
||||
#include "reinherit.h"
|
||||
|
||||
/*
|
||||
* Uses the following modules:
|
||||
\*--------------------------------------------------------------------------*/
|
||||
#include "animation_mod.h"
|
||||
#include "cvar_mod.h"
|
||||
#include "events_mod.h"
|
||||
|
@ -48,126 +40,93 @@
|
|||
#include "text_mod.h"
|
||||
#include "palanim_mod.h"
|
||||
|
||||
/*
|
||||
* Begin module:
|
||||
\*--------------------------------------------------------------------------*/
|
||||
#include "scene.h"
|
||||
#include "ihnm_introproc.h"
|
||||
|
||||
namespace Saga {
|
||||
|
||||
R_SCENE_RESLIST IHNM_IntroMovie1RL[] = {
|
||||
|
||||
{30, SAGA_BG_IMAGE, 0, 0}
|
||||
,
|
||||
{30, SAGA_BG_IMAGE, 0, 0} ,
|
||||
{31, SAGA_ANIM_1, 0, 0}
|
||||
};
|
||||
|
||||
R_SCENE_DESC IHNM_IntroMovie1Desc = {
|
||||
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
IHNM_IntroMovie1RL,
|
||||
ARRAYSIZE(IHNM_IntroMovie1RL)
|
||||
|
||||
};
|
||||
|
||||
R_SCENE_RESLIST IHNM_IntroMovie2RL[] = {
|
||||
|
||||
{32, SAGA_BG_IMAGE, 0, 0}
|
||||
,
|
||||
{32, SAGA_BG_IMAGE, 0, 0} ,
|
||||
{33, SAGA_ANIM_1, 0, 0}
|
||||
};
|
||||
|
||||
R_SCENE_DESC IHNM_IntroMovie2Desc = {
|
||||
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
IHNM_IntroMovie2RL,
|
||||
ARRAYSIZE(IHNM_IntroMovie2RL)
|
||||
|
||||
};
|
||||
|
||||
R_SCENE_RESLIST IHNM_IntroMovie3RL[] = {
|
||||
|
||||
{34, SAGA_BG_IMAGE, 0, 0}
|
||||
,
|
||||
{34, SAGA_BG_IMAGE, 0, 0},
|
||||
{35, SAGA_ANIM_1, 0, 0}
|
||||
};
|
||||
|
||||
R_SCENE_DESC IHNM_IntroMovie3Desc = {
|
||||
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
IHNM_IntroMovie3RL,
|
||||
ARRAYSIZE(IHNM_IntroMovie3RL)
|
||||
|
||||
};
|
||||
|
||||
R_SCENE_RESLIST IHNM_IntroMovie4RL[] = {
|
||||
|
||||
{1227, SAGA_BG_IMAGE, 0, 0}
|
||||
,
|
||||
{1227, SAGA_BG_IMAGE, 0, 0},
|
||||
{1226, SAGA_ANIM_1, 0, 0}
|
||||
};
|
||||
|
||||
R_SCENE_DESC IHNM_IntroMovie4Desc = {
|
||||
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
IHNM_IntroMovie4RL,
|
||||
ARRAYSIZE(IHNM_IntroMovie4RL)
|
||||
|
||||
};
|
||||
|
||||
R_SCENE_QUEUE IHNM_IntroList[] = {
|
||||
{0, &IHNM_IntroMovie1Desc, BY_DESC, IHNM_IntroMovieProc1, 0}
|
||||
,
|
||||
{0, &IHNM_IntroMovie2Desc, BY_DESC, IHNM_IntroMovieProc2, 0}
|
||||
,
|
||||
{0, &IHNM_IntroMovie3Desc, BY_DESC, IHNM_IntroMovieProc3, 0}
|
||||
,
|
||||
{0, &IHNM_IntroMovie1Desc, BY_DESC, IHNM_IntroMovieProc1, 0} ,
|
||||
{0, &IHNM_IntroMovie2Desc, BY_DESC, IHNM_IntroMovieProc2, 0} ,
|
||||
{0, &IHNM_IntroMovie3Desc, BY_DESC, IHNM_IntroMovieProc3, 0} ,
|
||||
{0, &IHNM_IntroMovie4Desc, BY_DESC, IHNM_HateProc, 0}
|
||||
};
|
||||
|
||||
int IHNM_StartProc(void)
|
||||
{
|
||||
int IHNM_StartProc() {
|
||||
size_t n_introscenes;
|
||||
size_t i;
|
||||
|
||||
n_introscenes = ARRAYSIZE(IHNM_IntroList);
|
||||
|
||||
for (i = 0; i < n_introscenes; i++) {
|
||||
|
||||
SCENE_Queue(&IHNM_IntroList[i]);
|
||||
}
|
||||
|
||||
return R_SUCCESS;
|
||||
}
|
||||
|
||||
int IHNM_IntroMovieProc1(int param, R_SCENE_INFO * scene_info)
|
||||
{
|
||||
|
||||
int IHNM_IntroMovieProc1(int param, R_SCENE_INFO *scene_info) {
|
||||
R_EVENT event;
|
||||
|
||||
YS_IGNORE_PARAM(scene_info);
|
||||
|
||||
switch (param) {
|
||||
|
||||
case SCENE_BEGIN:
|
||||
|
||||
/* Background for intro scene is the first frame of the
|
||||
* intro animation; display it and set the palette
|
||||
\*-----------------------------------------------------*/
|
||||
// Background for intro scene is the first frame of the
|
||||
// intro animation; display it and set the palette
|
||||
event.type = R_ONESHOT_EVENT;
|
||||
event.code = R_BG_EVENT;
|
||||
event.op = EVENT_DISPLAY;
|
||||
event.param = SET_PALETTE;
|
||||
event.time = 0;
|
||||
|
||||
EVENT_Queue(&event);
|
||||
|
||||
ANIM_SetFrameTime(0, R_IHNM_INTRO_FRAMETIME);
|
||||
ANIM_SetFlag(0, ANIM_ENDSCENE);
|
||||
ANIM_Play(0, 0);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -175,24 +134,17 @@ int IHNM_IntroMovieProc1(int param, R_SCENE_INFO * scene_info)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int IHNM_IntroMovieProc2(int param, R_SCENE_INFO * scene_info)
|
||||
{
|
||||
|
||||
int IHNM_IntroMovieProc2(int param, R_SCENE_INFO *scene_info) {
|
||||
R_EVENT event;
|
||||
R_EVENT *q_event;
|
||||
|
||||
PALENTRY *pal;
|
||||
|
||||
static PALENTRY current_pal[R_PAL_ENTRIES];
|
||||
|
||||
YS_IGNORE_PARAM(scene_info);
|
||||
|
||||
switch (param) {
|
||||
|
||||
case SCENE_BEGIN:
|
||||
|
||||
/* Fade to black out of the intro CyberDreams logo anim
|
||||
* \*----------------------------------------------------- */
|
||||
// Fade to black out of the intro CyberDreams logo anim
|
||||
SYSGFX_GetCurrentPal(current_pal);
|
||||
|
||||
event.type = R_CONTINUOUS_EVENT;
|
||||
|
@ -204,9 +156,8 @@ int IHNM_IntroMovieProc2(int param, R_SCENE_INFO * scene_info)
|
|||
|
||||
q_event = EVENT_Queue(&event);
|
||||
|
||||
/* Background for intro scene is the first frame of the
|
||||
* intro animation; display it but don't set palette
|
||||
\*-----------------------------------------------------*/
|
||||
// Background for intro scene is the first frame of the
|
||||
// intro animation; display it but don't set palette
|
||||
event.type = R_ONESHOT_EVENT;
|
||||
event.code = R_BG_EVENT;
|
||||
event.op = EVENT_DISPLAY;
|
||||
|
@ -215,8 +166,7 @@ int IHNM_IntroMovieProc2(int param, R_SCENE_INFO * scene_info)
|
|||
|
||||
q_event = EVENT_Chain(q_event, &event);
|
||||
|
||||
/* Fade in from black to the scene background palette
|
||||
* \*----------------------------------------------------- */
|
||||
// Fade in from black to the scene background palette
|
||||
SCENE_GetBGPal(&pal);
|
||||
|
||||
event.type = R_CONTINUOUS_EVENT;
|
||||
|
@ -231,17 +181,14 @@ int IHNM_IntroMovieProc2(int param, R_SCENE_INFO * scene_info)
|
|||
ANIM_SetFlag(0, ANIM_LOOP);
|
||||
ANIM_Play(0, R_IHNM_PALFADE_TIME * 2);
|
||||
|
||||
/* Queue end of scene after looping animation for a while
|
||||
* \*----------------------------------------------------- */
|
||||
// Queue end of scene after looping animation for a while
|
||||
event.type = R_ONESHOT_EVENT;
|
||||
event.code = R_SCENE_EVENT;
|
||||
event.op = EVENT_END;
|
||||
event.time = R_IHNM_DGLOGO_TIME;
|
||||
|
||||
q_event = EVENT_Chain(q_event, &event);
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -249,24 +196,16 @@ int IHNM_IntroMovieProc2(int param, R_SCENE_INFO * scene_info)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int IHNM_IntroMovieProc3(int param, R_SCENE_INFO * scene_info)
|
||||
{
|
||||
|
||||
int IHNM_IntroMovieProc3(int param, R_SCENE_INFO *scene_info) {
|
||||
R_EVENT event;
|
||||
R_EVENT *q_event;
|
||||
|
||||
PALENTRY *pal;
|
||||
|
||||
static PALENTRY current_pal[R_PAL_ENTRIES];
|
||||
|
||||
YS_IGNORE_PARAM(scene_info);
|
||||
|
||||
switch (param) {
|
||||
|
||||
case SCENE_BEGIN:
|
||||
|
||||
/* Fade to black out of the intro DG logo anim
|
||||
* \*----------------------------------------------------- */
|
||||
// Fade to black out of the intro DG logo anim
|
||||
SYSGFX_GetCurrentPal(current_pal);
|
||||
|
||||
event.type = R_CONTINUOUS_EVENT;
|
||||
|
@ -278,9 +217,8 @@ int IHNM_IntroMovieProc3(int param, R_SCENE_INFO * scene_info)
|
|||
|
||||
q_event = EVENT_Queue(&event);
|
||||
|
||||
/* Background for intro scene is the first frame of the
|
||||
* intro animation; display it but don't set palette
|
||||
\*-----------------------------------------------------*/
|
||||
// Background for intro scene is the first frame of the
|
||||
// intro animation; display it but don't set palette
|
||||
event.type = R_ONESHOT_EVENT;
|
||||
event.code = R_BG_EVENT;
|
||||
event.op = EVENT_DISPLAY;
|
||||
|
@ -289,8 +227,7 @@ int IHNM_IntroMovieProc3(int param, R_SCENE_INFO * scene_info)
|
|||
|
||||
q_event = EVENT_Chain(q_event, &event);
|
||||
|
||||
/* Fade in from black to the scene background palette
|
||||
* \*----------------------------------------------------- */
|
||||
// Fade in from black to the scene background palette
|
||||
SCENE_GetBGPal(&pal);
|
||||
|
||||
event.type = R_CONTINUOUS_EVENT;
|
||||
|
@ -304,17 +241,14 @@ int IHNM_IntroMovieProc3(int param, R_SCENE_INFO * scene_info)
|
|||
|
||||
ANIM_Play(0, 0);
|
||||
|
||||
/* Queue end of scene after a while
|
||||
* \*----------------------------------------------------- */
|
||||
// Queue end of scene after a while
|
||||
event.type = R_ONESHOT_EVENT;
|
||||
event.code = R_SCENE_EVENT;
|
||||
event.op = EVENT_END;
|
||||
event.time = R_IHNM_TITLE_TIME;
|
||||
|
||||
q_event = EVENT_Chain(q_event, &event);
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -322,21 +256,15 @@ int IHNM_IntroMovieProc3(int param, R_SCENE_INFO * scene_info)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int IHNM_HateProc(int param, R_SCENE_INFO * scene_info)
|
||||
{
|
||||
|
||||
int IHNM_HateProc(int param, R_SCENE_INFO *scene_info) {
|
||||
R_EVENT event;
|
||||
R_EVENT *q_event;
|
||||
|
||||
YS_IGNORE_PARAM(scene_info);
|
||||
|
||||
switch (param) {
|
||||
|
||||
case SCENE_BEGIN:
|
||||
|
||||
/* Background for intro scene is the first frame of the
|
||||
* intro animation; display it and set the palette
|
||||
\*-----------------------------------------------------*/
|
||||
// Background for intro scene is the first frame of the
|
||||
// intro animation; display it and set the palette
|
||||
event.type = R_ONESHOT_EVENT;
|
||||
event.code = R_BG_EVENT;
|
||||
event.op = EVENT_DISPLAY;
|
||||
|
@ -347,9 +275,7 @@ int IHNM_HateProc(int param, R_SCENE_INFO * scene_info)
|
|||
|
||||
ANIM_SetFlag(0, ANIM_LOOP);
|
||||
ANIM_Play(0, 0);
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -20,13 +20,8 @@
|
|||
* $Header$
|
||||
*
|
||||
*/
|
||||
/*
|
||||
Description:
|
||||
|
||||
Intro sequence scene procedures header file
|
||||
|
||||
Notes:
|
||||
*/
|
||||
// Intro sequence scene procedures header file
|
||||
|
||||
#ifndef SAGA_ITE_INTRO_H_
|
||||
#define SAGA_ITE_INTRO_H_
|
||||
|
@ -40,5 +35,4 @@ namespace Saga {
|
|||
|
||||
} // End of namespace Saga
|
||||
|
||||
#endif /* R_IHNM_INTRO_H_ */
|
||||
/* end "r_ihnm_introproc.h */
|
||||
#endif
|
||||
|
|
160
saga/image.cpp
160
saga/image.cpp
|
@ -20,34 +20,21 @@
|
|||
* $Header$
|
||||
*
|
||||
*/
|
||||
/*
|
||||
Description:
|
||||
|
||||
SAGA Image resource management routines
|
||||
|
||||
Notes:
|
||||
*/
|
||||
// SAGA Image resource management routines
|
||||
|
||||
#include "reinherit.h"
|
||||
|
||||
#include "yslib.h"
|
||||
|
||||
/*
|
||||
* Uses the following modules:
|
||||
\*--------------------------------------------------------------------------*/
|
||||
#include "game_mod.h"
|
||||
|
||||
/*
|
||||
* Begin module
|
||||
\*--------------------------------------------------------------------------*/
|
||||
#include "image_mod.h"
|
||||
#include "image.h"
|
||||
|
||||
namespace Saga {
|
||||
|
||||
static int granulate(int value, int granularity)
|
||||
{
|
||||
|
||||
static int granulate(int value, int granularity) {
|
||||
int remainder;
|
||||
|
||||
if (value == 0)
|
||||
|
@ -63,27 +50,18 @@ static int granulate(int value, int granularity)
|
|||
} else {
|
||||
return (granularity - remainder + value);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int
|
||||
IMG_DecodeBGImage(const byte * image_data,
|
||||
size_t image_size,
|
||||
byte ** output_buf, size_t * output_buf_len, int *w, int *h)
|
||||
{
|
||||
|
||||
int IMG_DecodeBGImage(const byte * image_data, size_t image_size,
|
||||
byte ** output_buf, size_t * output_buf_len, int *w, int *h) {
|
||||
R_IMAGE_HEADER hdr;
|
||||
int modex_height;
|
||||
|
||||
const byte *RLE_data_ptr;
|
||||
size_t RLE_data_len;
|
||||
|
||||
byte *decode_buf;
|
||||
size_t decode_buf_len;
|
||||
|
||||
byte *out_buf;
|
||||
size_t out_buf_len;
|
||||
|
||||
const byte *read_p = image_data;
|
||||
|
||||
if (image_size <= SAGA_IMAGE_DATA_OFFSET) {
|
||||
|
@ -109,19 +87,15 @@ IMG_DecodeBGImage(const byte * image_data,
|
|||
|
||||
if (DecodeBGImageRLE(RLE_data_ptr,
|
||||
RLE_data_len, decode_buf, decode_buf_len) != R_SUCCESS) {
|
||||
|
||||
free(decode_buf);
|
||||
free(out_buf);
|
||||
|
||||
return R_FAILURE;
|
||||
}
|
||||
|
||||
UnbankBGImage(out_buf, decode_buf, hdr.width, hdr.height);
|
||||
|
||||
/* For some reason bg images in IHNM are upside down
|
||||
* \*------------------------------------------------------------- */
|
||||
// For some reason bg images in IHNM are upside down
|
||||
if (GAME_GetGameType() == R_GAMETYPE_IHNM) {
|
||||
|
||||
FlipImage(out_buf, hdr.width, hdr.height);
|
||||
}
|
||||
|
||||
|
@ -136,11 +110,7 @@ IMG_DecodeBGImage(const byte * image_data,
|
|||
return R_SUCCESS;
|
||||
}
|
||||
|
||||
int
|
||||
DecodeBGImageRLE(const byte * inbuf,
|
||||
size_t inbuf_len, byte * outbuf, size_t outbuf_len)
|
||||
{
|
||||
|
||||
int DecodeBGImageRLE(const byte *inbuf, size_t inbuf_len, byte *outbuf, size_t outbuf_len) {
|
||||
const byte *inbuf_ptr;
|
||||
byte *outbuf_ptr;
|
||||
uint16 inbuf_remain;
|
||||
|
@ -185,17 +155,13 @@ DecodeBGImageRLE(const byte * inbuf,
|
|||
mark_byte = *inbuf_ptr++;
|
||||
inbuf_remain--;
|
||||
|
||||
test_byte = mark_byte & 0xC0; /* Mask all but two high order bits */
|
||||
test_byte = mark_byte & 0xC0; // Mask all but two high order bits
|
||||
|
||||
switch (test_byte) {
|
||||
|
||||
case 0xC0: /* 1100 0000 */
|
||||
|
||||
/* Uncompressed run follows: Max runlength 63 */
|
||||
case 0xC0: // 1100 0000
|
||||
// Uncompressed run follows: Max runlength 63
|
||||
runcount = mark_byte & 0x3f;
|
||||
|
||||
if ((inbuf_remain < runcount) ||
|
||||
(outbuf_remain < runcount)) {
|
||||
if ((inbuf_remain < runcount) || (outbuf_remain < runcount)) {
|
||||
return R_FAILURE;
|
||||
}
|
||||
|
||||
|
@ -206,14 +172,10 @@ DecodeBGImageRLE(const byte * inbuf,
|
|||
inbuf_remain -= runcount;
|
||||
outbuf_remain -= runcount;
|
||||
continue;
|
||||
|
||||
break;
|
||||
|
||||
case 0x80: /* 1000 0000 */
|
||||
|
||||
/* Compressed run follows: Max runlength 63 */
|
||||
case 0x80: // 1000 0000
|
||||
// Compressed run follows: Max runlength 63
|
||||
runcount = (mark_byte & 0x3f) + 3;
|
||||
|
||||
if (!inbuf_remain || (outbuf_remain < runcount)) {
|
||||
return R_FAILURE;
|
||||
}
|
||||
|
@ -229,18 +191,14 @@ DecodeBGImageRLE(const byte * inbuf,
|
|||
|
||||
break;
|
||||
|
||||
case 0x40: /* 0100 0000 */
|
||||
|
||||
/* Repeat decoded sequence from output stream:
|
||||
* Max runlength 10 */
|
||||
case 0x40: // 0100 0000
|
||||
// Repeat decoded sequence from output stream:
|
||||
// Max runlength 10
|
||||
|
||||
runcount = ((mark_byte >> 3) & 0x07U) + 3;
|
||||
|
||||
backtrack_amount = *inbuf_ptr;
|
||||
|
||||
if (!inbuf_remain ||
|
||||
(backtrack_amount > (outbuf_ptr - outbuf)) ||
|
||||
(runcount > outbuf_remain)) {
|
||||
if (!inbuf_remain || (backtrack_amount > (outbuf_ptr - outbuf)) || (runcount > outbuf_remain)) {
|
||||
return R_FAILURE;
|
||||
}
|
||||
|
||||
|
@ -255,25 +213,21 @@ DecodeBGImageRLE(const byte * inbuf,
|
|||
|
||||
outbuf_remain -= runcount;
|
||||
continue;
|
||||
|
||||
break;
|
||||
|
||||
default: /* 0000 0000 */
|
||||
default: // 0000 0000
|
||||
break;
|
||||
}
|
||||
|
||||
/* Mask all but the third and fourth highest order bits */
|
||||
// Mask all but the third and fourth highest order bits
|
||||
test_byte = mark_byte & 0x30;
|
||||
|
||||
switch (test_byte) {
|
||||
|
||||
case 0x30: /* 0011 0000 */
|
||||
/* Bitfield compression */
|
||||
|
||||
case 0x30: // 0011 0000
|
||||
// Bitfield compression
|
||||
runcount = (mark_byte & 0x0F) + 1;
|
||||
|
||||
if ((inbuf_remain < (runcount + 2)) ||
|
||||
(outbuf_remain < (runcount * 8))) {
|
||||
if ((inbuf_remain < (runcount + 2)) || (outbuf_remain < (runcount * 8))) {
|
||||
return R_FAILURE;
|
||||
}
|
||||
|
||||
|
@ -281,19 +235,14 @@ DecodeBGImageRLE(const byte * inbuf,
|
|||
bitfield_byte2 = *inbuf_ptr++;
|
||||
|
||||
for (c = 0; c < runcount; c++) {
|
||||
|
||||
bitfield = *inbuf_ptr;
|
||||
|
||||
for (b = 0; b < 8; b++) {
|
||||
|
||||
if (bitfield & 0x80) {
|
||||
*outbuf_ptr = bitfield_byte2;
|
||||
} else {
|
||||
*outbuf_ptr = bitfield_byte1;
|
||||
}
|
||||
|
||||
bitfield <<= 1;
|
||||
|
||||
outbuf_ptr++;
|
||||
}
|
||||
inbuf_ptr++;
|
||||
|
@ -302,16 +251,11 @@ DecodeBGImageRLE(const byte * inbuf,
|
|||
inbuf_remain -= (runcount + 2);
|
||||
outbuf_remain -= (runcount * 8);
|
||||
continue;
|
||||
|
||||
break;
|
||||
|
||||
case 0x20: /* 0010 0000 */
|
||||
/* Uncompressed run follows */
|
||||
|
||||
case 0x20: // 0010 0000
|
||||
// Uncompressed run follows
|
||||
runcount = ((mark_byte & 0x0F) << 8) + *inbuf_ptr;
|
||||
|
||||
if ((inbuf_remain < (runcount + 1)) ||
|
||||
(outbuf_remain < runcount)) {
|
||||
if ((inbuf_remain < (runcount + 1)) || (outbuf_remain < runcount)) {
|
||||
return R_FAILURE;
|
||||
}
|
||||
|
||||
|
@ -327,12 +271,9 @@ DecodeBGImageRLE(const byte * inbuf,
|
|||
|
||||
break;
|
||||
|
||||
case 0x10: /* 0001 0000 */
|
||||
/* Repeat decoded sequence from output stream */
|
||||
|
||||
backtrack_amount =
|
||||
((mark_byte & 0x0F) << 8) + *inbuf_ptr;
|
||||
|
||||
case 0x10: // 0001 0000
|
||||
// Repeat decoded sequence from output stream
|
||||
backtrack_amount = ((mark_byte & 0x0F) << 8) + *inbuf_ptr;
|
||||
if (inbuf_remain < 2) {
|
||||
return R_FAILURE;
|
||||
}
|
||||
|
@ -340,8 +281,7 @@ DecodeBGImageRLE(const byte * inbuf,
|
|||
inbuf_ptr++;
|
||||
runcount = *inbuf_ptr++;
|
||||
|
||||
if ((backtrack_amount > (outbuf_ptr - outbuf)) ||
|
||||
(outbuf_remain < runcount)) {
|
||||
if ((backtrack_amount > (outbuf_ptr - outbuf)) || (outbuf_remain < runcount)) {
|
||||
return R_FAILURE;
|
||||
}
|
||||
|
||||
|
@ -354,23 +294,17 @@ DecodeBGImageRLE(const byte * inbuf,
|
|||
inbuf_remain -= 2;
|
||||
outbuf_remain -= runcount;
|
||||
continue;
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
return R_FAILURE;
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
} /* end while */
|
||||
}
|
||||
|
||||
return R_SUCCESS;
|
||||
}
|
||||
|
||||
int FlipImage(byte * img_buf, int columns, int scanlines)
|
||||
{
|
||||
|
||||
int FlipImage(byte *img_buf, int columns, int scanlines) {
|
||||
int line;
|
||||
byte *tmp_scan;
|
||||
|
||||
|
@ -388,11 +322,9 @@ int FlipImage(byte * img_buf, int columns, int scanlines)
|
|||
flip_p2 = img_buf + (columns * (scanlines - 1));
|
||||
|
||||
for (line = 0; line < flipcount; line++) {
|
||||
|
||||
memcpy(tmp_scan, flip_p1, columns);
|
||||
memcpy(flip_p1, flip_p2, columns);
|
||||
memcpy(flip_p2, tmp_scan, columns);
|
||||
|
||||
flip_p1 += columns;
|
||||
flip_p2 -= columns;
|
||||
}
|
||||
|
@ -402,23 +334,15 @@ int FlipImage(byte * img_buf, int columns, int scanlines)
|
|||
return R_SUCCESS;
|
||||
}
|
||||
|
||||
int
|
||||
UnbankBGImage(byte * dst_buf,
|
||||
const byte * src_buf, int columns, int scanlines)
|
||||
{
|
||||
|
||||
int UnbankBGImage(byte *dst_buf, const byte *src_buf, int columns, int scanlines) {
|
||||
int x, y;
|
||||
int temp;
|
||||
|
||||
int quadruple_rows;
|
||||
int remain_rows;
|
||||
|
||||
int rowjump_src;
|
||||
int rowjump_dest;
|
||||
|
||||
const byte *src_p;
|
||||
byte *dst_p;
|
||||
|
||||
const byte *srcptr1, *srcptr2, *srcptr3, *srcptr4;
|
||||
byte *dstptr1, *dstptr2, *dstptr3, *dstptr4;
|
||||
|
||||
|
@ -443,9 +367,8 @@ UnbankBGImage(byte * dst_buf,
|
|||
rowjump_src = columns * 4;
|
||||
rowjump_dest = columns * 4;
|
||||
|
||||
/* Unbank groups of 4 first */
|
||||
// Unbank groups of 4 first
|
||||
for (y = 0; y < quadruple_rows; y += 4) {
|
||||
|
||||
for (x = 0; x < columns; x++) {
|
||||
temp = x * 4;
|
||||
dstptr1[x] = srcptr1[temp];
|
||||
|
@ -454,10 +377,9 @@ UnbankBGImage(byte * dst_buf,
|
|||
dstptr4[x] = srcptr4[temp];
|
||||
}
|
||||
|
||||
/* This is to avoid generating invalid pointers -
|
||||
* usually innocuous, but undefined */
|
||||
// This is to avoid generating invalid pointers -
|
||||
// usually innocuous, but undefined
|
||||
if (y < quadruple_rows - 4) {
|
||||
|
||||
dstptr1 += rowjump_dest;
|
||||
dstptr2 += rowjump_dest;
|
||||
dstptr3 += rowjump_dest;
|
||||
|
@ -467,35 +389,29 @@ UnbankBGImage(byte * dst_buf,
|
|||
srcptr3 += rowjump_src;
|
||||
srcptr4 += rowjump_src;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* Unbank rows remaining */
|
||||
// Unbank rows remaining
|
||||
switch (remain_rows) {
|
||||
|
||||
case 1:
|
||||
dstptr1 += rowjump_dest;
|
||||
srcptr1 += rowjump_src;
|
||||
|
||||
for (x = 0; x < columns; x++) {
|
||||
temp = x * 4;
|
||||
dstptr1[x] = srcptr1[temp];
|
||||
}
|
||||
break;
|
||||
|
||||
case 2:
|
||||
dstptr1 += rowjump_dest;
|
||||
dstptr2 += rowjump_dest;
|
||||
srcptr1 += rowjump_src;
|
||||
srcptr2 += rowjump_src;
|
||||
|
||||
for (x = 0; x < columns; x++) {
|
||||
temp = x * 4;
|
||||
dstptr1[x] = srcptr1[temp];
|
||||
dstptr2[x] = srcptr2[temp];
|
||||
}
|
||||
break;
|
||||
|
||||
case 3:
|
||||
dstptr1 += rowjump_dest;
|
||||
dstptr2 += rowjump_dest;
|
||||
|
@ -503,7 +419,6 @@ UnbankBGImage(byte * dst_buf,
|
|||
srcptr1 += rowjump_src;
|
||||
srcptr2 += rowjump_src;
|
||||
srcptr3 += rowjump_src;
|
||||
|
||||
for (x = 0; x < columns; x++) {
|
||||
temp = x * 4;
|
||||
dstptr1[x] = srcptr1[temp];
|
||||
|
@ -511,16 +426,13 @@ UnbankBGImage(byte * dst_buf,
|
|||
dstptr3[x] = srcptr3[temp];
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return R_SUCCESS;
|
||||
}
|
||||
|
||||
const byte *IMG_GetImagePal(const byte * image_data, size_t image_size)
|
||||
{
|
||||
const byte *IMG_GetImagePal(const byte *image_data, size_t image_size) {
|
||||
if (image_size <= SAGA_IMAGE_HEADER_LEN) {
|
||||
return NULL;
|
||||
}
|
||||
|
|
24
saga/image.h
24
saga/image.h
|
@ -20,13 +20,8 @@
|
|||
* $Header$
|
||||
*
|
||||
*/
|
||||
/*
|
||||
Description:
|
||||
|
||||
SAGA Image resource management header file
|
||||
|
||||
Notes:
|
||||
*/
|
||||
// SAGA Image resource management header file
|
||||
|
||||
#ifndef SAGA_IMAGE_H__
|
||||
#define SAGA_IMAGE_H__
|
||||
|
@ -40,25 +35,16 @@ namespace Saga {
|
|||
#define SAGA_IMAGE_HEADER_LEN 8
|
||||
|
||||
struct R_IMAGE_HEADER {
|
||||
|
||||
int width;
|
||||
int height;
|
||||
int unknown4;
|
||||
int unknown6;
|
||||
|
||||
};
|
||||
|
||||
int
|
||||
DecodeBGImageRLE(const byte * inbuf,
|
||||
size_t inbuf_len, byte * outbuf, size_t outbuf_len);
|
||||
|
||||
int FlipImage(byte * img_buf, int columns, int scanlines);
|
||||
|
||||
int
|
||||
UnbankBGImage(byte * dest_buf,
|
||||
const byte * src_buf, int columns, int scanlines);
|
||||
int DecodeBGImageRLE(const byte *inbuf, size_t inbuf_len, byte *outbuf, size_t outbuf_len);
|
||||
int FlipImage(byte *img_buf, int columns, int scanlines);
|
||||
int UnbankBGImage(byte * dest_buf, const byte * src_buf, int columns, int scanlines);
|
||||
|
||||
} // End of namespace Saga
|
||||
|
||||
#endif /* R_IMAGE_H__ */
|
||||
/* end "r_image.h" */
|
||||
#endif
|
||||
|
|
|
@ -20,27 +20,18 @@
|
|||
* $Header$
|
||||
*
|
||||
*/
|
||||
/*
|
||||
Description:
|
||||
|
||||
SAGA Image resource management routines
|
||||
|
||||
Notes:
|
||||
*/
|
||||
// SAGA Image resource management routines
|
||||
|
||||
#ifndef SAGA_IMAGE_MOD_H_
|
||||
#define SAGA_IMAGE_MOD_H_
|
||||
|
||||
namespace Saga {
|
||||
|
||||
int
|
||||
IMG_DecodeBGImage(const byte * image_data,
|
||||
size_t image_size,
|
||||
byte ** output_buf, size_t * output_buf_len, int *w, int *h);
|
||||
|
||||
const byte *IMG_GetImagePal(const byte * image_data, size_t image_size);
|
||||
int IMG_DecodeBGImage(const byte *image_data, size_t image_size,
|
||||
byte **output_buf, size_t *output_buf_len, int *w, int *h);
|
||||
const byte *IMG_GetImagePal(const byte *image_data, size_t image_size);
|
||||
|
||||
} // End of namespace Saga
|
||||
|
||||
#endif /* R_IMAGE_MOD_H_ */
|
||||
/* end "r_image_mod.h" */
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue