aboutsummaryrefslogtreecommitdiff
path: root/saga/image.cpp
diff options
context:
space:
mode:
authorPaweł Kołodziejski2004-05-01 09:19:35 +0000
committerPaweł Kołodziejski2004-05-01 09:19:35 +0000
commit1d649b1c06660fd820c08b5cd2c90cfceedfb8fc (patch)
tree51b24aaa09459e8df55d03788cdddb0ce9a51b34 /saga/image.cpp
parentae9f6dd86a36f2cdca91ff32b2a29b6ac3593f97 (diff)
downloadscummvm-rg350-1d649b1c06660fd820c08b5cd2c90cfceedfb8fc.tar.gz
scummvm-rg350-1d649b1c06660fd820c08b5cd2c90cfceedfb8fc.tar.bz2
scummvm-rg350-1d649b1c06660fd820c08b5cd2c90cfceedfb8fc.zip
indent
svn-id: r13698
Diffstat (limited to 'saga/image.cpp')
-rw-r--r--saga/image.cpp160
1 files changed, 36 insertions, 124 deletions
diff --git a/saga/image.cpp b/saga/image.cpp
index 99e63ae19d..f3bd6fd351 100644
--- a/saga/image.cpp
+++ b/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;
}