Rev 4634 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4634 | Rev 4647 | ||
---|---|---|---|
Line 282... | Line 282... | ||
282 | // |===|===|
|
282 | // |===|===|
|
283 | //----x O---x O--------
|
283 | //----x O---x O--------
|
284 | nbitpos = LSWAPIL(*(int32_t *)&filptr[8]); |
284 | nbitpos = LSWAPIL(*(int32_t *)&filptr[8]); |
285 | nfilptr = (uint8_t *)&filptr[nbitpos+12]; |
285 | nfilptr = (uint8_t *)&filptr[nbitpos+12]; |
286 | *(int32_t *)&fakebuf[0] = *(int32_t *)&filptr[0]; //Copy last dword of IDAT chunk |
286 | *(int32_t *)&fakebuf[0] = *(int32_t *)&filptr[0]; //Copy last dword of IDAT chunk |
287 | if (*(int32_t *)&filptr[12] == LSWAPIB(0x54414449)) //Copy 1st dword of next IDAT chunk |
287 | if (*(int32_t *)&filptr[12] == (int32_t)LSWAPIB(0x54414449)) //Copy 1st dword of next IDAT chunk |
288 | *(int32_t *)&fakebuf[4] = *(int32_t *)&filptr[16]; |
288 | *(int32_t *)&fakebuf[4] = *(int32_t *)&filptr[16]; |
289 | filptr = &fakebuf[4]; bitpos -= 32; |
289 | filptr = &fakebuf[4]; bitpos -= 32; |
290 | }
|
290 | }
|
291 | 291 | ||
292 | static _inline int32_t peekbits(int32_t n) { return((LSWAPIB(*(int32_t *)&filptr[bitpos>>3])>>(bitpos&7))&pow2mask[n]); } |
292 | static _inline int32_t peekbits(int32_t n) { return((LSWAPIB(*(int32_t *)&filptr[bitpos>>3])>>(bitpos&7))&pow2mask[n]); } |
Line 793... | Line 793... | ||
793 | 793 | ||
794 | UNREFERENCED_PARAMETER(kfilength); |
794 | UNREFERENCED_PARAMETER(kfilength); |
795 | 795 | ||
796 | if (!pnginited) { pnginited = 1; initpngtables(); } |
796 | if (!pnginited) { pnginited = 1; initpngtables(); } |
797 | 797 | ||
798 | if ((*(int32_t *)&kfilebuf[0] != LSWAPIB(0x474e5089)) || (*(int32_t *)&kfilebuf[4] != LSWAPIB(0x0a1a0a0d))) |
798 | if ((*(int32_t *)&kfilebuf[0] != (int32_t)LSWAPIB(0x474e5089)) || (*(int32_t *)&kfilebuf[4] != (int32_t)LSWAPIB(0x0a1a0a0d))) |
799 | return(-1); //"Invalid PNG file signature" |
799 | return(-1); //"Invalid PNG file signature" |
800 | filptr = (uint8_t *)&kfilebuf[8]; |
800 | filptr = (uint8_t *)&kfilebuf[8]; |
801 | 801 | ||
802 | trnsrgb = 0; filter1st = -1; filterest = 0; |
802 | trnsrgb = 0; filter1st = -1; filterest = 0; |
803 | 803 | ||
804 | while (1) |
804 | while (1) |
805 | {
|
805 | {
|
806 | leng = LSWAPIL(*(int32_t *)&filptr[0]); i = *(int32_t *)&filptr[4]; |
806 | leng = LSWAPIL(*(int32_t *)&filptr[0]); i = *(int32_t *)&filptr[4]; |
807 | filptr = &filptr[8]; |
807 | filptr = &filptr[8]; |
808 | 808 | ||
809 | if (i == LSWAPIB(0x52444849)) //IHDR (must be first) |
809 | if (i == (int32_t)LSWAPIB(0x52444849)) //IHDR (must be first) |
810 | {
|
810 | {
|
811 | xsiz = LSWAPIL(*(int32_t *)&filptr[0]); if (xsiz <= 0) return(-1); |
811 | xsiz = LSWAPIL(*(int32_t *)&filptr[0]); if (xsiz <= 0) return(-1); |
812 | ysiz = LSWAPIL(*(int32_t *)&filptr[4]); if (ysiz <= 0) return(-1); |
812 | ysiz = LSWAPIL(*(int32_t *)&filptr[4]); if (ysiz <= 0) return(-1); |
813 | bitdepth = filptr[8]; if (!((1<<bitdepth)&0x116)) return(-1); //"Bit depth not supported" |
813 | bitdepth = filptr[8]; if (!((1<<bitdepth)&0x116)) return(-1); //"Bit depth not supported" |
814 | kcoltype = filptr[9]; if (!((1<<kcoltype)&0x5d)) return(-1); //"Color type not supported" |
814 | kcoltype = filptr[9]; if (!((1<<kcoltype)&0x5d)) return(-1); //"Color type not supported" |
Line 823... | Line 823... | ||
823 | j = 0xff000000; k = (255 / ((1<<bitdepth)-1))*0x10101; |
823 | j = 0xff000000; k = (255 / ((1<<bitdepth)-1))*0x10101; |
824 | paleng = (1<<bitdepth); |
824 | paleng = (1<<bitdepth); |
825 | for (i=0; i<paleng; i++,j+=k) palcol[i] = LSWAPIB(j); |
825 | for (i=0; i<paleng; i++,j+=k) palcol[i] = LSWAPIB(j); |
826 | }
|
826 | }
|
827 | }
|
827 | }
|
828 | else if (i == LSWAPIB(0x45544c50)) //PLTE (must be before IDAT) |
828 | else if (i == (int32_t)LSWAPIB(0x45544c50)) //PLTE (must be before IDAT) |
829 | {
|
829 | {
|
830 | paleng = leng/3; |
830 | paleng = leng/3; |
831 | for (i=paleng-1; i>=0; i--) palcol[i] = LSWAPIB((LSWAPIL(*(int32_t *)&filptr[i*3])>>8)|0xff000000); |
831 | for (i=paleng-1; i>=0; i--) palcol[i] = LSWAPIB((LSWAPIL(*(int32_t *)&filptr[i*3])>>8)|0xff000000); |
832 | }
|
832 | }
|
833 | else if (i == LSWAPIB(0x44474b62)) //bKGD (must be after PLTE and before IDAT) |
833 | else if (i == (int32_t)LSWAPIB(0x44474b62)) //bKGD (must be after PLTE and before IDAT) |
834 | {
|
834 | {
|
835 | switch (kcoltype) |
835 | switch (kcoltype) |
836 | {
|
836 | {
|
837 | case 0: case 4: |
837 | case 0: case 4: |
838 | bakcol = (((int32_t)filptr[0]<<8)+(int32_t)filptr[1])*255/((1<<bitdepth)-1); |
838 | bakcol = (((int32_t)filptr[0]<<8)+(int32_t)filptr[1])*255/((1<<bitdepth)-1); |
Line 852... | Line 852... | ||
852 | bakr = ((bakcol>>16)&255); |
852 | bakr = ((bakcol>>16)&255); |
853 | bakg = ((bakcol>>8)&255); |
853 | bakg = ((bakcol>>8)&255); |
854 | bakb = (bakcol&255); |
854 | bakb = (bakcol&255); |
855 | bakcol = LSWAPIB(bakcol); |
855 | bakcol = LSWAPIB(bakcol); |
856 | }
|
856 | }
|
857 | else if (i == LSWAPIB(0x534e5274)) //tRNS (must be after PLTE and before IDAT) |
857 | else if (i == (int32_t)LSWAPIB(0x534e5274)) //tRNS (must be after PLTE and before IDAT) |
858 | {
|
858 | {
|
859 | switch (kcoltype) |
859 | switch (kcoltype) |
860 | {
|
860 | {
|
861 | case 0: |
861 | case 0: |
862 | if (bitdepth <= 8) |
862 | if (bitdepth <= 8) |
Line 873... | Line 873... | ||
873 | palcol[i] &= LSWAPIB((((int32_t)filptr[i])<<24)|0xffffff); |
873 | palcol[i] &= LSWAPIB((((int32_t)filptr[i])<<24)|0xffffff); |
874 | break; |
874 | break; |
875 | default:; |
875 | default:; |
876 | }
|
876 | }
|
877 | }
|
877 | }
|
878 | else if (i == LSWAPIB(0x54414449)) { break; } //IDAT |
878 | else if (i == (int32_t)LSWAPIB(0x54414449)) { break; } //IDAT |
879 | 879 | ||
880 | filptr = &filptr[leng+4]; //crc = LSWAPIL(*(int32_t *)&filptr[-4]); |
880 | filptr = &filptr[leng+4]; //crc = LSWAPIL(*(int32_t *)&filptr[-4]); |
881 | }
|
881 | }
|
882 | 882 | ||
883 | //Initialize this for the getbits() function
|
883 | //Initialize this for the getbits() function
|
Line 1946... | Line 1946... | ||
1946 | }
|
1946 | }
|
1947 | 1947 | ||
1948 | //============================== TARGA ends =================================
|
1948 | //============================== TARGA ends =================================
|
1949 | //============================== BMP begins =================================
|
1949 | //============================== BMP begins =================================
|
1950 | //TODO: handle BI_RLE8 and BI_RLE4 (compression types 1&2 respectively)
|
1950 | //TODO: handle BI_RLE8 and BI_RLE4 (compression types 1&2 respectively)
|
1951 | // ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
|
1951 | // +---------------+
|
1952 | // ³ 0(2): "BM" ³
|
1952 | // | 0(2): "BM" |
|
1953 | // ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿³ 10(4): rastoff³ ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
|
1953 | // +---------------------+| 10(4): rastoff| +------------------+
|
1954 | // ³headsiz=12 (OS/2 1.x)³³ 14(4): headsiz³ ³ All new formats: ³
|
1954 | // |headsiz=12 (OS/2 1.x)|| 14(4): headsiz| | All new formats: |
|
1955 | //ÚÁÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÁÁÄÄÄÄÄÄÄÄÄÄÄÄÄÂÄÁÄÁÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
|
1955 | //++---------------------++-------------+-+-+------------------+-----------------------+
|
1956 | //³ 18(2): xsiz ³ 18(4): xsiz ³
|
1956 | //| 18(2): xsiz | 18(4): xsiz |
|
1957 | //³ 20(2): ysiz ³ 22(4): ysiz ³
|
1957 | //| 20(2): ysiz | 22(4): ysiz |
|
1958 | //³ 22(2): planes (always 1) ³ 26(2): planes (always 1) ³
|
1958 | //| 22(2): planes (always 1) | 26(2): planes (always 1) |
|
1959 | //³ 24(2): cdim (1,4,8,24) ³ 28(2): cdim (1,4,8,16,24,32) ³
|
1959 | //| 24(2): cdim (1,4,8,24) | 28(2): cdim (1,4,8,16,24,32) |
|
1960 | //³ if (cdim < 16) ³ 30(4): compression (0,1,2,3!?,4) ³
|
1960 | //| if (cdim < 16) | 30(4): compression (0,1,2,3!?,4) |
|
1961 | //³ 26(rastoff-14-headsiz): pal(bgr) ³ 34(4): (bitmap data size+3)&3 ³
|
1961 | //| 26(rastoff-14-headsiz): pal(bgr) | 34(4): (bitmap data size+3)&3 |
|
1962 | //³ ³ 46(4): N colors (0=2^cdim) ³
|
1962 | //| | 46(4): N colors (0=2^cdim) |
|
1963 | //³ ³ if (cdim < 16) ³
|
1963 | //| | if (cdim < 16) |
|
1964 | //³ ³ 14+headsiz(rastoff-14-headsiz): pal(bgr0) ³
|
1964 | //| | 14+headsiz(rastoff-14-headsiz): pal(bgr0) |
|
1965 | //ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
|
1965 | //+---------------------+---------------+---------+------------------------------------+
|
1966 | // ³ rastoff(?): bitmap data ³
|
1966 | // | rastoff(?): bitmap data |
|
1967 | // ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
|
1967 | // +-------------------------+
|
1968 | static int32_t kbmprend(const char *buf, int32_t fleng, |
1968 | static int32_t kbmprend(const char *buf, int32_t fleng, |
1969 | intptr_t daframeplace, int32_t dabytesperline, int32_t daxres, int32_t dayres) |
1969 | intptr_t daframeplace, int32_t dabytesperline, int32_t daxres, int32_t dayres) |
1970 | {
|
1970 | {
|
1971 | int32_t i, j, x, y, x0, x1, y0, y1, rastoff, headsiz, xsiz, ysiz, cdim, comp, cptrinc, *lptr; |
1971 | int32_t i, j, x, y, x0, x1, y0, y1, rastoff, headsiz, xsiz, ysiz, cdim, comp, cptrinc, *lptr; |
1972 | const char *cptr; |
1972 | const char *cptr; |
1973 | 1973 | ||
1974 | UNREFERENCED_PARAMETER(fleng); |
1974 | UNREFERENCED_PARAMETER(fleng); |
1975 | 1975 | ||
1976 | headsiz = *(int32_t *)&buf[14]; |
1976 | headsiz = *(int32_t *)&buf[14]; |
1977 | if (headsiz == LSWAPIB(12)) //OS/2 1.x (old format) |
1977 | if (headsiz == (int32_t)LSWAPIB(12)) //OS/2 1.x (old format) |
1978 | {
|
1978 | {
|
1979 | if (*(int16_t *)(&buf[22]) != SSWAPIB(1)) return(-1); |
1979 | if (*(int16_t *)(&buf[22]) != SSWAPIB(1)) return(-1); |
1980 | xsiz = (int32_t)SSWAPIB(*(uint16_t *)&buf[18]); |
1980 | xsiz = (int32_t)SSWAPIB(*(uint16_t *)&buf[18]); |
1981 | ysiz = (int32_t)SSWAPIB(*(uint16_t *)&buf[20]); |
1981 | ysiz = (int32_t)SSWAPIB(*(uint16_t *)&buf[20]); |
1982 | cdim = (int32_t)SSWAPIB(*(uint16_t *)&buf[24]); |
1982 | cdim = (int32_t)SSWAPIB(*(uint16_t *)&buf[24]); |
Line 1998... | Line 1998... | ||
1998 | rastoff = LSWAPIB(*(int32_t *)&buf[10]); |
1998 | rastoff = LSWAPIB(*(int32_t *)&buf[10]); |
1999 | 1999 | ||
2000 | if (cdim < 16) |
2000 | if (cdim < 16) |
2001 | {
|
2001 | {
|
2002 | if (cdim == 2) { palcol[0] = 0xffffffff; palcol[1] = LSWAPIB(0xff000000); } |
2002 | if (cdim == 2) { palcol[0] = 0xffffffff; palcol[1] = LSWAPIB(0xff000000); } |
2003 | if (headsiz == LSWAPIB(12)) j = 3; else j = 4; |
2003 | if (headsiz == (int32_t)LSWAPIB(12)) j = 3; else j = 4; |
2004 | for (i=0,cptr=&buf[headsiz+14]; cptr<&buf[rastoff]; i++,cptr+=j) |
2004 | for (i=0,cptr=&buf[headsiz+14]; cptr<&buf[rastoff]; i++,cptr+=j) |
2005 | palcol[i] = ((*(int32_t *)&cptr[0])|LSWAPIB(0xff000000)); |
2005 | palcol[i] = ((*(int32_t *)&cptr[0])|LSWAPIB(0xff000000)); |
2006 | kcoltype = 3; bitdepth = (int8_t)cdim; paleng = i; //For PNGOUT |
2006 | kcoltype = 3; bitdepth = (int8_t)cdim; paleng = i; //For PNGOUT |
2007 | }
|
2007 | }
|
2008 | else if (!(cdim&15)) |
2008 | else if (!(cdim&15)) |
Line 2084... | Line 2084... | ||
2084 | {
|
2084 | {
|
2085 | int32_t j, x, y, nplanes, x0, x1, y0, y1, bpl, xsiz, ysiz; |
2085 | int32_t j, x, y, nplanes, x0, x1, y0, y1, bpl, xsiz, ysiz; |
2086 | intptr_t p,i; |
2086 | intptr_t p,i; |
2087 | uint8_t c, *cptr; |
2087 | uint8_t c, *cptr; |
2088 | 2088 | ||
2089 | if (*(int32_t *)buf != LSWAPIB(0x0801050a)) return(-1); |
2089 | if (*(int32_t *)buf != (int32_t)LSWAPIB(0x0801050a)) return(-1); |
2090 | xsiz = SSWAPIB(*(int16_t *)&buf[ 8])-SSWAPIB(*(int16_t *)&buf[4])+1; if (xsiz <= 0) return(-1); |
2090 | xsiz = SSWAPIB(*(int16_t *)&buf[ 8])-SSWAPIB(*(int16_t *)&buf[4])+1; if (xsiz <= 0) return(-1); |
2091 | ysiz = SSWAPIB(*(int16_t *)&buf[10])-SSWAPIB(*(int16_t *)&buf[6])+1; if (ysiz <= 0) return(-1); |
2091 | ysiz = SSWAPIB(*(int16_t *)&buf[10])-SSWAPIB(*(int16_t *)&buf[6])+1; if (ysiz <= 0) return(-1); |
2092 | //buf[3]: bpp/plane:{1,2,4,8}
|
2092 | //buf[3]: bpp/plane:{1,2,4,8}
|
2093 | nplanes = buf[65]; //nplanes*bpl bytes per scanline; always be decoding break at the end of scan line |
2093 | nplanes = buf[65]; //nplanes*bpl bytes per scanline; always be decoding break at the end of scan line |
2094 | bpl = SSWAPIB(*(int16_t *)&buf[66]); //#bytes per scanline. Must be EVEN. May have unused data. |
2094 | bpl = SSWAPIB(*(int16_t *)&buf[66]); //#bytes per scanline. Must be EVEN. May have unused data. |
Line 2301... | Line 2301... | ||
2301 | 2301 | ||
2302 | (*xsiz) = (*ysiz) = 0; if (leng < 16) return; |
2302 | (*xsiz) = (*ysiz) = 0; if (leng < 16) return; |
2303 | if (*(uint16_t *)&ubuf[0] == SSWAPIB(0x5089)) //.PNG |
2303 | if (*(uint16_t *)&ubuf[0] == SSWAPIB(0x5089)) //.PNG |
2304 | {
|
2304 | {
|
2305 | lptr = (int32_t *)buf; |
2305 | lptr = (int32_t *)buf; |
2306 | if ((lptr[0] != LSWAPIB(0x474e5089)) || (lptr[1] != LSWAPIB(0x0a1a0a0d))) return; |
2306 | if ((lptr[0] != (int32_t)LSWAPIB(0x474e5089)) || (lptr[1] != (int32_t)LSWAPIB(0x0a1a0a0d))) return; |
2307 | lptr = &lptr[2]; |
2307 | lptr = &lptr[2]; |
2308 | while (((uintptr_t)lptr-(uintptr_t)buf) < (uintptr_t)(leng-16)) |
2308 | while (((uintptr_t)lptr-(uintptr_t)buf) < (uintptr_t)(leng-16)) |
2309 | {
|
2309 | {
|
2310 | if (lptr[1] == LSWAPIB(0x52444849)) //IHDR |
2310 | if (lptr[1] == (int32_t)LSWAPIB(0x52444849)) //IHDR |
2311 | {(*xsiz) = LSWAPIL(lptr[2]); (*ysiz) = LSWAPIL(lptr[3]); break; } |
2311 | {(*xsiz) = LSWAPIL(lptr[2]); (*ysiz) = LSWAPIL(lptr[3]); break; } |
2312 | lptr = (int32_t *)((intptr_t)lptr + LSWAPIL(lptr[0]) + 12); |
2312 | lptr = (int32_t *)((intptr_t)lptr + LSWAPIL(lptr[0]) + 12); |
2313 | }
|
2313 | }
|
2314 | }
|
2314 | }
|
2315 | else if (*(uint16_t *)&ubuf[0] == SSWAPIB(0xd8ff)) //.JPG |
2315 | else if (*(uint16_t *)&ubuf[0] == SSWAPIB(0xd8ff)) //.JPG |
Line 2334... | Line 2334... | ||
2334 | (*xsiz) = (int32_t) SSWAPIB(*(uint16_t *) &buf[6]); |
2334 | (*xsiz) = (int32_t) SSWAPIB(*(uint16_t *) &buf[6]); |
2335 | (*ysiz) = (int32_t) SSWAPIB(*(uint16_t *) &buf[8]); |
2335 | (*ysiz) = (int32_t) SSWAPIB(*(uint16_t *) &buf[8]); |
2336 | }
|
2336 | }
|
2337 | else if ((ubuf[0] == 'B') && (ubuf[1] == 'M')) //.BMP |
2337 | else if ((ubuf[0] == 'B') && (ubuf[1] == 'M')) //.BMP |
2338 | {
|
2338 | {
|
2339 | if (*(int32_t *) (&buf[14]) == LSWAPIB(12)) //OS/2 1.x (old format) |
2339 | if (*(int32_t *) (&buf[14]) == (int32_t)LSWAPIB(12)) //OS/2 1.x (old format) |
2340 | {
|
2340 | {
|
2341 | if (*(int16_t *) (&buf[22]) != SSWAPIB(1)) return; |
2341 | if (*(int16_t *) (&buf[22]) != SSWAPIB(1)) return; |
2342 | (*xsiz) = (int32_t) SSWAPIB(*(uint16_t *) &buf[18]); |
2342 | (*xsiz) = (int32_t) SSWAPIB(*(uint16_t *) &buf[18]); |
2343 | (*ysiz) = (int32_t) SSWAPIB(*(uint16_t *) &buf[20]); |
2343 | (*ysiz) = (int32_t) SSWAPIB(*(uint16_t *) &buf[20]); |
2344 | }
|
2344 | }
|
Line 2347... | Line 2347... | ||
2347 | if (*(int16_t *) (&buf[26]) != SSWAPIB(1)) return; |
2347 | if (*(int16_t *) (&buf[26]) != SSWAPIB(1)) return; |
2348 | (*xsiz) = LSWAPIB(*(int32_t *) &buf[18]); |
2348 | (*xsiz) = LSWAPIB(*(int32_t *) &buf[18]); |
2349 | (*ysiz) = LSWAPIB(*(int32_t *) &buf[22]); |
2349 | (*ysiz) = LSWAPIB(*(int32_t *) &buf[22]); |
2350 | }
|
2350 | }
|
2351 | }
|
2351 | }
|
2352 | else if (*(int32_t *) ubuf == LSWAPIB(0x0801050a)) //.PCX |
2352 | else if (*(int32_t *) ubuf == (int32_t)LSWAPIB(0x0801050a)) //.PCX |
2353 | {
|
2353 | {
|
2354 | (*xsiz) = SSWAPIB(*(int16_t *) &buf[8])-SSWAPIB(*(int16_t *) &buf[4])+1; |
2354 | (*xsiz) = SSWAPIB(*(int16_t *) &buf[8])-SSWAPIB(*(int16_t *) &buf[4])+1; |
2355 | (*ysiz) = SSWAPIB(*(int16_t *) &buf[10])-SSWAPIB(*(int16_t *) &buf[6])+1; |
2355 | (*ysiz) = SSWAPIB(*(int16_t *) &buf[10])-SSWAPIB(*(int16_t *) &buf[6])+1; |
2356 | }
|
2356 | }
|
2357 | #ifdef KPCEL
|
2357 | #ifdef KPCEL
|
Line 2392... | Line 2392... | ||
2392 | {
|
2392 | {
|
2393 | if ((ubuf[0] == 'G') && (ubuf[1] == 'I') && (ubuf[2] == 'F')) //.GIF |
2393 | if ((ubuf[0] == 'G') && (ubuf[1] == 'I') && (ubuf[2] == 'F')) //.GIF |
2394 | return(kgifrend(buf, leng, frameptr, bpl, xdim, ydim)); |
2394 | return(kgifrend(buf, leng, frameptr, bpl, xdim, ydim)); |
2395 | else if ((ubuf[0] == 'B') && (ubuf[1] == 'M')) //.BMP |
2395 | else if ((ubuf[0] == 'B') && (ubuf[1] == 'M')) //.BMP |
2396 | return(kbmprend(buf, leng, frameptr, bpl, xdim, ydim)); |
2396 | return(kbmprend(buf, leng, frameptr, bpl, xdim, ydim)); |
2397 | else if (*(int32_t *) ubuf == LSWAPIB(0x0801050a)) //.PCX |
2397 | else if (*(int32_t *) ubuf == (int32_t)LSWAPIB(0x0801050a)) //.PCX |
2398 | return(kpcxrend(buf, leng, frameptr, bpl, xdim, ydim)); |
2398 | return(kpcxrend(buf, leng, frameptr, bpl, xdim, ydim)); |
2399 | #ifdef KPCEL
|
2399 | #ifdef KPCEL
|
2400 | else if ((ubuf[0] == 0x19) && (ubuf[1] == 0x91) && (ubuf[10] == 8) && (ubuf[11] == 0)) //old .CEL/.PIC |
2400 | else if ((ubuf[0] == 0x19) && (ubuf[1] == 0x91) && (ubuf[10] == 8) && (ubuf[11] == 0)) //old .CEL/.PIC |
2401 | return(kcelrend(buf, leng, frameptr, bpl, xdim, ydim, xoff, yoff)); |
2401 | return(kcelrend(buf, leng, frameptr, bpl, xdim, ydim, xoff, yoff)); |
2402 | #endif
|
2402 | #endif
|
Line 2536... | Line 2536... | ||
2536 | i = strlen(filnam)+1; if (!kzcheckhashsiz(i)) { fclose(fil); return(-1); } |
2536 | i = strlen(filnam)+1; if (!kzcheckhashsiz(i)) { fclose(fil); return(-1); } |
2537 | strcpy(&kzhashbuf[kzhashpos],filnam); |
2537 | strcpy(&kzhashbuf[kzhashpos],filnam); |
2538 | zipnamoffs = kzhashpos; kzhashpos += i; |
2538 | zipnamoffs = kzhashpos; kzhashpos += i; |
2539 | 2539 | ||
2540 | fread(&i,4,1,fil); |
2540 | fread(&i,4,1,fil); |
2541 | if (i == LSWAPIB(0x04034b50)) //'PK\3\4' is ZIP file id |
2541 | if (i == (int32_t)LSWAPIB(0x04034b50)) //'PK\3\4' is ZIP file id |
2542 | {
|
2542 | {
|
2543 | fseek(fil,-22,SEEK_END); |
2543 | fseek(fil,-22,SEEK_END); |
2544 | fread(tempbuf,22,1,fil); |
2544 | fread(tempbuf,22,1,fil); |
2545 | if (*(int32_t *)&tempbuf[0] == LSWAPIB(0x06054b50)) //Fast way of finding dir info |
2545 | if (*(int32_t *)&tempbuf[0] == (int32_t)LSWAPIB(0x06054b50)) //Fast way of finding dir info |
2546 | {
|
2546 | {
|
2547 | numfiles = SSWAPIB(*(int16_t *)&tempbuf[10]); |
2547 | numfiles = SSWAPIB(*(int16_t *)&tempbuf[10]); |
2548 | fseek(fil,LSWAPIB(*(int32_t *)&tempbuf[16]),SEEK_SET); |
2548 | fseek(fil,LSWAPIB(*(int32_t *)&tempbuf[16]),SEEK_SET); |
2549 | }
|
2549 | }
|
2550 | else //Slow way of finding dir info (used when ZIP has junk at end) |
2550 | else //Slow way of finding dir info (used when ZIP has junk at end) |
2551 | {
|
2551 | {
|
2552 | fseek(fil,0,SEEK_SET); numfiles = 0; |
2552 | fseek(fil,0,SEEK_SET); numfiles = 0; |
2553 | while (1) |
2553 | while (1) |
2554 | {
|
2554 | {
|
2555 | if (!fread(&j,4,1,fil)) { numfiles = -1; break; } |
2555 | if (!fread(&j,4,1,fil)) { numfiles = -1; break; } |
2556 | if (j == LSWAPIB(0x02014b50)) break; //Found central file header :) |
2556 | if (j == (int32_t)LSWAPIB(0x02014b50)) break; //Found central file header :) |
2557 | if (j != LSWAPIB(0x04034b50)) { numfiles = -1; break; } |
2557 | if (j != (int32_t)LSWAPIB(0x04034b50)) { numfiles = -1; break; } |
2558 | fread(tempbuf,26,1,fil); |
2558 | fread(tempbuf,26,1,fil); |
2559 | fseek(fil,LSWAPIB(*(int32_t *)&tempbuf[14]) + SSWAPIB(*(int16_t *)&tempbuf[24]) + SSWAPIB(*(int16_t *)&tempbuf[22]),SEEK_CUR); |
2559 | fseek(fil,LSWAPIB(*(int32_t *)&tempbuf[14]) + SSWAPIB(*(int16_t *)&tempbuf[24]) + SSWAPIB(*(int16_t *)&tempbuf[22]),SEEK_CUR); |
2560 | numfiles++;
|
2560 | numfiles++;
|
2561 | }
|
2561 | }
|
2562 | if (numfiles < 0) { fclose(fil); return(-1); } |
2562 | if (numfiles < 0) { fclose(fil); return(-1); } |
2563 | fseek(fil,-4,SEEK_CUR); |
2563 | fseek(fil,-4,SEEK_CUR); |
2564 | }
|
2564 | }
|
2565 | for (i=0; i<numfiles; i++) |
2565 | for (i=0; i<numfiles; i++) |
2566 | {
|
2566 | {
|
2567 | fread(tempbuf,46,1,fil); |
2567 | fread(tempbuf,46,1,fil); |
2568 | if (*(int32_t *)&tempbuf[0] != LSWAPIB(0x02014b50)) { fclose(fil); return(0); } |
2568 | if (*(int32_t *)&tempbuf[0] != (int32_t)LSWAPIB(0x02014b50)) { fclose(fil); return(0); } |
2569 | 2569 | ||
2570 | j = SSWAPIB(*(int16_t *)&tempbuf[28]); //filename length |
2570 | j = SSWAPIB(*(int16_t *)&tempbuf[28]); //filename length |
2571 | fread(&tempbuf[46],j,1,fil); |
2571 | fread(&tempbuf[46],j,1,fil); |
2572 | tempbuf[j+46] = 0; |
2572 | tempbuf[j+46] = 0; |
2573 | 2573 | ||
Line 2586... | Line 2586... | ||
2586 | j = SSWAPIB(*(int16_t *)&tempbuf[30]); //extra field length |
2586 | j = SSWAPIB(*(int16_t *)&tempbuf[30]); //extra field length |
2587 | j += SSWAPIB(*(int16_t *)&tempbuf[32]); //file comment length |
2587 | j += SSWAPIB(*(int16_t *)&tempbuf[32]); //file comment length |
2588 | fseek(fil,j,SEEK_CUR); |
2588 | fseek(fil,j,SEEK_CUR); |
2589 | }
|
2589 | }
|
2590 | }
|
2590 | }
|
2591 | else if (i == LSWAPIB(0x536e654b)) //'KenS' is GRP file id |
2591 | else if (i == (int32_t)LSWAPIB(0x536e654b)) //'KenS' is GRP file id |
2592 | {
|
2592 | {
|
2593 | fread(tempbuf,12,1,fil); |
2593 | fread(tempbuf,12,1,fil); |
2594 | if ((*(int32_t *)&tempbuf[0] != LSWAPIB(0x65766c69)) || //'ilve' |
2594 | if ((*(int32_t *)&tempbuf[0] != (int32_t)LSWAPIB(0x65766c69)) || //'ilve' |
2595 | (*(int32_t *)&tempbuf[4] != LSWAPIB(0x6e616d72))) //'rman' |
2595 | (*(int32_t *)&tempbuf[4] != (int32_t)LSWAPIB(0x6e616d72))) //'rman' |
2596 | { fclose(fil); return(0); } |
2596 | { fclose(fil); return(0); } |
2597 | numfiles = LSWAPIB(*(int32_t *)&tempbuf[8]); k = ((numfiles+1)<<4); |
2597 | numfiles = LSWAPIB(*(int32_t *)&tempbuf[8]); k = ((numfiles+1)<<4); |
2598 | for (i=0; i<numfiles; i++,k+=leng) |
2598 | for (i=0; i<numfiles; i++,k+=leng) |
2599 | {
|
2599 | {
|
2600 | fread(tempbuf,16,1,fil); |
2600 | fread(tempbuf,16,1,fil); |
Line 2664... | Line 2664... | ||
2664 | return((intptr_t)kzfs.fil); |
2664 | return((intptr_t)kzfs.fil); |
2665 | }
|
2665 | }
|
2666 | else
|
2666 | else
|
2667 | {
|
2667 | {
|
2668 | fread(tempbuf,30,1,fil); |
2668 | fread(tempbuf,30,1,fil); |
2669 | if (*(int32_t *)&tempbuf[0] != LSWAPIB(0x04034b50)) { fclose(fil); return(0); } |
2669 | if (*(int32_t *)&tempbuf[0] != (int32_t)LSWAPIB(0x04034b50)) { fclose(fil); return(0); } |
2670 | fseek(fil,SSWAPIB(*(int16_t *)&tempbuf[26])+SSWAPIB(*(int16_t *)&tempbuf[28]),SEEK_CUR); |
2670 | fseek(fil,SSWAPIB(*(int16_t *)&tempbuf[26])+SSWAPIB(*(int16_t *)&tempbuf[28]),SEEK_CUR); |
2671 | 2671 | ||
2672 | kzfs.fil = fil; |
2672 | kzfs.fil = fil; |
2673 | kzfs.comptyp = SSWAPIB(*(int16_t *)&tempbuf[8]); |
2673 | kzfs.comptyp = SSWAPIB(*(int16_t *)&tempbuf[8]); |
2674 | kzfs.seek0 = ftell(fil); |
2674 | kzfs.seek0 = ftell(fil); |
Line 2678... | Line 2678... | ||
2678 | {
|
2678 | {
|
2679 | case 0: kzfs.i = 0; return((intptr_t)kzfs.fil); |
2679 | case 0: kzfs.i = 0; return((intptr_t)kzfs.fil); |
2680 | case 8: |
2680 | case 8: |
2681 | if (!pnginited) { pnginited = 1; initpngtables(); } |
2681 | if (!pnginited) { pnginited = 1; initpngtables(); } |
2682 | kzfs.comptell = 0; |
2682 | kzfs.comptell = 0; |
2683 | kzfs.compleng = LSWAPIB(*(int32_t *)&tempbuf[18]); |
2683 | kzfs.compleng = (int32_t)LSWAPIB(*(int32_t *)&tempbuf[18]); |
2684 | 2684 | ||
2685 | //WARNING: No file in ZIP can be > 2GB-32K bytes
|
2685 | //WARNING: No file in ZIP can be > 2GB-32K bytes
|
2686 | gslidew = 0x7fffffff; //Force reload at beginning |
2686 | gslidew = 0x7fffffff; //Force reload at beginning |
2687 | 2687 | ||
2688 | return((intptr_t)kzfs.fil); |
2688 | return((intptr_t)kzfs.fil); |