]> git.rm.cloudns.org Git - xonotic/darkplaces.git/commitdiff
remove CRLFs added by last commit
authorRudolf Polzer <divverent@alientrap.org>
Sun, 20 Mar 2011 19:53:04 +0000 (20:53 +0100)
committerRudolf Polzer <divverent@alientrap.org>
Sun, 20 Mar 2011 19:53:20 +0000 (20:53 +0100)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@10939 d7cf8633-e32d-0410-b094-e92efae38249
::stable-branch::merge=ee0a2f637d2a39ad1838c6dc1f0597cbbd135d38

cl_video_jamdecode.c
shader_hlsl.h

index eb6f922ec64c87e1c92a4ad65dce78122871d549..55a4983708aa7f5740433bacb1dd268ce23efc20 100644 (file)
-// JAM format decoder, used by Blood Omnicide\r
-\r
-typedef struct jamdecodestream_s\r
-{\r
-       int error;\r
-\r
-       qfile_t *file;\r
-       double info_framerate;\r
-       unsigned int info_frames;\r
-       unsigned int info_imagewidth;\r
-       unsigned int info_imageheight;\r
-       int doubleres;\r
-       float colorscale;\r
-       unsigned char colorsub;\r
-       float stipple;\r
-\r
-       // info used durign decoding\r
-       unsigned char *videopixels;\r
-       unsigned char *compressed;\r
-       unsigned char *framedata;\r
-       unsigned char *prevframedata;\r
-       unsigned char colormap[768];\r
-       unsigned int framesize;\r
-       unsigned int framenum;\r
-\r
-       // channel the sound file is being played on\r
-       int sndchan;\r
-}\r
-jamdecodestream_t;\r
-\r
-#define JAMDECODEERROR_NONE                0\r
-#define JAMDECODEERROR_EOF                 1\r
-#define JAMDECODEERROR_READERROR           2\r
-#define JAMDECODEERROR_BAD_FRAME_HEADER    3\r
-#define JAMDECODEERROR_BAD_OUTPUT_SIZE     4\r
-#define JAMDECODEERROR_BAD_COLORMAP        5\r
-\r
-// opens a stream\r
-void jam_close(void *stream);\r
-unsigned int jam_getwidth(void *stream);\r
-unsigned int jam_getheight(void *stream);\r
-double jam_getframerate(void *stream);\r
-int jam_video(void *stream, void *imagedata, unsigned int Rmask, unsigned int Gmask, unsigned int Bmask, unsigned int bytesperpixel, int imagebytesperrow);\r
-void *jam_open(clvideo_t *video, char *filename, const char **errorstring)\r
-{\r
-       unsigned char jamHead[16];\r
-       char *wavename;\r
-       jamdecodestream_t *s;\r
-       qfile_t *file;\r
-\r
-       s = (jamdecodestream_t *)Z_Malloc(sizeof(jamdecodestream_t));\r
-       if (s != NULL)\r
-       {\r
-               if ((file = FS_OpenVirtualFile(filename, false)))\r
-               {\r
-                       s->file = file;\r
-                       if (FS_Read(s->file, &jamHead, 16))\r
-                       {\r
-                               if (!memcmp(jamHead, "JAM", 3))\r
-                               {\r
-                                       s->info_imagewidth = LittleLong(*(jamHead + 4));\r
-                                       s->info_imageheight = LittleLong(*(jamHead + 8));\r
-                                       s->info_frames = LittleLong(*(jamHead + 12));\r
-                                       s->info_framerate = 15;\r
-                                       s->doubleres = 0;\r
-                                       s->colorscale = 0.70;\r
-                                       s->colorsub = 8;\r
-                                       s->stipple = 0.4;\r
-                                       s->framesize = s->info_imagewidth * s->info_imageheight;\r
-                                       if (s->framesize > 0)\r
-                                       {\r
-                                               s->compressed = (unsigned char *)Z_Malloc(s->framesize);\r
-                                               s->framedata = (unsigned char *)Z_Malloc(s->framesize * 2);\r
-                                               s->prevframedata = (unsigned char *)Z_Malloc(s->framesize * 2);\r
-                                               s->videopixels = (unsigned char *)Z_Malloc(s->framesize * 4); // bgra, doubleres\r
-                                               if (s->compressed != NULL && s->framedata != NULL && s->prevframedata != NULL && s->videopixels != NULL)\r
-                                               {\r
-                                                       size_t namelen;\r
-\r
-                                                       namelen = strlen(filename) + 10;\r
-                                                       wavename = (char *)Z_Malloc(namelen);\r
-                                                       if (wavename)\r
-                                                       {\r
-                                                               sfx_t* sfx;\r
-\r
-                                                               FS_StripExtension(filename, wavename, namelen);\r
-                                                               strlcat(wavename, ".wav", namelen);\r
-                                                               sfx = S_PrecacheSound(wavename, false, false);\r
-                                                               if (sfx != NULL)\r
-                                                                       s->sndchan = S_StartSound (-1, 0, sfx, vec3_origin, 1.0f, 0);\r
-                                                               else\r
-                                                                       s->sndchan = -1;\r
-                                                               Z_Free(wavename);\r
-                                                       }\r
-                                                       // all is well...\r
-                                                       // set the module functions\r
-                                                       s->framenum = 0;\r
-                                                       video->close = jam_close;\r
-                                                       video->getwidth = jam_getwidth;\r
-                                                       video->getheight = jam_getheight;\r
-                                                       video->getframerate = jam_getframerate;\r
-                                                       video->decodeframe = jam_video;\r
-                                                       return s;\r
-                                               }\r
-                                               else if (errorstring != NULL)\r
-                                                       *errorstring = "unable to allocate memory for stream info structure";\r
-                                               if (s->compressed != NULL)\r
-                                                       Z_Free(s->compressed);\r
-                                               if (s->framedata != NULL)\r
-                                                       Z_Free(s->framedata);\r
-                                               if (s->prevframedata != NULL)\r
-                                                       Z_Free(s->prevframedata);\r
-                                               if (s->videopixels != NULL)\r
-                                                       Z_Free(s->videopixels);\r
-                                       }\r
-                                       else if (errorstring != NULL)\r
-                                               *errorstring = "bad framesize";\r
-                               }\r
-                               else if (errorstring != NULL)\r
-                                       *errorstring = "not JAM videofile";\r
-                       }\r
-                       else if (errorstring != NULL)\r
-                               *errorstring = "unexpected EOF";\r
-                       FS_Close(file);\r
-               }\r
-               else if (errorstring != NULL)\r
-                       *errorstring = "unable to open videofile";\r
-               Z_Free(s);\r
-       }\r
-       else if (errorstring != NULL)\r
-               *errorstring = "unable to allocate memory for stream info structure";\r
-       return NULL;\r
-}\r
-\r
-// closes a stream\r
-void jam_close(void *stream)\r
-{\r
-       jamdecodestream_t *s = (jamdecodestream_t *)stream;\r
-       if (s == NULL)\r
-               return;\r
-       Z_Free(s->compressed);\r
-       Z_Free(s->framedata);\r
-       Z_Free(s->prevframedata);\r
-       Z_Free(s->videopixels);\r
-       if (s->sndchan != -1)\r
-               S_StopChannel(s->sndchan, true);\r
-       if (s->file)\r
-               FS_Close(s->file);\r
-       Z_Free(s);\r
-}\r
-\r
-// returns the width of the image data\r
-unsigned int jam_getwidth(void *stream)\r
-{\r
-       jamdecodestream_t *s = (jamdecodestream_t *)stream;\r
-       if (s->doubleres)\r
-               return s->info_imagewidth * 2;\r
-       return s->info_imagewidth;\r
-}\r
-\r
-// returns the height of the image data\r
-unsigned int jam_getheight(void *stream)\r
-{\r
-       jamdecodestream_t *s = (jamdecodestream_t *)stream;\r
-       if (s->doubleres)\r
-               return s->info_imageheight * 2;\r
-       return s->info_imageheight;\r
-}\r
-\r
-// returns the framerate of the stream\r
-double jam_getframerate(void *stream)\r
-{\r
-       jamdecodestream_t *s = (jamdecodestream_t *)stream;\r
-       return s->info_framerate;\r
-}\r
-\r
-\r
-// decode JAM frame\r
-void jam_decodeframe(unsigned char *inbuf, unsigned char *outbuf, unsigned char *prevbuf, int outsize, int frametype)\r
-{\r
-       unsigned char *srcptr, *destptr, *prevptr;\r
-       int bytesleft;\r
-       unsigned int mark;\r
-       unsigned short int bits;\r
-       int rep;\r
-       int backoffs;\r
-       unsigned char *back;\r
-       int i;\r
-\r
-       srcptr = inbuf;\r
-       destptr = outbuf;\r
-       prevptr = prevbuf;\r
-       bytesleft = outsize;\r
-\r
-       if (frametype == 2)\r
-       {\r
-               memcpy(outbuf, inbuf, outsize);\r
-               return;\r
-       }\r
-       while(bytesleft > 0)\r
-       {\r
-               memcpy(&mark, srcptr, 4);\r
-               srcptr += 4;\r
-               for(i=0; i<32 && bytesleft > 0; i++,mark=mark>>1)\r
-               {\r
-                       if(mark & 1)\r
-                       {\r
-                               *destptr = *srcptr;\r
-                               destptr ++;\r
-                               prevptr ++;\r
-                               srcptr ++;\r
-                               bytesleft --;\r
-                       }\r
-                       else\r
-                       {\r
-                               bits = srcptr[0] + 256*srcptr[1];\r
-                               rep = (bits >> 11) + 3;\r
-                               if(frametype == 1)\r
-                               {\r
-                                       backoffs = 0x821 - (bits & 0x7ff);\r
-                                       back = destptr - backoffs;\r
-                               }\r
-                               else\r
-                               {\r
-                                       backoffs = 0x400 - (bits & 0x7ff);\r
-                                       back = prevptr - backoffs;\r
-                               }\r
-                               srcptr += 2;\r
-                               memcpy(destptr, back, rep);\r
-                               destptr += rep;\r
-                               prevptr += rep;\r
-                               bytesleft -= rep;\r
-                       }\r
-               }\r
-       }\r
-}\r
-\r
-// decodes a video frame to the supplied output pixels\r
-int jam_video(void *stream, void *imagedata, unsigned int Rmask, unsigned int Gmask, unsigned int Bmask, unsigned int bytesperpixel, int imagebytesperrow)\r
-{\r
-       unsigned char frameHead[16], *b;\r
-       unsigned int compsize, outsize, i, j;\r
-       jamdecodestream_t *s = (jamdecodestream_t *)stream;\r
-\r
-       s->error = DPVSIMPLEDECODEERROR_NONE;\r
-       if (s->framenum < s->info_frames)\r
-       {\r
-readframe:\r
-               if (FS_Read(s->file, &frameHead, 16))\r
-               {\r
-                       compsize = LittleLong(*(frameHead + 8)) - 16;\r
-                       outsize = LittleLong(*(frameHead + 12));\r
-                       if (compsize < 0 || compsize > s->framesize || outsize < 0 || outsize > s->framesize)\r
-                               s->error = JAMDECODEERROR_BAD_FRAME_HEADER;\r
-                       else if (FS_Read(s->file, s->compressed, compsize))\r
-                       {\r
-                               // palette goes interleaved with special flag\r
-                               if (frameHead[0] == 2)\r
-                               {\r
-                                       if (compsize == 768)\r
-                                       {\r
-                                               memcpy(s->colormap, s->compressed, 768);\r
-                                               for(i = 0; i < 768; i++)\r
-                                                       s->colormap[i] = (unsigned char)(bound(0, (s->colormap[i] * s->colorscale) - s->colorsub, 255));\r
-                                               goto readframe;\r
-                                       }\r
-                                       //else\r
-                                       //      s->error = JAMDECODEERROR_BAD_COLORMAP;\r
-                               }\r
-                               else\r
-                               {\r
-                                       // decode frame\r
-                                       // shift buffers to provide current and previous one, decode\r
-                                       b = s->prevframedata;\r
-                                       s->prevframedata = s->framedata;\r
-                                       s->framedata = b;\r
-                                       jam_decodeframe(s->compressed, s->framedata, s->prevframedata, outsize, frameHead[4]);\r
-                                       // make 32bit imagepixels from 8bit palettized frame\r
-                                       if (s->doubleres)\r
-                                               b = s->videopixels;\r
-                                       else\r
-                                               b = (unsigned char *)imagedata;\r
-                                       for(i = 0; i < s->framesize; i++)\r
-                                       {\r
-                                               // bgra\r
-                                               *b++ = s->colormap[s->framedata[i]*3 + 2];\r
-                                               *b++ = s->colormap[s->framedata[i]*3 + 1];\r
-                                               *b++ = s->colormap[s->framedata[i]*3];\r
-                                               *b++ = 255;\r
-                                       }\r
-                                       // nearest 2x\r
-                                       if (s->doubleres)\r
-                                       {\r
-                                               for (i = 0; i < s->info_imageheight; i++)\r
-                                               {\r
-                                                       b = (unsigned char *)imagedata + (s->info_imagewidth*2*4)*(i*2);\r
-                                                       for (j = 0; j < s->info_imagewidth; j++)\r
-                                                       {\r
-                                                               *b++ = s->videopixels[i*s->info_imagewidth*4 + j*4];\r
-                                                               *b++ = s->videopixels[i*s->info_imagewidth*4 + j*4 + 1];\r
-                                                               *b++ = s->videopixels[i*s->info_imagewidth*4 + j*4 + 2];\r
-                                                               *b++ = s->videopixels[i*s->info_imagewidth*4 + j*4 + 3];\r
-                                                               //\r
-                                                               *b++ = s->videopixels[i*s->info_imagewidth*4 + j*4];\r
-                                                               *b++ = s->videopixels[i*s->info_imagewidth*4 + j*4 + 1];\r
-                                                               *b++ = s->videopixels[i*s->info_imagewidth*4 + j*4 + 2];\r
-                                                               *b++ = s->videopixels[i*s->info_imagewidth*4 + j*4 + 3];\r
-                                                       }\r
-                                                       b = (unsigned char *)imagedata + (s->info_imagewidth*2*4)*(i*2 + 1);\r
-                                                       for (j = 0; j < s->info_imagewidth; j++)\r
-                                                       {\r
-                                                               *b++ = s->videopixels[i*s->info_imagewidth*4 + j*4];\r
-                                                               *b++ = s->videopixels[i*s->info_imagewidth*4 + j*4 + 1];\r
-                                                               *b++ = s->videopixels[i*s->info_imagewidth*4 + j*4 + 2];\r
-                                                               *b++ = s->videopixels[i*s->info_imagewidth*4 + j*4 + 3];\r
-                                                               //\r
-                                                               *b++ = s->videopixels[i*s->info_imagewidth*4 + j*4];\r
-                                                               *b++ = s->videopixels[i*s->info_imagewidth*4 + j*4 + 1];\r
-                                                               *b++ = s->videopixels[i*s->info_imagewidth*4 + j*4 + 2];\r
-                                                               *b++ = s->videopixels[i*s->info_imagewidth*4 + j*4 + 3];\r
-                                                       }\r
-                                               }\r
-                                               // do stippling\r
-                                               if (s->stipple)\r
-                                               {\r
-                                                       for (i = 0; i < s->info_imageheight; i++)\r
-                                                       {\r
-                                                               b = (unsigned char *)imagedata + (s->info_imagewidth * 4 * 2 * 2 * i);\r
-                                                               for (j = 0; j < s->info_imagewidth; j++)\r
-                                                               {\r
-                                                                       b[0] = b[0] * s->stipple;\r
-                                                                       b[1] = b[1] * s->stipple;\r
-                                                                       b[2] = b[2] * s->stipple;\r
-                                                                       b += 4;\r
-                                                                       b[0] = b[0] * s->stipple;\r
-                                                                       b[1] = b[1] * s->stipple;\r
-                                                                       b[2] = b[2] * s->stipple;\r
-                                                                       b += 4;\r
-                                                               }\r
-                                                       }\r
-                                               }\r
-                                       }\r
-\r
-                               }\r
-                       }\r
-                       else\r
-                               s->error = JAMDECODEERROR_READERROR;\r
-               }\r
-               else\r
-                       s->error = JAMDECODEERROR_READERROR;\r
-       }\r
-       else\r
-               s->error = DPVSIMPLEDECODEERROR_EOF;\r
-       return s->error;\r
+// JAM format decoder, used by Blood Omnicide
+
+typedef struct jamdecodestream_s
+{
+       int error;
+
+       qfile_t *file;
+       double info_framerate;
+       unsigned int info_frames;
+       unsigned int info_imagewidth;
+       unsigned int info_imageheight;
+       int doubleres;
+       float colorscale;
+       unsigned char colorsub;
+       float stipple;
+
+       // info used durign decoding
+       unsigned char *videopixels;
+       unsigned char *compressed;
+       unsigned char *framedata;
+       unsigned char *prevframedata;
+       unsigned char colormap[768];
+       unsigned int framesize;
+       unsigned int framenum;
+
+       // channel the sound file is being played on
+       int sndchan;
+}
+jamdecodestream_t;
+
+#define JAMDECODEERROR_NONE                0
+#define JAMDECODEERROR_EOF                 1
+#define JAMDECODEERROR_READERROR           2
+#define JAMDECODEERROR_BAD_FRAME_HEADER    3
+#define JAMDECODEERROR_BAD_OUTPUT_SIZE     4
+#define JAMDECODEERROR_BAD_COLORMAP        5
+
+// opens a stream
+void jam_close(void *stream);
+unsigned int jam_getwidth(void *stream);
+unsigned int jam_getheight(void *stream);
+double jam_getframerate(void *stream);
+int jam_video(void *stream, void *imagedata, unsigned int Rmask, unsigned int Gmask, unsigned int Bmask, unsigned int bytesperpixel, int imagebytesperrow);
+void *jam_open(clvideo_t *video, char *filename, const char **errorstring)
+{
+       unsigned char jamHead[16];
+       char *wavename;
+       jamdecodestream_t *s;
+       qfile_t *file;
+
+       s = (jamdecodestream_t *)Z_Malloc(sizeof(jamdecodestream_t));
+       if (s != NULL)
+       {
+               if ((file = FS_OpenVirtualFile(filename, false)))
+               {
+                       s->file = file;
+                       if (FS_Read(s->file, &jamHead, 16))
+                       {
+                               if (!memcmp(jamHead, "JAM", 3))
+                               {
+                                       s->info_imagewidth = LittleLong(*(jamHead + 4));
+                                       s->info_imageheight = LittleLong(*(jamHead + 8));
+                                       s->info_frames = LittleLong(*(jamHead + 12));
+                                       s->info_framerate = 15;
+                                       s->doubleres = 0;
+                                       s->colorscale = 0.70;
+                                       s->colorsub = 8;
+                                       s->stipple = 0.4;
+                                       s->framesize = s->info_imagewidth * s->info_imageheight;
+                                       if (s->framesize > 0)
+                                       {
+                                               s->compressed = (unsigned char *)Z_Malloc(s->framesize);
+                                               s->framedata = (unsigned char *)Z_Malloc(s->framesize * 2);
+                                               s->prevframedata = (unsigned char *)Z_Malloc(s->framesize * 2);
+                                               s->videopixels = (unsigned char *)Z_Malloc(s->framesize * 4); // bgra, doubleres
+                                               if (s->compressed != NULL && s->framedata != NULL && s->prevframedata != NULL && s->videopixels != NULL)
+                                               {
+                                                       size_t namelen;
+
+                                                       namelen = strlen(filename) + 10;
+                                                       wavename = (char *)Z_Malloc(namelen);
+                                                       if (wavename)
+                                                       {
+                                                               sfx_t* sfx;
+
+                                                               FS_StripExtension(filename, wavename, namelen);
+                                                               strlcat(wavename, ".wav", namelen);
+                                                               sfx = S_PrecacheSound(wavename, false, false);
+                                                               if (sfx != NULL)
+                                                                       s->sndchan = S_StartSound (-1, 0, sfx, vec3_origin, 1.0f, 0);
+                                                               else
+                                                                       s->sndchan = -1;
+                                                               Z_Free(wavename);
+                                                       }
+                                                       // all is well...
+                                                       // set the module functions
+                                                       s->framenum = 0;
+                                                       video->close = jam_close;
+                                                       video->getwidth = jam_getwidth;
+                                                       video->getheight = jam_getheight;
+                                                       video->getframerate = jam_getframerate;
+                                                       video->decodeframe = jam_video;
+                                                       return s;
+                                               }
+                                               else if (errorstring != NULL)
+                                                       *errorstring = "unable to allocate memory for stream info structure";
+                                               if (s->compressed != NULL)
+                                                       Z_Free(s->compressed);
+                                               if (s->framedata != NULL)
+                                                       Z_Free(s->framedata);
+                                               if (s->prevframedata != NULL)
+                                                       Z_Free(s->prevframedata);
+                                               if (s->videopixels != NULL)
+                                                       Z_Free(s->videopixels);
+                                       }
+                                       else if (errorstring != NULL)
+                                               *errorstring = "bad framesize";
+                               }
+                               else if (errorstring != NULL)
+                                       *errorstring = "not JAM videofile";
+                       }
+                       else if (errorstring != NULL)
+                               *errorstring = "unexpected EOF";
+                       FS_Close(file);
+               }
+               else if (errorstring != NULL)
+                       *errorstring = "unable to open videofile";
+               Z_Free(s);
+       }
+       else if (errorstring != NULL)
+               *errorstring = "unable to allocate memory for stream info structure";
+       return NULL;
+}
+
+// closes a stream
+void jam_close(void *stream)
+{
+       jamdecodestream_t *s = (jamdecodestream_t *)stream;
+       if (s == NULL)
+               return;
+       Z_Free(s->compressed);
+       Z_Free(s->framedata);
+       Z_Free(s->prevframedata);
+       Z_Free(s->videopixels);
+       if (s->sndchan != -1)
+               S_StopChannel(s->sndchan, true);
+       if (s->file)
+               FS_Close(s->file);
+       Z_Free(s);
+}
+
+// returns the width of the image data
+unsigned int jam_getwidth(void *stream)
+{
+       jamdecodestream_t *s = (jamdecodestream_t *)stream;
+       if (s->doubleres)
+               return s->info_imagewidth * 2;
+       return s->info_imagewidth;
+}
+
+// returns the height of the image data
+unsigned int jam_getheight(void *stream)
+{
+       jamdecodestream_t *s = (jamdecodestream_t *)stream;
+       if (s->doubleres)
+               return s->info_imageheight * 2;
+       return s->info_imageheight;
+}
+
+// returns the framerate of the stream
+double jam_getframerate(void *stream)
+{
+       jamdecodestream_t *s = (jamdecodestream_t *)stream;
+       return s->info_framerate;
+}
+
+
+// decode JAM frame
+void jam_decodeframe(unsigned char *inbuf, unsigned char *outbuf, unsigned char *prevbuf, int outsize, int frametype)
+{
+       unsigned char *srcptr, *destptr, *prevptr;
+       int bytesleft;
+       unsigned int mark;
+       unsigned short int bits;
+       int rep;
+       int backoffs;
+       unsigned char *back;
+       int i;
+
+       srcptr = inbuf;
+       destptr = outbuf;
+       prevptr = prevbuf;
+       bytesleft = outsize;
+
+       if (frametype == 2)
+       {
+               memcpy(outbuf, inbuf, outsize);
+               return;
+       }
+       while(bytesleft > 0)
+       {
+               memcpy(&mark, srcptr, 4);
+               srcptr += 4;
+               for(i=0; i<32 && bytesleft > 0; i++,mark=mark>>1)
+               {
+                       if(mark & 1)
+                       {
+                               *destptr = *srcptr;
+                               destptr ++;
+                               prevptr ++;
+                               srcptr ++;
+                               bytesleft --;
+                       }
+                       else
+                       {
+                               bits = srcptr[0] + 256*srcptr[1];
+                               rep = (bits >> 11) + 3;
+                               if(frametype == 1)
+                               {
+                                       backoffs = 0x821 - (bits & 0x7ff);
+                                       back = destptr - backoffs;
+                               }
+                               else
+                               {
+                                       backoffs = 0x400 - (bits & 0x7ff);
+                                       back = prevptr - backoffs;
+                               }
+                               srcptr += 2;
+                               memcpy(destptr, back, rep);
+                               destptr += rep;
+                               prevptr += rep;
+                               bytesleft -= rep;
+                       }
+               }
+       }
+}
+
+// decodes a video frame to the supplied output pixels
+int jam_video(void *stream, void *imagedata, unsigned int Rmask, unsigned int Gmask, unsigned int Bmask, unsigned int bytesperpixel, int imagebytesperrow)
+{
+       unsigned char frameHead[16], *b;
+       unsigned int compsize, outsize, i, j;
+       jamdecodestream_t *s = (jamdecodestream_t *)stream;
+
+       s->error = DPVSIMPLEDECODEERROR_NONE;
+       if (s->framenum < s->info_frames)
+       {
+readframe:
+               if (FS_Read(s->file, &frameHead, 16))
+               {
+                       compsize = LittleLong(*(frameHead + 8)) - 16;
+                       outsize = LittleLong(*(frameHead + 12));
+                       if (compsize < 0 || compsize > s->framesize || outsize < 0 || outsize > s->framesize)
+                               s->error = JAMDECODEERROR_BAD_FRAME_HEADER;
+                       else if (FS_Read(s->file, s->compressed, compsize))
+                       {
+                               // palette goes interleaved with special flag
+                               if (frameHead[0] == 2)
+                               {
+                                       if (compsize == 768)
+                                       {
+                                               memcpy(s->colormap, s->compressed, 768);
+                                               for(i = 0; i < 768; i++)
+                                                       s->colormap[i] = (unsigned char)(bound(0, (s->colormap[i] * s->colorscale) - s->colorsub, 255));
+                                               goto readframe;
+                                       }
+                                       //else
+                                       //      s->error = JAMDECODEERROR_BAD_COLORMAP;
+                               }
+                               else
+                               {
+                                       // decode frame
+                                       // shift buffers to provide current and previous one, decode
+                                       b = s->prevframedata;
+                                       s->prevframedata = s->framedata;
+                                       s->framedata = b;
+                                       jam_decodeframe(s->compressed, s->framedata, s->prevframedata, outsize, frameHead[4]);
+                                       // make 32bit imagepixels from 8bit palettized frame
+                                       if (s->doubleres)
+                                               b = s->videopixels;
+                                       else
+                                               b = (unsigned char *)imagedata;
+                                       for(i = 0; i < s->framesize; i++)
+                                       {
+                                               // bgra
+                                               *b++ = s->colormap[s->framedata[i]*3 + 2];
+                                               *b++ = s->colormap[s->framedata[i]*3 + 1];
+                                               *b++ = s->colormap[s->framedata[i]*3];
+                                               *b++ = 255;
+                                       }
+                                       // nearest 2x
+                                       if (s->doubleres)
+                                       {
+                                               for (i = 0; i < s->info_imageheight; i++)
+                                               {
+                                                       b = (unsigned char *)imagedata + (s->info_imagewidth*2*4)*(i*2);
+                                                       for (j = 0; j < s->info_imagewidth; j++)
+                                                       {
+                                                               *b++ = s->videopixels[i*s->info_imagewidth*4 + j*4];
+                                                               *b++ = s->videopixels[i*s->info_imagewidth*4 + j*4 + 1];
+                                                               *b++ = s->videopixels[i*s->info_imagewidth*4 + j*4 + 2];
+                                                               *b++ = s->videopixels[i*s->info_imagewidth*4 + j*4 + 3];
+                                                               //
+                                                               *b++ = s->videopixels[i*s->info_imagewidth*4 + j*4];
+                                                               *b++ = s->videopixels[i*s->info_imagewidth*4 + j*4 + 1];
+                                                               *b++ = s->videopixels[i*s->info_imagewidth*4 + j*4 + 2];
+                                                               *b++ = s->videopixels[i*s->info_imagewidth*4 + j*4 + 3];
+                                                       }
+                                                       b = (unsigned char *)imagedata + (s->info_imagewidth*2*4)*(i*2 + 1);
+                                                       for (j = 0; j < s->info_imagewidth; j++)
+                                                       {
+                                                               *b++ = s->videopixels[i*s->info_imagewidth*4 + j*4];
+                                                               *b++ = s->videopixels[i*s->info_imagewidth*4 + j*4 + 1];
+                                                               *b++ = s->videopixels[i*s->info_imagewidth*4 + j*4 + 2];
+                                                               *b++ = s->videopixels[i*s->info_imagewidth*4 + j*4 + 3];
+                                                               //
+                                                               *b++ = s->videopixels[i*s->info_imagewidth*4 + j*4];
+                                                               *b++ = s->videopixels[i*s->info_imagewidth*4 + j*4 + 1];
+                                                               *b++ = s->videopixels[i*s->info_imagewidth*4 + j*4 + 2];
+                                                               *b++ = s->videopixels[i*s->info_imagewidth*4 + j*4 + 3];
+                                                       }
+                                               }
+                                               // do stippling
+                                               if (s->stipple)
+                                               {
+                                                       for (i = 0; i < s->info_imageheight; i++)
+                                                       {
+                                                               b = (unsigned char *)imagedata + (s->info_imagewidth * 4 * 2 * 2 * i);
+                                                               for (j = 0; j < s->info_imagewidth; j++)
+                                                               {
+                                                                       b[0] = b[0] * s->stipple;
+                                                                       b[1] = b[1] * s->stipple;
+                                                                       b[2] = b[2] * s->stipple;
+                                                                       b += 4;
+                                                                       b[0] = b[0] * s->stipple;
+                                                                       b[1] = b[1] * s->stipple;
+                                                                       b[2] = b[2] * s->stipple;
+                                                                       b += 4;
+                                                               }
+                                                       }
+                                               }
+                                       }
+
+                               }
+                       }
+                       else
+                               s->error = JAMDECODEERROR_READERROR;
+               }
+               else
+                       s->error = JAMDECODEERROR_READERROR;
+       }
+       else
+               s->error = DPVSIMPLEDECODEERROR_EOF;
+       return s->error;
 }
\ No newline at end of file
index 67824e75d2c17957afa1335249287cbd6ad292fd..f1e8ff27449097bf5925d6c80ec5b16d4b979ee9 100644 (file)
 "#endif\n"
 "#ifdef USEVERTEXTEXTUREBLEND\n"
 "#ifdef USEBOTHALPHAS\n"
-"      half4 color2 = half4(tex2D(Texture_SecondaryColor, TexCoord2));\n"\r
-"      half terrainblend = clamp(half(gl_FrontColor.a) * color.a, half(1.0 - color2.a), half(1.0));\n"\r
+"      half4 color2 = half4(tex2D(Texture_SecondaryColor, TexCoord2));\n"
+"      half terrainblend = clamp(half(gl_FrontColor.a) * color.a, half(1.0 - color2.a), half(1.0));\n"
 "      color.rgb = lerp(color2.rgb, color.rgb, terrainblend);\n"
 "#else\n"
 "      half terrainblend = clamp(half(gl_FrontColor.a) * color.a * 2.0 - 0.5, half(0.0), half(1.0));\n"