remove fmemopen

master
Eduardo Bart 13 years ago
parent ca38f53e15
commit 7e7d16ee5f

@ -12,6 +12,7 @@ FIND_PACKAGE(Lua51 REQUIRED)
FIND_PACKAGE(YamlCpp REQUIRED) FIND_PACKAGE(YamlCpp REQUIRED)
FIND_PACKAGE(PhysFS REQUIRED) FIND_PACKAGE(PhysFS REQUIRED)
FIND_PACKAGE(GMP REQUIRED) FIND_PACKAGE(GMP REQUIRED)
FIND_PACKAGE(ZLIB REQUIRED)
# choose a default build type if not specified # choose a default build type if not specified
IF(NOT CMAKE_BUILD_TYPE) IF(NOT CMAKE_BUILD_TYPE)
@ -35,6 +36,7 @@ INCLUDE_DIRECTORIES(
${YAMLCPP_INCLUDE_DIR} ${YAMLCPP_INCLUDE_DIR}
${PHYSFS_INCLUDE_DIR} ${PHYSFS_INCLUDE_DIR}
${GMP_INCLUDE_DIR} ${GMP_INCLUDE_DIR}
${ZLIB_INCLUDE_DIR}
"${CMAKE_CURRENT_SOURCE_DIR}/src/framework") "${CMAKE_CURRENT_SOURCE_DIR}/src/framework")
LINK_DIRECTORIES( LINK_DIRECTORIES(
@ -130,4 +132,5 @@ TARGET_LINK_LIBRARIES(otclient
${YAMLCPP_LIBRARY} ${YAMLCPP_LIBRARY}
${PHYSFS_LIBRARY} ${PHYSFS_LIBRARY}
${GMP_LIBRARIES} ${GMP_LIBRARIES}
${ZLIB_LIBRARY}
${ADDITIONAL_LIBRARIES}) ${ADDITIONAL_LIBRARIES})

@ -27,16 +27,9 @@
#include <memory.h> #include <memory.h>
#include <zlib.h> #include <zlib.h>
#include "apngloader.h" #include "apngloader.h"
#include <iostream>
// hack to create a portable fmemopen #include <sstream>
FILE *fmemopen (void *buf, size_t size, const char *opentype) #include <fstream>
{
FILE *f;
f = tmpfile();
fwrite(buf, 1, size, f);
rewind(f);
return f;
}
#if defined(_MSC_VER) && _MSC_VER >= 1300 #if defined(_MSC_VER) && _MSC_VER >= 1300
#define swap16(data) _byteswap_ushort(data) #define swap16(data) _byteswap_ushort(data)
@ -84,21 +77,21 @@ unsigned int palsize, trnssize;
unsigned int hasTRNS; unsigned int hasTRNS;
unsigned short trns1, trns2, trns3; unsigned short trns1, trns2, trns3;
unsigned int read32(FILE * f1) unsigned int read32(std::istream& f1)
{ {
unsigned char a, b, c, d; unsigned char a, b, c, d;
fread(&a, 1, 1, f1); f1.read((char*)&a, 1);
fread(&b, 1, 1, f1); f1.read((char*)&b, 1);
fread(&c, 1, 1, f1); f1.read((char*)&c, 1);
fread(&d, 1, 1, f1); f1.read((char*)&d, 1);
return ((unsigned int)a<<24)+((unsigned int)b<<16)+((unsigned int)c<<8)+(unsigned int)d; return ((unsigned int)a<<24)+((unsigned int)b<<16)+((unsigned int)c<<8)+(unsigned int)d;
} }
unsigned short read16(FILE * f1) unsigned short read16(std::istream& f1)
{ {
unsigned char a, b; unsigned char a, b;
fread(&a, 1, 1, f1); f1.read((char*)&a, 1);
fread(&b, 1, 1, f1); f1.read((char*)&b, 1);
return ((unsigned short)a<<8)+(unsigned short)b; return ((unsigned short)a<<8)+(unsigned short)b;
} }
@ -516,7 +509,6 @@ void compose6(unsigned char * dst, unsigned int dstbytes, unsigned char * src, u
int load_apng(unsigned char *filedata, unsigned int filesize, struct apng_data *apng) int load_apng(unsigned char *filedata, unsigned int filesize, struct apng_data *apng)
{ {
int res;
unsigned int i, j; unsigned int i, j;
unsigned int rowbytes; unsigned int rowbytes;
int imagesize, zbuf_size, zsize, trns_idx; int imagesize, zbuf_size, zsize, trns_idx;
@ -530,9 +522,8 @@ int load_apng(unsigned char *filedata, unsigned int filesize, struct apng_data *
unsigned char coltype, compr, filter, interl; unsigned char coltype, compr, filter, interl;
z_stream zstream; z_stream zstream;
memset(apng, 0, sizeof(struct apng_data)); memset(apng, 0, sizeof(struct apng_data));
FILE * f1 = fmemopen(filedata, filesize, "rb"); std::istringstream f1;
if(!f1) f1.rdbuf()->pubsetbuf((char*)filedata, filesize);
return -1;
for (i=0; i<256; i++) for (i=0; i<256; i++)
{ {
@ -569,10 +560,8 @@ int load_apng(unsigned char *filedata, unsigned int filesize, struct apng_data *
unsigned char * pDst2; unsigned char * pDst2;
unsigned int * frames_delay; unsigned int * frames_delay;
if ((res = fread(sig, 1, 8, f1)) == 8) f1.read((char*)sig, 8);
{ if(f1.good() && memcmp(sig, png_sign, 8) == 0) {
if (memcmp(sig, png_sign, 8) == 0)
{
len = read32(f1); len = read32(f1);
chunk = read32(f1); chunk = read32(f1);
@ -580,11 +569,11 @@ int load_apng(unsigned char *filedata, unsigned int filesize, struct apng_data *
{ {
w = w0 = read32(f1); w = w0 = read32(f1);
h = h0 = read32(f1); h = h0 = read32(f1);
fread(&depth, 1, 1, f1); f1.read((char*)&depth, 1);
fread(&coltype, 1, 1, f1); f1.read((char*)&coltype, 1);
fread(&compr, 1, 1, f1); f1.read((char*)&compr, 1);
fread(&filter, 1, 1, f1); f1.read((char*)&filter, 1);
fread(&interl, 1, 1, f1); f1.read((char*)&interl, 1);
crc = read32(f1); crc = read32(f1);
channels = 1; channels = 1;
@ -627,7 +616,7 @@ int load_apng(unsigned char *filedata, unsigned int filesize, struct apng_data *
memset(pOut1, 0, outimg1); memset(pOut1, 0, outimg1);
memset(pOut2, 0, outimg2); memset(pOut2, 0, outimg2);
while ( !feof(f1) ) while (!f1.eof())
{ {
len = read32(f1); len = read32(f1);
chunk = read32(f1); chunk = read32(f1);
@ -637,7 +626,7 @@ int load_apng(unsigned char *filedata, unsigned int filesize, struct apng_data *
unsigned int col; unsigned int col;
for (i=0; i<len; i++) for (i=0; i<len; i++)
{ {
fread(&c, 1, 1, f1); f1.read((char*)&c, 1);
col = i/3; col = i/3;
if (col<256) if (col<256)
{ {
@ -652,7 +641,7 @@ int load_apng(unsigned char *filedata, unsigned int filesize, struct apng_data *
hasTRNS = 1; hasTRNS = 1;
for (i=0; i<len; i++) for (i=0; i<len; i++)
{ {
fread(&c, 1, 1, f1); f1.read((char*)&c, 1);
if (i<256) if (i<256)
{ {
trns[i] = c; trns[i] = c;
@ -766,8 +755,8 @@ int load_apng(unsigned char *filedata, unsigned int filesize, struct apng_data *
y0 = read32(f1); y0 = read32(f1);
d1 = read16(f1); d1 = read16(f1);
d2 = read16(f1); d2 = read16(f1);
fread(&dop, 1, 1, f1); f1.read((char*)&dop, 1);
fread(&bop, 1, 1, f1); f1.read((char*)&bop, 1);
crc = read32(f1); crc = read32(f1);
if(d2 == 0) if(d2 == 0)
@ -791,7 +780,7 @@ int load_apng(unsigned char *filedata, unsigned int filesize, struct apng_data *
} }
else if (chunk == 0x49444154) /* IDAT */ else if (chunk == 0x49444154) /* IDAT */
{ {
fread(pData + zsize, 1, len, f1); f1.read((char*)(pData + zsize), len);
zsize += len; zsize += len;
crc = read32(f1); crc = read32(f1);
} }
@ -799,7 +788,7 @@ int load_apng(unsigned char *filedata, unsigned int filesize, struct apng_data *
{ {
seq = read32(f1); seq = read32(f1);
len -= 4; len -= 4;
fread(pData + zsize, 1, len, f1); f1.read((char*)(pData + zsize), len);
zsize += len; zsize += len;
crc = read32(f1); crc = read32(f1);
} }
@ -829,7 +818,7 @@ int load_apng(unsigned char *filedata, unsigned int filesize, struct apng_data *
c = (unsigned char)(chunk & 0xFF); c = (unsigned char)(chunk & 0xFF);
if (notabc(c)) break; if (notabc(c)) break;
fseek( f1, len, SEEK_CUR ); f1.seekg(len, std::ios_base::cur);
crc = read32(f1); crc = read32(f1);
} }
} }
@ -870,8 +859,6 @@ int load_apng(unsigned char *filedata, unsigned int filesize, struct apng_data *
return -1; return -1;
} else } else
return -1; return -1;
} else
return -1;
return 0; return 0;
} }

Loading…
Cancel
Save