Skip to content
Snippets Groups Projects
Commit 07bf163c authored by Marcus Comstedt's avatar Marcus Comstedt
Browse files

Fixed basic mipmap support (only decodes fullsize texture for now).

Rev: src/modules/Image/encodings/pvr.c:1.4
parent 902a5594
No related branches found
No related tags found
No related merge requests found
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
#include <ctype.h> #include <ctype.h>
#include "stralloc.h" #include "stralloc.h"
RCSID("$Id: pvr.c,v 1.3 2000/02/27 13:06:45 marcus Exp $"); RCSID("$Id: pvr.c,v 1.4 2000/02/27 14:01:31 marcus Exp $");
#include "pike_macros.h" #include "pike_macros.h"
#include "object.h" #include "object.h"
#include "constants.h" #include "constants.h"
...@@ -268,13 +268,15 @@ void img_pvr_decode(INT32 args,int header_only) ...@@ -268,13 +268,15 @@ void img_pvr_decode(INT32 args,int header_only)
len=str->len; len=str->len;
pop_n_elems(args-1); pop_n_elems(args-1);
if(len >= 12 && !strncmp(s, "GBIX", 4) && if(len >= 12 && !strncmp(s, "GBIX", 4)) {
s[4]==4 && s[5]==0 && s[6]==0 && s[7]==0) { INT32 l = s[4]|(s[5]<<8)|(s[6]<<16)|(s[7]<<24);
push_text("global_index"); if(l>=4 && l<=len-8) {
push_int(s[8]|(s[9]<<8)|(s[10]<<16)|(s[11]<<24)); push_text("global_index");
n++; push_int(s[8]|(s[9]<<8)|(s[10]<<16)|(s[11]<<24));
len -= 12; n++;
s += 12; len -= l+8;
s += l+8;
}
} }
if(len < 16 || strncmp(s, "PVRT", 4)) if(len < 16 || strncmp(s, "PVRT", 4))
...@@ -313,10 +315,12 @@ void img_pvr_decode(INT32 args,int header_only) ...@@ -313,10 +315,12 @@ void img_pvr_decode(INT32 args,int header_only)
int twiddle=0, hasalpha=0, bpp=0; int twiddle=0, hasalpha=0, bpp=0;
struct object *o; struct object *o;
struct image *img; struct image *img;
INT32 mipmap=0;
switch(attr&0xff00) { switch(attr&0xff00) {
case MODE_TWIDDLE:
case MODE_TWIDDLE_MIPMAP: case MODE_TWIDDLE_MIPMAP:
mipmap = 1;
case MODE_TWIDDLE:
twiddle = 1; twiddle = 1;
if(w != h || w<8 || w>1024 || (w&(w-1))) if(w != h || w<8 || w>1024 || (w&(w-1)))
error("invalid size for twiddle texture\n"); error("invalid size for twiddle texture\n");
...@@ -336,7 +340,7 @@ void img_pvr_decode(INT32 args,int header_only) ...@@ -336,7 +340,7 @@ void img_pvr_decode(INT32 args,int header_only)
case MODE_CLUT4_MIPMAP: case MODE_CLUT4_MIPMAP:
case MODE_CLUT8: case MODE_CLUT8:
case MODE_CLUT8_MIPMAP: case MODE_CLUT8_MIPMAP:
error("palette PVRs not supported\n"); error("palette PVRs not supported\n");
default: default:
error("unknown PVR format\n"); error("unknown PVR format\n");
} }
...@@ -358,9 +362,15 @@ void img_pvr_decode(INT32 args,int header_only) ...@@ -358,9 +362,15 @@ void img_pvr_decode(INT32 args,int header_only)
error("unknown PVR color mode\n"); error("unknown PVR color mode\n");
} }
if(len < (INT32)bpp*h*w) if(mipmap)
for(x=w; x>>=1;)
mipmap += x*x;
if(len < (INT32)(bpp*(h*w+mipmap)))
error("short PVRT chunk\n"); error("short PVRT chunk\n");
s += bpp*mipmap;
push_text("image"); push_text("image");
push_int(w); push_int(w);
push_int(h); push_int(h);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment