work under bigendian again

SVN revision: 3526
This commit is contained in:
Carsten Haitzler 2000-09-19 16:11:12 +00:00
parent 24a1af7ee0
commit fcdd68dc7e
1 changed files with 29 additions and 31 deletions

View File

@ -82,11 +82,8 @@ load (ImlibImage *im, ImlibProgressFunction progress,
ptr = strrchr(file, ':'); ptr = strrchr(file, ':');
if (ptr) if (ptr)
{ {
int flen;
*ptr = 0; *ptr = 0;
if (!can_read(file)) if (!can_read(file)) return 0;
return 0;
strcpy(key, &(ptr[1])); strcpy(key, &(ptr[1]));
} }
else else
@ -206,14 +203,17 @@ load (ImlibImage *im, ImlibProgressFunction progress,
} }
else else
{ {
int dlen; uLongf dlen;
int x;
dlen = w * h * sizeof(DATA32); dlen = w * h * sizeof(DATA32);
uncompress(im->data, &dlen, body, size - 32); uncompress((Bytef *)im->data, &dlen, (Bytef *)body, (uLongf)(size - 32));
#ifdef WORDS_BIGENDIAN #ifdef WORDS_BIGENDIAN
for (x = 0; x < (im->w * im->h); x++) {
SWAP32(im->data[x]); int x;
for (x = 0; x < (im->w * im->h); x++)
SWAP32(im->data[x]);
}
#endif #endif
if (progress) if (progress)
progress(im, 100, 0, 0, im->w, im->h); progress(im, 100, 0, 0, im->w, im->h);
@ -248,15 +248,11 @@ save (ImlibImage *im, ImlibProgressFunction progress,
cp = strrchr(file, ':'); cp = strrchr(file, ':');
if (cp) if (cp)
{ {
int flen;
*cp = 0; *cp = 0;
if (exists(file)) if (exists(file))
{ {
if (!can_write(file)) if (!can_write(file)) return 0;
return 0; if (!can_read(file)) return 0;
if (!can_read(file))
return 0;
} }
strcpy(key, &(cp[1])); strcpy(key, &(cp[1]));
} }
@ -293,12 +289,14 @@ save (ImlibImage *im, ImlibProgressFunction progress,
{ {
DATA32 *compressed; DATA32 *compressed;
int retr; int retr;
int buflen; uLongf buflen;
compressed = &(buf[8]); compressed = &(buf[8]);
buflen = ((im->w * im->h * sizeof(DATA32) * 101) / 100) + 12; buflen = ((im->w * im->h * sizeof(DATA32) * 101) / 100) + 12;
#ifdef WORDS_BIGENDIAN #ifdef WORDS_BIGENDIAN
{ {
DATA32 *buf2;
buf2 = malloc((((im->w * im->h * 101) / 100) + 3) * sizeof(DATA32)); buf2 = malloc((((im->w * im->h * 101) / 100) + 3) * sizeof(DATA32));
if (buf2) if (buf2)
{ {
@ -307,16 +305,20 @@ save (ImlibImage *im, ImlibProgressFunction progress,
memcpy(buf2, im->data, im->w * im->h * sizeof(DATA32)); memcpy(buf2, im->data, im->w * im->h * sizeof(DATA32));
for (y = 0; y < (im->w * im->h) + 8; y++) for (y = 0; y < (im->w * im->h) + 8; y++)
SWAP32(buf2[y]); SWAP32(buf2[y]);
retr = compress2(compressed, &buflen, buf2, retr = compress2((Bytef *)compressed, &buflen,
im->w * im->h * sizeof(DATA32), compression); (Bytef *)buf2,
(uLong)(im->w * im->h * sizeof(DATA32)),
compression);
free(buf2); free(buf2);
} }
else else
retr = Z_MEM_ERROR; retr = Z_MEM_ERROR;
} }
#else #else
retr = compress2(compressed, &buflen, im->data, retr = compress2((Bytef *)compressed, &buflen,
im->w * im->h * sizeof(DATA32), compression); (Bytef *)im->data,
(uLong)(im->w * im->h * sizeof(DATA32)),
compression);
#endif #endif
if (retr != Z_OK) if (retr != Z_OK)
compressed = 0; compressed = 0;
@ -328,24 +330,20 @@ save (ImlibImage *im, ImlibProgressFunction progress,
size = (8 * sizeof(DATA32)) + buflen; size = (8 * sizeof(DATA32)) + buflen;
} }
} }
if (compression == 0) else
{ {
memcpy(&(buf[8]), im->data, im->w * im->h * sizeof(DATA32)); memcpy(&(buf[8]), im->data, im->w * im->h * sizeof(DATA32));
header[4] = compression; header[4] = compression;
#ifdef WORDS_BIGENDIAN #ifdef WORDS_BIGENDIAN
for (y = 0; y < (im->w * im->h) + 8; y++) {
SWAP32(buf[y]); int y;
for (y = 0; y < (im->w * im->h) + 8; y++)
SWAP32(buf[y]);
}
#endif #endif
size = ((im->w * im->h) + 8) * sizeof(DATA32); size = ((im->w * im->h) + 8) * sizeof(DATA32);
} }
#ifdef WORDS_BIGENDIAN
else
{
int y;
for (y = 0; y < 8; y++)
SWAP32(buf2[y]);
}
#endif
ret = buf; ret = buf;
e_db_data_set(db, key, ret, size); e_db_data_set(db, key, ret, size);
free(buf); free(buf);