forked from old/legacy-imlib2
Move SWAP.. macro definitions to common.h
This commit is contained in:
parent
b2e06bc6bd
commit
7206a84311
|
@ -16,6 +16,24 @@
|
|||
#define DATA16 unsigned short
|
||||
#define DATA8 unsigned char
|
||||
|
||||
#define SWAP32(x) \
|
||||
((((x) & 0x000000ff ) << 24) | \
|
||||
(((x) & 0x0000ff00 ) << 8) | \
|
||||
(((x) & 0x00ff0000 ) >> 8) | \
|
||||
(((x) & 0xff000000 ) >> 24))
|
||||
|
||||
#define SWAP16(x) \
|
||||
((((x) & 0x00ff ) << 8) | \
|
||||
(((x) & 0xff00 ) >> 8))
|
||||
|
||||
#ifdef WORDS_BIGENDIAN
|
||||
#define SWAP_LE_16(x) x = SWAP16(x)
|
||||
#define SWAP_LE_32(x) x = SWAP32(x)
|
||||
#else
|
||||
#define SWAP_LE_16(x)
|
||||
#define SWAP_LE_32(x)
|
||||
#endif
|
||||
|
||||
#ifdef DO_MMX_ASM
|
||||
int __imlib_get_cpuid(void);
|
||||
|
||||
|
|
|
@ -26,7 +26,8 @@ __imlib_GrabXImageToRGBA(DATA32 * data, int ox, int oy, int ow, int oh,
|
|||
int depth, int x, int y, int w, int h, char grab)
|
||||
{
|
||||
int inx, iny;
|
||||
DATA32 *src, *ptr;
|
||||
const DATA32 *src;
|
||||
DATA32 *ptr;
|
||||
int pixel;
|
||||
int origx, origy;
|
||||
int bgr = 0;
|
||||
|
@ -54,14 +55,6 @@ __imlib_GrabXImageToRGBA(DATA32 * data, int ox, int oy, int ow, int oh,
|
|||
if ((depth == 24) && (xim->bits_per_pixel == 32))
|
||||
depth = 25; /* fake depth meaning 24 bit in 32 bpp ximage */
|
||||
/* data needs swapping */
|
||||
#define SWAP32(x) (x) = \
|
||||
((((int)(x) & 0x000000ff ) << 24) |\
|
||||
(((int)(x) & 0x0000ff00 ) << 8) |\
|
||||
(((int)(x) & 0x00ff0000 ) >> 8) |\
|
||||
(((int)(x) & 0xff000000 ) >> 24))
|
||||
#define SWAP16(x) (x) = \
|
||||
((((short)(x) & 0x00ff ) << 8) |\
|
||||
(((short)(x) & 0xff00 ) >> 8))
|
||||
|
||||
#ifdef WORDS_BIGENDIAN
|
||||
if (xim->bitmap_bit_order == LSBFirst)
|
||||
|
@ -91,7 +84,7 @@ __imlib_GrabXImageToRGBA(DATA32 * data, int ox, int oy, int ow, int oh,
|
|||
(unsigned short *)(xim->data + (xim->bytes_per_line * y));
|
||||
for (x = 0; x < w; x++)
|
||||
{
|
||||
SWAP16(*tmp);
|
||||
*tmp = SWAP16(*tmp);
|
||||
tmp++;
|
||||
}
|
||||
}
|
||||
|
@ -106,7 +99,7 @@ __imlib_GrabXImageToRGBA(DATA32 * data, int ox, int oy, int ow, int oh,
|
|||
tmp = (unsigned int *)(xim->data + (xim->bytes_per_line * y));
|
||||
for (x = 0; x < w; x++)
|
||||
{
|
||||
SWAP32(*tmp);
|
||||
*tmp = SWAP32(*tmp);
|
||||
tmp++;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,11 +1,5 @@
|
|||
#include "loader_common.h"
|
||||
|
||||
#define SWAP32(x) (x) = \
|
||||
((((x) & 0x000000ff ) << 24) |\
|
||||
(((x) & 0x0000ff00 ) << 8) |\
|
||||
(((x) & 0x00ff0000 ) >> 8) |\
|
||||
(((x) & 0xff000000 ) >> 24))
|
||||
|
||||
char
|
||||
load(ImlibImage * im, ImlibProgressFunction progress,
|
||||
char progress_granularity, char immediate_load)
|
||||
|
@ -49,7 +43,7 @@ load(ImlibImage * im, ImlibProgressFunction progress,
|
|||
if (((!im->data) && (im->loader)) || (immediate_load) || (progress))
|
||||
{
|
||||
DATA32 *ptr;
|
||||
int y, pl = 0;
|
||||
int y, l, pl = 0;
|
||||
char pper = 0;
|
||||
|
||||
/* must set the im->data member before callign progress function */
|
||||
|
@ -62,22 +56,6 @@ load(ImlibImage * im, ImlibProgressFunction progress,
|
|||
}
|
||||
for (y = 0; y < h; y++)
|
||||
{
|
||||
#ifdef WORDS_BIGENDIAN
|
||||
{
|
||||
int x;
|
||||
|
||||
if (fread(ptr, im->w, 4, f) != 4)
|
||||
{
|
||||
free(im->data);
|
||||
im->data = NULL;
|
||||
im->w = 0;
|
||||
fclose(f);
|
||||
return 0;
|
||||
}
|
||||
for (x = 0; x < im->w; x++)
|
||||
SWAP32(ptr[x]);
|
||||
}
|
||||
#else
|
||||
if (fread(ptr, im->w, 4, f) != 4)
|
||||
{
|
||||
free(im->data);
|
||||
|
@ -86,12 +64,14 @@ load(ImlibImage * im, ImlibProgressFunction progress,
|
|||
fclose(f);
|
||||
return 0;
|
||||
}
|
||||
#ifdef WORDS_BIGENDIAN
|
||||
for (l = 0; l < im->w; l++)
|
||||
SWAP_LE_32(ptr[l]);
|
||||
#endif
|
||||
ptr += im->w;
|
||||
if (progress)
|
||||
{
|
||||
char per;
|
||||
int l;
|
||||
|
||||
per = (char)((100 * y) / im->h);
|
||||
if (((per - pper) >= progress_granularity) ||
|
||||
|
@ -143,7 +123,7 @@ save(ImlibImage * im, ImlibProgressFunction progress, char progress_granularity)
|
|||
|
||||
memcpy(buf, ptr, im->w * 4);
|
||||
for (x = 0; x < im->w; x++)
|
||||
SWAP32(buf[x]);
|
||||
SWAP_LE_32(buf[x]);
|
||||
fwrite(buf, im->w, 4, f);
|
||||
}
|
||||
#else
|
||||
|
|
Loading…
Reference in New Issue