Indent (most) .c files.

SVN revision: 58518
This commit is contained in:
Kim Woelders 2011-04-09 09:24:44 +00:00
parent 4c55d2c3f6
commit 41c3a967d0
30 changed files with 2420 additions and 2163 deletions

View File

@ -55,9 +55,8 @@ main(int argc, char **argv)
vis = DefaultVisual(disp, DefaultScreen(disp));
depth = DefaultDepth(disp, DefaultScreen(disp));
cm = DefaultColormap(disp, DefaultScreen(disp));
win =
XCreateSimpleWindow(disp, DefaultRootWindow(disp), 0, 0, 100, 100, 0, 0,
0);
win = XCreateSimpleWindow(disp, DefaultRootWindow(disp), 0, 0, 100, 100,
0, 0, 0);
XSelectInput(disp, win,
ButtonPressMask | ButtonReleaseMask | ButtonMotionMask |
PointerMotionMask | ExposureMask);
@ -122,7 +121,8 @@ main(int argc, char **argv)
* first = 0; */
imlib_apply_filter
("bump_map_point(x=[],y=[],map="PACKAGE_DATA_DIR"/data/images/imlib2.png);", &x, &y);
("bump_map_point(x=[],y=[],map=" PACKAGE_DATA_DIR
"/data/images/imlib2.png);", &x, &y);
temp2 = im_bg;
im_bg = temp;

View File

@ -45,9 +45,8 @@ main(int argc, char **argv)
vis = DefaultVisual(disp, DefaultScreen(disp));
depth = DefaultDepth(disp, DefaultScreen(disp));
cm = DefaultColormap(disp, DefaultScreen(disp));
win =
XCreateSimpleWindow(disp, DefaultRootWindow(disp), 0, 0, 100, 100, 0, 0,
0);
win = XCreateSimpleWindow(disp, DefaultRootWindow(disp), 0, 0, 100, 100,
0, 0, 0);
XSelectInput(disp, win,
ButtonPressMask | ButtonReleaseMask | ButtonMotionMask |
PointerMotionMask | ExposureMask | KeyPressMask);

View File

@ -23,7 +23,8 @@ int image_width = 0, image_height = 0;
static void
usage(void)
{
printf("Usage: imlib2_grab [-v] [-id <drawable id>] [-width <width>] [-height <height>] [-noshape] <output file>\n");
printf
("Usage: imlib2_grab [-v] [-id <drawable id>] [-width <width>] [-height <height>] [-noshape] <output file>\n");
}
int

View File

@ -44,9 +44,8 @@ main(int argc, char **argv)
vis = DefaultVisual(disp, DefaultScreen(disp));
depth = DefaultDepth(disp, DefaultScreen(disp));
cm = DefaultColormap(disp, DefaultScreen(disp));
win =
XCreateSimpleWindow(disp, DefaultRootWindow(disp), 0, 0, 100, 100, 0, 0,
0);
win = XCreateSimpleWindow(disp, DefaultRootWindow(disp), 0, 0, 100, 100,
0, 0, 0);
XSelectInput(disp, win,
ButtonPressMask | ButtonReleaseMask | ButtonMotionMask |
PointerMotionMask | ExposureMask | KeyPressMask);

View File

@ -265,6 +265,7 @@ main(int argc, char **argv)
if (!blendtest)
{
const char *display_name = getenv("DISPLAY");
if (!display_name)
display_name = ":0";
disp = XOpenDisplay(display_name);
@ -986,19 +987,32 @@ main(int argc, char **argv)
im_sh1 = imlib_load_image(PACKAGE_DATA_DIR "/data/images/sh1.png");
im_sh2 = imlib_load_image(PACKAGE_DATA_DIR "/data/images/sh2.png");
im_sh3 = imlib_load_image(PACKAGE_DATA_DIR "/data/images/sh3.png");
im_ic[0] = imlib_load_image(PACKAGE_DATA_DIR"/data/images/audio.png");
im_ic[1] = imlib_load_image(PACKAGE_DATA_DIR"/data/images/folder.png");
im_ic[2] = imlib_load_image(PACKAGE_DATA_DIR"/data/images/mush.png");
im_ic[3] = imlib_load_image(PACKAGE_DATA_DIR"/data/images/paper.png");
im_ic[4] = imlib_load_image(PACKAGE_DATA_DIR"/data/images/mail.png");
im_ic[5] = imlib_load_image(PACKAGE_DATA_DIR"/data/images/calc.png");
im_ic[6] = imlib_load_image(PACKAGE_DATA_DIR"/data/images/cal.png");
im_ic[7] = imlib_load_image(PACKAGE_DATA_DIR"/data/images/stop.png");
im_ic[8] = imlib_load_image(PACKAGE_DATA_DIR"/data/images/globe.png");
im_ic[9] = imlib_load_image(PACKAGE_DATA_DIR"/data/images/menu.png");
im_ic[10] = imlib_load_image(PACKAGE_DATA_DIR"/data/images/tnt.png");
im_ic[11] = imlib_load_image(PACKAGE_DATA_DIR"/data/images/bulb.png");
im_ic[12] = imlib_load_image(PACKAGE_DATA_DIR"/data/images/lock.png");
im_ic[0] =
imlib_load_image(PACKAGE_DATA_DIR "/data/images/audio.png");
im_ic[1] =
imlib_load_image(PACKAGE_DATA_DIR "/data/images/folder.png");
im_ic[2] =
imlib_load_image(PACKAGE_DATA_DIR "/data/images/mush.png");
im_ic[3] =
imlib_load_image(PACKAGE_DATA_DIR "/data/images/paper.png");
im_ic[4] =
imlib_load_image(PACKAGE_DATA_DIR "/data/images/mail.png");
im_ic[5] =
imlib_load_image(PACKAGE_DATA_DIR "/data/images/calc.png");
im_ic[6] =
imlib_load_image(PACKAGE_DATA_DIR "/data/images/cal.png");
im_ic[7] =
imlib_load_image(PACKAGE_DATA_DIR "/data/images/stop.png");
im_ic[8] =
imlib_load_image(PACKAGE_DATA_DIR "/data/images/globe.png");
im_ic[9] =
imlib_load_image(PACKAGE_DATA_DIR "/data/images/menu.png");
im_ic[10] =
imlib_load_image(PACKAGE_DATA_DIR "/data/images/tnt.png");
im_ic[11] =
imlib_load_image(PACKAGE_DATA_DIR "/data/images/bulb.png");
im_ic[12] =
imlib_load_image(PACKAGE_DATA_DIR "/data/images/lock.png");
imlib_context_set_image(im);
if (first)

View File

@ -111,7 +111,8 @@ main(int argc, char **argv)
case MotionNotify:
/* if the mouse moves - note it */
/* add a rectangle update for the new mouse position */
image = imlib_load_image(PACKAGE_DATA_DIR"/data/images/mush.png");
image =
imlib_load_image(PACKAGE_DATA_DIR "/data/images/mush.png");
imlib_context_set_image(image);
w = imlib_image_get_width();
h = imlib_image_get_height();

View File

@ -33,6 +33,7 @@ __imlib_BestVisual(Display * d, int screen, int *depth_return)
XVisualInfo xvi, *xvir;
int j, i, num, maxd = 0;
Visual *v = NULL;
const int visprefs[] = {
PseudoColor, TrueColor, DirectColor, StaticColor, GrayScale, StaticGray
};

View File

@ -136,18 +136,14 @@ __imlib_RenderGetPixel(Display * d, Drawable w, Visual * v, Colormap cm,
return 0;
}
__hidden void
__imlib_generic_render(DATA32 * src, int jump, int w, int h, int dx, int dy,
XImage * xim, Visual * v,
Context * ct);
void
static void
__imlib_generic_render(DATA32 * src, int jump, int w, int h, int dx, int dy,
XImage * xim, Visual * v, Context * ct)
{
unsigned int x, y, r, g, b, val, hh;
unsigned int rmask, gmask, bmask;
int i, rshift, gshift, bshift;
const DATA8 _dither_88[8][8] = {
{0, 32, 8, 40, 2, 34, 10, 42},
{48, 16, 56, 24, 50, 18, 58, 26},

View File

@ -205,14 +205,16 @@ load(ImlibImage * im, ImlibProgressFunction progress,
if (headSize == 12)
{
ncols /= 3;
if (ncols > 256) ncols = 256;
if (ncols > 256)
ncols = 256;
for (i = 0; i < ncols; i++)
fread(&rgbQuads[i], 3, 1, f);
}
else
{
ncols /= 4;
if (ncols > 256) ncols = 256;
if (ncols > 256)
ncols = 256;
fread(rgbQuads, 4, ncols, f);
}
}
@ -227,19 +229,25 @@ load(ImlibImage * im, ImlibProgressFunction progress,
ReadleLong(f, &bmask);
for (bit = bitcount - 1; bit >= 0; bit--)
{
if (bmask & (1 << bit)) bshift = bit;
if (gmask & (1 << bit)) gshift = bit;
if (rmask & (1 << bit)) rshift = bit;
if (bmask & (1 << bit))
bshift = bit;
if (gmask & (1 << bit))
gshift = bit;
if (rmask & (1 << bit))
rshift = bit;
}
while(((((0xffffL & bmask) >> bshift) << bleftshift) & 0x80) == 0)
while (((((0xffffL & bmask) >> bshift) << bleftshift) & 0x80) ==
0)
{
bleftshift++;
}
while(((((0xffffL & gmask) >> gshift) << gleftshift) & 0x80) == 0)
while (((((0xffffL & gmask) >> gshift) << gleftshift) & 0x80) ==
0)
{
gleftshift++;
}
while(((((0xffffL & rmask) >> rshift) << rleftshift) & 0x80) == 0)
while (((((0xffffL & rmask) >> rshift) << rleftshift) & 0x80) ==
0)
{
rleftshift++;
}
@ -373,10 +381,12 @@ load(ImlibImage * im, ImlibProgressFunction progress,
* 21.3.2006: This is better than using 'if buffer_ptr + 1 < buffer_end'
*/
unsigned char *buffer_end_minus_1 = buffer_end - 1;
x = 0;
y = 0;
for (i = 0; i < imgsize && buffer_ptr < buffer_end_minus_1; i++)
for (i = 0; i < imgsize && buffer_ptr < buffer_end_minus_1;
i++)
{
byte1 = buffer_ptr[0];
byte2 = buffer_ptr[1];
@ -387,21 +397,26 @@ load(ImlibImage * im, ImlibProgressFunction progress,
l = byte1;
/* Check for invalid length */
if (l + x > w) goto _bail;
if (l + x > w)
goto _bail;
t1 = 0xff000000 | (rgbQuads[byte2 >> 4].rgbRed << 16) |
t1 = 0xff000000 |
(rgbQuads[byte2 >> 4].rgbRed << 16) |
(rgbQuads[byte2 >> 4].rgbGreen << 8) |
(rgbQuads[byte2 >> 4].rgbBlue);
t2 = 0xff000000 | (rgbQuads[byte2 & 0xF].rgbRed << 16) |
t2 = 0xff000000 |
(rgbQuads[byte2 & 0xF].rgbRed << 16) |
(rgbQuads[byte2 & 0xF].rgbGreen << 8) |
(rgbQuads[byte2 & 0xF].rgbBlue);
for (j = l/2; j; j--) {
for (j = l / 2; j; j--)
{
ptr[0] = t1;
ptr[1] = t2;
ptr += 2;
}
/* tail */
if (l & 1) *ptr++ = t1;
if (l & 1)
*ptr++ = t1;
x += l;
}
else
@ -410,41 +425,56 @@ load(ImlibImage * im, ImlibProgressFunction progress,
{
case RLE_NEXT:
x = 0;
if (++y >= h) goto _bail;
if (++y >= h)
goto _bail;
ptr = im->data + (h - y - 1) * w;
break;
case RLE_END:
goto _bail;
case RLE_MOVE:
/* Need to read two bytes */
if (buffer_ptr >= buffer_end_minus_1) goto _bail;
if (buffer_ptr >= buffer_end_minus_1)
goto _bail;
x += buffer_ptr[0];
y += buffer_ptr[1];
buffer_ptr += 2;
/* Check for correct coordinates */
if (x >= w) goto _bail;
if (y >= h) goto _bail;
if (x >= w)
goto _bail;
if (y >= h)
goto _bail;
ptr = im->data + (h - y - 1) * w + x;
break;
default:
l = byte2;
/* Check for invalid length and valid buffer size */
if (l + x > w) goto _bail;
if (buffer_ptr + (l >> 1) + (l & 1) > buffer_end) goto _bail;
if (l + x > w)
goto _bail;
if (buffer_ptr + (l >> 1) + (l & 1) >
buffer_end)
goto _bail;
for (j = l/2; j; j--) {
for (j = l / 2; j; j--)
{
byte = *buffer_ptr++;
ptr[0] = 0xff000000 | (rgbQuads[byte >> 4].rgbRed << 16) |
ptr[0] =
0xff000000 |
(rgbQuads[byte >> 4].rgbRed << 16) |
(rgbQuads[byte >> 4].rgbGreen << 8) |
(rgbQuads[byte >> 4].rgbBlue);
ptr[1] = 0xff000000 | (rgbQuads[byte & 0xF].rgbRed << 16) |
ptr[1] =
0xff000000 |
(rgbQuads[byte & 0xF].rgbRed << 16) |
(rgbQuads[byte & 0xF].rgbGreen << 8) |
(rgbQuads[byte & 0xF].rgbBlue);
ptr += 2;
}
if (l & 1) {
if (l & 1)
{
byte = *buffer_ptr++;
*ptr++ = 0xff000000 | (rgbQuads[byte >> 4].rgbRed << 16) |
*ptr++ =
0xff000000 |
(rgbQuads[byte >> 4].rgbRed << 16) |
(rgbQuads[byte >> 4].rgbGreen << 8) |
(rgbQuads[byte >> 4].rgbBlue);
}
@ -531,21 +561,26 @@ load(ImlibImage * im, ImlibProgressFunction progress,
* 21.3.2006: This is better than using 'if buffer_ptr + 1 < buffer_end'
*/
unsigned char *buffer_end_minus_1 = buffer_end - 1;
x = 0;
y = 0;
for (i = 0; i < imgsize && buffer_ptr < buffer_end_minus_1; i++)
for (i = 0; i < imgsize && buffer_ptr < buffer_end_minus_1;
i++)
{
byte1 = buffer_ptr[0];
byte2 = buffer_ptr[1];
buffer_ptr += 2;
if (byte1)
{
DATA32 pix = 0xff000000 | (rgbQuads[byte2].rgbRed << 16) |
DATA32 pix =
0xff000000 | (rgbQuads[byte2].rgbRed << 16) |
(rgbQuads[byte2].rgbGreen << 8) |
(rgbQuads[byte2].rgbBlue);
l = byte1;
if (x + l > w) goto _bail;
for (j = l; j; j--) *ptr++ = pix;
if (x + l > w)
goto _bail;
for (j = l; j; j--)
*ptr++ = pix;
x += l;
}
else
@ -554,26 +589,32 @@ load(ImlibImage * im, ImlibProgressFunction progress,
{
case RLE_NEXT:
x = 0;
if (++y >= h) goto _bail;
if (++y >= h)
goto _bail;
ptr = im->data + ((h - y - 1) * w) + x;
break;
case RLE_END:
goto _bail;
case RLE_MOVE:
/* Need to read two bytes */
if (buffer_ptr >= buffer_end_minus_1) goto _bail;
if (buffer_ptr >= buffer_end_minus_1)
goto _bail;
x += buffer_ptr[0];
y += buffer_ptr[1];
buffer_ptr += 2;
/* Check for correct coordinates */
if (x >= w) goto _bail;
if (y >= h) goto _bail;
if (x >= w)
goto _bail;
if (y >= h)
goto _bail;
ptr = im->data + ((h - y - 1) * w) + x;
break;
default:
l = byte2;
if (x + l > w) goto _bail;
if (buffer_ptr + l > buffer_end) goto _bail;
if (x + l > w)
goto _bail;
if (buffer_ptr + l > buffer_end)
goto _bail;
for (j = 0; j < l; j++)
{
byte = *(buffer_ptr++);
@ -656,6 +697,7 @@ load(ImlibImage * im, ImlibProgressFunction progress,
{
/* 21.3.2006 - Need to check for buffer_ptr + 1 < buffer_end */
unsigned char *buffer_end_minus_1 = buffer_end - 1;
skip = (((w * 16 + 31) / 32) * 4) - (w * 2);
for (y = 0; y < h; y++)
{
@ -671,7 +713,10 @@ load(ImlibImage * im, ImlibProgressFunction progress,
* *ptr++ = 0xff000000 | (r << 16) | (g << 8) | b;
*/
unsigned short pix = *(unsigned short *)buffer_ptr;
*ptr++ = 0xff000000 | ((((pix & rmask) >> rshift) << rleftshift) << 16) |
*ptr++ =
0xff000000 |
((((pix & rmask) >> rshift) << rleftshift) << 16) |
((((pix & gmask) >> gshift) << gleftshift) << 8) |
((((pix & bmask) >> bshift) << bleftshift));
buffer_ptr += 2;
@ -705,6 +750,7 @@ load(ImlibImage * im, ImlibProgressFunction progress,
{
/* 21.3.2006 - Fix: need to check for buffer_ptr + 2 < buffer_end */
unsigned char *buffer_end_minus_2 = buffer_end - 2;
skip = (4 - ((w * 3) % 4)) & 3;
for (y = 0; y < h; y++)
{
@ -744,6 +790,7 @@ load(ImlibImage * im, ImlibProgressFunction progress,
{
/* 21.3.2006 - Need to check buffer_ptr + 3 < buffer_end */
unsigned char *buffer_end_minus_3 = buffer_end_minus_3;
skip = (((w * 32 + 31) / 32) * 4) - (w * 4);
for (y = 0; y < h; y++)
{
@ -762,6 +809,7 @@ load(ImlibImage * im, ImlibProgressFunction progress,
/* TODO: What about alpha channel...Is used? */
DATA32 pix = *(unsigned int *)buffer_ptr;
*ptr++ = 0xff000000 | (((pix & rmask) >> rshift) << 16) |
(((pix & gmask) >> gshift) << 8) |
(((pix & bmask) >> bshift));

View File

@ -8,7 +8,8 @@
#define OUTBUF_SIZE 16384
#define INBUF_SIZE 1024
static int uncompress_file (FILE *fp, int dest)
static int
uncompress_file(FILE * fp, int dest)
{
BZFILE *bf;
DATA8 outbuf[OUTBUF_SIZE];
@ -16,12 +17,14 @@ static int uncompress_file (FILE *fp, int dest)
bf = BZ2_bzReadOpen(&error, fp, 0, 0, NULL, 0);
if (error != BZ_OK) {
if (error != BZ_OK)
{
BZ2_bzReadClose(NULL, bf);
return 0;
}
while (1) {
while (1)
{
bytes = BZ2_bzRead(&error, bf, &outbuf, OUTBUF_SIZE);
if (error == BZ_OK || error == BZ_STREAM_END)
@ -29,7 +32,8 @@ static int uncompress_file (FILE *fp, int dest)
if (error == BZ_STREAM_END)
break;
else if (error != BZ_OK) {
else if (error != BZ_OK)
{
ret = 0;
break;
}
@ -40,7 +44,8 @@ static int uncompress_file (FILE *fp, int dest)
return ret;
}
char load (ImlibImage *im, ImlibProgressFunction progress,
char
load(ImlibImage * im, ImlibProgressFunction progress,
char progress_granularity, char immediate_load)
{
ImlibLoader *loader;
@ -55,10 +60,12 @@ char load (ImlibImage *im, ImlibProgressFunction progress,
* (e.g. "foo.png.bz2"
*/
p = strrchr(im->real_file, '.');
if (p && p != im->real_file) {
if (p && p != im->real_file)
{
if (strcasecmp(p + 1, "bz2"))
return 0;
} else
}
else
return 0;
strncpy(real_ext, p - sizeof(real_ext) + 1, sizeof(real_ext));
@ -68,11 +75,13 @@ char load (ImlibImage *im, ImlibProgressFunction progress,
if (!strrchr(real_ext, '.'))
return 0;
if (!(fp = fopen (im->real_file, "rb"))) {
if (!(fp = fopen(im->real_file, "rb")))
{
return 0;
}
if ((dest = mkstemp (tmp)) < 0) {
if ((dest = mkstemp(tmp)) < 0)
{
fclose(fp);
return 0;
}
@ -81,12 +90,14 @@ char load (ImlibImage *im, ImlibProgressFunction progress,
fclose(fp);
close(dest);
if (!res) {
if (!res)
{
unlink(tmp);
return 0;
}
if (!(loader = __imlib_FindBestLoaderForFile (real_ext, 0))) {
if (!(loader = __imlib_FindBestLoaderForFile(real_ext, 0)))
{
unlink(tmp);
return 0;
}
@ -105,7 +116,8 @@ char load (ImlibImage *im, ImlibProgressFunction progress,
return 1;
}
void formats (ImlibLoader *l)
void
formats(ImlibLoader * l)
{
/* this is the only bit you have to change... */
char *list_formats[] = { "bz2" };

View File

@ -126,7 +126,8 @@ load(ImlibImage * im, ImlibProgressFunction progress, char progress_granularity,
DGifGetExtensionNext(gif, &ext);
}
}
} while (rec != TERMINATE_RECORD_TYPE);
}
while (rec != TERMINATE_RECORD_TYPE);
if (transp >= 0)
{
SET_FLAG(im->flags, F_HAS_ALPHA);

View File

@ -21,8 +21,7 @@
#define UNLIKELY(exp) (exp)
#endif
typedef struct context
{
typedef struct context {
int id;
char *filename;
struct id3_tag *tag;
@ -38,50 +37,54 @@ id3_tag_get_frame (struct id3_tag* tag, size_t index)
return tag->frames[index];
}
static inline size_t id3_tag_get_numframes (struct id3_tag* tag)
static inline size_t
id3_tag_get_numframes(struct id3_tag *tag)
{
return tag->nframes;
}
static inline char const* id3_frame_id (struct id3_frame* frame)
static inline char const *
id3_frame_id(struct id3_frame *frame)
{
return frame->id;
}
static context* context_create (const char* filename)
static context *
context_create(const char *filename)
{
context *node = (context *) malloc(sizeof(context));
context *ptr, *last;
int last_id = INT_MAX;
node->refcount = 1;
{
struct id3_file *file;
struct id3_tag *tag;
unsigned int i;
file = id3_file_open(filename, ID3_FILE_MODE_READONLY);
if (! file) {
if (!file)
{
fprintf(stderr, "Unable to open tagged file %s: %s\n",
filename, strerror(errno));
goto fail_free;
}
tag = id3_file_tag(file);
if (! tag) {
fprintf (stderr,
"Unable to find ID3v2 tags in file %s\n",
filename);
if (!tag)
{
fprintf(stderr, "Unable to find ID3v2 tags in file %s\n", filename);
id3_file_close(file);
goto fail_free;
}
node->tag = id3_tag_new();
for (i = 0; i < id3_tag_get_numframes(tag); i++)
if (! strcmp (id3_frame_id
(id3_tag_get_frame (tag, i)), "APIC"))
id3_tag_attachframe (node->tag,
id3_tag_get_frame (tag, i));
if (!strcmp(id3_frame_id(id3_tag_get_frame(tag, i)), "APIC"))
id3_tag_attachframe(node->tag, id3_tag_get_frame(tag, i));
id3_file_close(file);
}
node->filename = strdup(filename);
if (! id3_ctxs) {
if (!id3_ctxs)
{
node->id = 1;
node->next = NULL;
id3_ctxs = node;
@ -89,21 +92,26 @@ static context* context_create (const char* filename)
}
ptr = id3_ctxs;
last = NULL;
while (UNLIKELY (ptr && (ptr->id + 1) >= last_id)) {
while (UNLIKELY(ptr && (ptr->id + 1) >= last_id))
{
last_id = ptr->id;
last = ptr;
ptr = ptr->next;
}
/* Paranoid! this can occur only if there are INT_MAX contexts :) */
if (UNLIKELY (!ptr)) {
if (UNLIKELY(!ptr))
{
fprintf(stderr, "Too many open ID3 contexts\n");
goto fail_close;
}
node->id = ptr->id + 1;
if (UNLIKELY (!!last)) {
if (UNLIKELY(! !last))
{
node->next = last->next;
last->next = node;
} else {
}
else
{
node->next = id3_ctxs;
id3_ctxs = node;
}
@ -117,23 +125,29 @@ fail_free:
return NULL;
}
static void context_destroy (context* ctx)
static void
context_destroy(context * ctx)
{
id3_tag_delete(ctx->tag);
free(ctx->filename);
free(ctx);
}
static inline void context_addref (context* ctx)
static inline void
context_addref(context * ctx)
{
ctx->refcount++;
}
static context* context_get (int id)
static context *
context_get(int id)
{
context *ptr = id3_ctxs;
while (ptr) {
if (ptr->id == id) {
while (ptr)
{
if (ptr->id == id)
{
context_addref(ptr);
return ptr;
}
@ -143,11 +157,15 @@ static context* context_get (int id)
return NULL;
}
static context* context_get_by_name (const char* name)
static context *
context_get_by_name(const char *name)
{
context *ptr = id3_ctxs;
while (ptr) {
if (! strcmp (name, ptr->filename)) {
while (ptr)
{
if (!strcmp(name, ptr->filename))
{
context_addref(ptr);
return ptr;
}
@ -156,13 +174,18 @@ static context* context_get_by_name (const char* name)
return NULL;
}
static void context_delref (context* ctx)
static void
context_delref(context * ctx)
{
ctx->refcount--;
if (ctx->refcount <= 0) {
if (ctx->refcount <= 0)
{
context *last = NULL, *ptr = id3_ctxs;
while (ptr) {
if (ptr == ctx) {
while (ptr)
{
if (ptr == ctx)
{
if (last)
last->next = ctx->next;
else
@ -176,55 +199,68 @@ static void context_delref (context* ctx)
}
}
static int str2int (char* str, int old)
static int
str2int(char *str, int old)
{
long index;
errno = 0;
index = strtol(str, NULL, 10);
return ((errno || index > INT_MAX) ? old : (int)index);
}
static size_t str2uint (char* str, size_t old)
static size_t
str2uint(char *str, size_t old)
{
unsigned long index;
errno = 0;
index = strtoul(str, NULL, 10);
return ((errno || index > UINT_MAX) ? old : (size_t) index);
}
static void destructor_data (ImlibImage* im, void* data)
static void
destructor_data(ImlibImage * im, void *data)
{
free(data);
}
static void destructor_context (ImlibImage* im, void* data)
static void
destructor_context(ImlibImage * im, void *data)
{
context_delref((context *) data);
}
typedef struct lopt
{
typedef struct lopt {
context *ctx;
size_t index;
int traverse;
char cache_level;
} lopt;
static char get_options (lopt* opt, ImlibImage* im)
static char
get_options(lopt * opt, ImlibImage * im)
{
size_t handle = 0, index = 0, traverse = 0;
context *ctx;
if (im->key) {
if (im->key)
{
char *key = strdup(im->key);
char *tok = strtok(key, ",");
traverse = 0;
while (tok) {
while (tok)
{
char *value = strchr(tok, '=');
if (! value) {
if (!value)
{
value = tok;
tok = "index";
} else {
}
else
{
*value = '\0';
value++;
}
@ -237,11 +273,14 @@ static char get_options (lopt* opt, ImlibImage* im)
tok = strtok(NULL, ",");
}
free(key);
} else
}
else
traverse = 1;
if (! handle) {
if (!handle)
{
ImlibImageTag *htag = __imlib_GetTag(im, "context");
if (htag && htag->val)
handle = htag->val;
}
@ -251,13 +290,16 @@ static char get_options (lopt* opt, ImlibImage* im)
!(ctx = context_create(im->real_file)))
return 0;
if (! index) {
if (!index)
{
ImlibImageTag *htag = __imlib_GetTag(im, "index");
if (htag && htag->val)
index = htag->val;
}
if (index < 0 || index > id3_tag_get_numframes(ctx->tag) ||
(index == 0 && id3_tag_get_numframes (ctx->tag) < 1)) {
(index == 0 && id3_tag_get_numframes(ctx->tag) < 1))
{
if (index)
fprintf(stderr, "No picture frame # %d found\n", index);
context_delref(ctx);
@ -273,7 +315,8 @@ static char get_options (lopt* opt, ImlibImage* im)
return 1;
}
static int extract_pic (struct id3_frame* frame, int dest)
static int
extract_pic(struct id3_frame *frame, int dest)
{
union id3_field *field;
unsigned char const *data;
@ -282,13 +325,17 @@ static int extract_pic (struct id3_frame* frame, int dest)
field = id3_frame_field(frame, 4);
data = id3_field_getbinarydata(field, &length);
if (! data) {
if (!data)
{
fprintf(stderr, "No image data found for frame\n");
return 0;
}
while (length > 0) {
while (length > 0)
{
ssize_t res;
if ((res = write (dest, data + done, length)) < 0) {
if ((res = write(dest, data + done, length)) < 0)
{
if (errno == EINTR)
continue;
perror("Unable to write to file");
@ -302,7 +349,8 @@ static int extract_pic (struct id3_frame* frame, int dest)
#define EXT_LEN 14
static char get_loader (lopt* opt, ImlibLoader** loader)
static char
get_loader(lopt * opt, ImlibLoader ** loader)
{
union id3_field *field;
char const *data;
@ -311,25 +359,27 @@ static char get_loader (lopt* opt, ImlibLoader** loader)
ext[EXT_LEN + 1] = '\0';
ext[0] = '.';
field = id3_frame_field (id3_tag_get_frame (opt->ctx->tag,
opt->index - 1), 1);
field = id3_frame_field(id3_tag_get_frame(opt->ctx->tag, opt->index - 1), 1);
data = (char const *)id3_field_getlatin1(field);
if (! data) {
if (!data)
{
fprintf(stderr, "No mime type data found for image frame\n");
return 0;
}
if (strncasecmp (data, "image/", 6)) {
if (! strcmp (data, "-->")) {
if (strncasecmp(data, "image/", 6))
{
if (!strcmp(data, "-->"))
{
*loader = NULL;
return 1;
}
fprintf(stderr,
"Picture frame with unknown mime-type \'%s\' found\n",
data);
"Picture frame with unknown mime-type \'%s\' found\n", data);
return 0;
}
strncpy(ext + 1, data + 6, EXT_LEN);
if (! (*loader = __imlib_FindBestLoaderForFile (ext, 0))) {
if (!(*loader = __imlib_FindBestLoaderForFile(ext, 0)))
{
fprintf(stderr, "No loader found for extension %s\n", ext);
return 0;
}
@ -373,35 +423,34 @@ static char* id3_text_encodings [] = {
#define NUM_OF_ID3_TEXT_ENCODINGS \
(sizeof(id3_text_encodings) / sizeof(id3_text_encodings[0]))
static void write_tags (ImlibImage* im, lopt* opt)
static void
write_tags(ImlibImage * im, lopt * opt)
{
struct id3_frame* frame
= id3_tag_get_frame (opt->ctx->tag, opt->index - 1);
struct id3_frame *frame = id3_tag_get_frame(opt->ctx->tag, opt->index - 1);
union id3_field *field;
int num_data;
char *data;
if ((field = id3_frame_field(frame, 1)) &&
(data = (char *)id3_field_getlatin1(field)))
__imlib_AttachTag (im, "mime-type", 0,
strdup (data), destructor_data);
__imlib_AttachTag(im, "mime-type", 0, strdup(data), destructor_data);
if ((field = id3_frame_field(frame, 3)) &&
(data = (char*) id3_field_getstring (field))) {
(data = (char *)id3_field_getstring(field)))
{
size_t length;
char *dup;
id3_ucs4_t *ptr = (id3_ucs4_t *) data;
while (*ptr)
ptr++;
length = (ptr - (id3_ucs4_t *) data + 1) * sizeof(id3_ucs4_t);
dup = (char *)malloc(length);
memcpy(dup, data, length);
__imlib_AttachTag (im, "id3-description", 0,
dup, destructor_data);
__imlib_AttachTag(im, "id3-description", 0, dup, destructor_data);
}
if (field = id3_frame_field(frame, 0))
__imlib_AttachTag(im, "id3-description-text-encoding",
(num_data = (int)
id3_field_gettextencoding (field)),
(num_data = (int)id3_field_gettextencoding(field)),
num_data < NUM_OF_ID3_TEXT_ENCODINGS ?
id3_text_encodings[num_data] : NULL, NULL);
if (field = id3_frame_field(frame, 2))
@ -411,19 +460,22 @@ static void write_tags (ImlibImage* im, lopt* opt)
id3_pic_types[num_data] : NULL, NULL);
__imlib_AttachTag(im, "count", id3_tag_get_numframes(opt->ctx->tag),
NULL, NULL);
if (opt->cache_level) {
if (opt->cache_level)
{
context_addref(opt->ctx);
__imlib_AttachTag(im, "context", opt->ctx->id,
opt->ctx, destructor_context);
}
__imlib_AttachTag(im, "index", opt->index, NULL, NULL);
if (opt->traverse) {
if (opt->traverse)
{
char *buf = NULL;
if ((opt->index + opt->traverse)
<= id3_tag_get_numframes(opt->ctx->tag)
&& (opt->index + opt->traverse) > 0) {
buf = (char*) malloc
((strlen (im->real_file) + 50) * sizeof (char));
&& (opt->index + opt->traverse) > 0)
{
buf = (char *)malloc((strlen(im->real_file) + 50) * sizeof(char));
sprintf(buf, "%s:index=%d,traverse=%d", im->real_file,
opt->index + opt->traverse, opt->traverse);
}
@ -431,7 +483,8 @@ static void write_tags (ImlibImage* im, lopt* opt)
}
}
char load (ImlibImage *im, ImlibProgressFunction progress,
char
load(ImlibImage * im, ImlibProgressFunction progress,
char progress_granularity, char immediate_load)
{
ImlibLoader *loader;
@ -448,32 +501,35 @@ char load (ImlibImage *im, ImlibProgressFunction progress,
if (!get_loader(&opt, &loader))
goto fail_context;
if (loader) {
if (loader)
{
char *ofile, tmp[] = "/tmp/imlib2_loader_id3-XXXXXX";
int dest;
if ((dest = mkstemp (tmp)) < 0) {
if ((dest = mkstemp(tmp)) < 0)
{
fprintf(stderr, "Unable to create a temporary file\n");
goto fail_context;
}
res = extract_pic (id3_tag_get_frame (opt.ctx->tag,
opt.index - 1), dest);
res = extract_pic(id3_tag_get_frame(opt.ctx->tag, opt.index - 1), dest);
close(dest);
if (! res) {
if (!res)
{
unlink(tmp);
goto fail_context;
}
ofile = im->real_file;
im->real_file = strdup(tmp);
res = loader->load (im, progress,
progress_granularity, immediate_load);
res = loader->load(im, progress, progress_granularity, immediate_load);
free(im->real_file);
im->real_file = ofile;
unlink(tmp);
} else {
}
else
{
/* The tag actually provides a image url rather than image data.
* Practically, dunno if such a tag exists on earth :)
* Here's the code anyway...
@ -486,7 +542,8 @@ char load (ImlibImage *im, ImlibProgressFunction progress,
field = id3_frame_field
(id3_tag_get_frame(opt.ctx->tag, opt.index - 1), 4);
data = (char const *)id3_field_getbinarydata(field, &length);
if (! data || ! length) {
if (!data || !length)
{
fprintf(stderr, "No link image URL present\n");
goto fail_context;
}
@ -494,18 +551,17 @@ char load (ImlibImage *im, ImlibProgressFunction progress,
strncpy(url, data, length);
url[length] = '\0';
file = (strncmp(url, "file://", 7) ? url : url + 7);
if (! (loader = __imlib_FindBestLoaderForFile (file, 0))) {
if (!(loader = __imlib_FindBestLoaderForFile(file, 0)))
{
fprintf(stderr, "No loader found for file %s\n", file);
free(url);
goto fail_context;
}
ofile = im->real_file;
im->real_file = file;
res = loader->load (im, progress,
progress_granularity, immediate_load);
res = loader->load(im, progress, progress_granularity, immediate_load);
if (!im->loader)
__imlib_AttachTag (im, "id3-link-url", 0,
url, destructor_data);
__imlib_AttachTag(im, "id3-link-url", 0, url, destructor_data);
else
free(url);
im->real_file = ofile;
@ -515,10 +571,13 @@ char load (ImlibImage *im, ImlibProgressFunction progress,
write_tags(im, &opt);
#ifdef DEBUG
if (! im->loader) {
if (!im->loader)
{
ImlibImageTag *cur = im->tags;
fprintf(stderr, "Tags for file %s:\n", im->file);
while (cur) {
while (cur)
{
fprintf(stderr, "\t%s: (%d) %s\n", cur->key,
cur->val, (char *)cur->data);
cur = cur->next;
@ -534,7 +593,8 @@ fail_context:
return 0;
}
void formats (ImlibLoader *l)
void
formats(ImlibLoader * l)
{
/* this is the only bit you have to change... */
char *list_formats[] = { "mp3" };

View File

@ -138,10 +138,8 @@ load(ImlibImage * im, ImlibProgressFunction progress,
{
for (x = 0; x < w; x++)
{
*ptr2 =
(0xff000000) | ((ptr[0]) << 16) | ((ptr[1]) <<
8) |
(ptr[2]);
*ptr2 = (0xff000000) | ((ptr[0]) << 16) |
((ptr[1]) << 8) | (ptr[2]);
ptr += cinfo.output_components;
ptr2++;
}
@ -184,10 +182,8 @@ load(ImlibImage * im, ImlibProgressFunction progress,
{
for (x = 0; x < w; x++)
{
*ptr2 =
(0xff000000) | ((ptr[0]) << 16) | ((ptr[0]) <<
8) |
(ptr[0]);
*ptr2 = (0xff000000) | ((ptr[0]) << 16) |
((ptr[0]) << 8) | (ptr[0]);
ptr++;
ptr2++;
}

View File

@ -41,29 +41,35 @@ typedef struct ILBM {
int rle;
} ILBM;
/*------------------------------------------------------------------------------
* Frees memory allocated as part of an ILBM structure.
*------------------------------------------------------------------------------*/
static void freeilbm(ILBM *ilbm)
static void
freeilbm(ILBM * ilbm)
{
if (ilbm->bmhd.data) free(ilbm->bmhd.data);
if (ilbm->camg.data) free(ilbm->camg.data);
if (ilbm->cmap.data) free(ilbm->cmap.data);
if (ilbm->ctbl.data) free(ilbm->ctbl.data);
if (ilbm->sham.data) free(ilbm->sham.data);
if (ilbm->body.data) free(ilbm->body.data);
if (ilbm->bmhd.data)
free(ilbm->bmhd.data);
if (ilbm->camg.data)
free(ilbm->camg.data);
if (ilbm->cmap.data)
free(ilbm->cmap.data);
if (ilbm->ctbl.data)
free(ilbm->ctbl.data);
if (ilbm->sham.data)
free(ilbm->sham.data);
if (ilbm->body.data)
free(ilbm->body.data);
memset(ilbm, 0, sizeof(*ilbm));
}
/*------------------------------------------------------------------------------
* Reads the given chunks out of a file, returns 0 if the file had a problem.
*
* Format FORMsizeILBMtag.size....tag.size....tag.size....
*------------------------------------------------------------------------------*/
static int loadchunks(char *name, ILBM *ilbm, int full)
static int
loadchunks(char *name, ILBM * ilbm, int full)
{
CHUNK *c;
FILE *f;
@ -75,57 +81,78 @@ char buf[12];
ok = 0;
f = fopen(name, "rb");
if (f) {
if (f)
{
s = fread(buf, 1, 12, f);
if (s == 12 && !memcmp(buf, "FORM", 4) && !memcmp(buf + 8, "ILBM", 4)) {
if (s == 12 && !memcmp(buf, "FORM", 4) && !memcmp(buf + 8, "ILBM", 4))
{
memset(ilbm, 0, sizeof(*ilbm));
formsize = L2RLONG(buf + 4);
while (1) {
while (1)
{
pos = ftell(f);
if (pos < 0 || pos >= formsize + 8) break; /* Error or FORM data is finished. */
if (pos < 0 || pos >= formsize + 8)
break; /* Error or FORM data is finished. */
seek = 1;
s = fread(buf, 1, 8, f);
if (s != 8) break; /* Error or short file. */
if (s != 8)
break; /* Error or short file. */
z = L2RLONG(buf + 4);
if (z < 0) break; /* Corrupt file. */
if (z < 0)
break; /* Corrupt file. */
c = NULL;
if (!memcmp(buf, "BMHD", 4)) c = &(ilbm->bmhd);
else if (full) {
if (!memcmp(buf, "CAMG", 4)) c = &(ilbm->camg);
else if (!memcmp(buf, "CMAP", 4)) c = &(ilbm->cmap);
else if (!memcmp(buf, "CTBL", 4)) c = &(ilbm->ctbl);
else if (!memcmp(buf, "SHAM", 4)) c = &(ilbm->sham);
else if (!memcmp(buf, "BODY", 4)) c = &(ilbm->body);
if (!memcmp(buf, "BMHD", 4))
c = &(ilbm->bmhd);
else if (full)
{
if (!memcmp(buf, "CAMG", 4))
c = &(ilbm->camg);
else if (!memcmp(buf, "CMAP", 4))
c = &(ilbm->cmap);
else if (!memcmp(buf, "CTBL", 4))
c = &(ilbm->ctbl);
else if (!memcmp(buf, "SHAM", 4))
c = &(ilbm->sham);
else if (!memcmp(buf, "BODY", 4))
c = &(ilbm->body);
}
if (c && !c->data) {
if (c && !c->data)
{
c->size = z;
c->data = malloc(c->size);
if (!c->data) break; /* Out of memory. */
if (!c->data)
break; /* Out of memory. */
s = fread(c->data, 1, c->size, f);
if (s != c->size) break; /* Error or short file. */
if (s != c->size)
break; /* Error or short file. */
seek = 0;
if (!full) { /* Only BMHD required. */
if (!full)
{ /* Only BMHD required. */
ok = 1;
break;
}
}
if (pos + 8 + z >= formsize + 8) break; /* This was last chunk. */
if (pos + 8 + z >= formsize + 8)
break; /* This was last chunk. */
if (seek && fseek(f, z, SEEK_CUR) != 0) break;
if (seek && fseek(f, z, SEEK_CUR) != 0)
break;
}
/* File may end strangely, especially if body size is uneven, but it's
* ok if we have the chunks we want. !full check is already done. */
if (ilbm->bmhd.data && ilbm->body.data) ok = 1;
if (!ok) freeilbm(ilbm);
if (ilbm->bmhd.data && ilbm->body.data)
ok = 1;
if (!ok)
freeilbm(ilbm);
}
fclose(f);
}
@ -133,7 +160,6 @@ char buf[12];
return ok;
}
/*------------------------------------------------------------------------------
* Unpacks a row of possibly RLE data at a time.
*
@ -145,41 +171,53 @@ char buf[12];
*
* In theory RLE compression is not supposed to create runs across scanlines.
*------------------------------------------------------------------------------*/
static void bodyrow(unsigned char *p, int z, ILBM *ilbm)
static void
bodyrow(unsigned char *p, int z, ILBM * ilbm)
{
int i, x, w;
unsigned char b;
if (ilbm->offset >= ilbm->body.size) {
if (ilbm->offset >= ilbm->body.size)
{
memset(p, 0, z);
return;
}
if (!ilbm->rle) {
if (!ilbm->rle)
{
w = ilbm->body.size - ilbm->offset;
if (w > z) w = z;
if (w > z)
w = z;
memcpy(p, ilbm->body.data + ilbm->offset, w);
if (w < z) memset(p + w, 0, z - w);
if (w < z)
memset(p + w, 0, z - w);
ilbm->offset += w;
return;
}
for (i = 0; i < z; ) {
for (i = 0; i < z;)
{
b = ilbm->body.data[ilbm->offset++];
while (b == 0x80 && ilbm->offset < ilbm->body.size) b = ilbm->body.data[ilbm->offset++];
if (ilbm->offset >= ilbm->body.size) break;
while (b == 0x80 && ilbm->offset < ilbm->body.size)
b = ilbm->body.data[ilbm->offset++];
if (ilbm->offset >= ilbm->body.size)
break;
if (b & 0x80) {
if (b & 0x80)
{
w = (0x100 - b) + 1;
if (w > z - i) w = z - i;
if (w > z - i)
w = z - i;
b = ilbm->body.data[ilbm->offset++];
memset(p + i, b, w);
i += w;
}
else {
else
{
w = (b & 0x7f) + 1;
if (w > ilbm->body.size - ilbm->offset) w = ilbm->body.size - ilbm->offset;
if (w > ilbm->body.size - ilbm->offset)
w = ilbm->body.size - ilbm->offset;
x = (w <= z - i) ? w : z - i;
memcpy(p + i, ilbm->body.data + ilbm->offset, x);
i += x;
@ -187,20 +225,22 @@ unsigned char b;
}
}
if (i < z) memset(p, 0, z - i);
if (i < z)
memset(p, 0, z - i);
}
/*------------------------------------------------------------------------------
* Shifts a value to produce an 8-bit colour gun, and fills in the lower bits
* from the high bits of the value so that, for example, 4-bit 0x0f scales to
* 0xff, or 1-bit 0x01 scales to 0xff.
*------------------------------------------------------------------------------*/
static unsigned char scalegun(unsigned char v, int sl)
static unsigned char
scalegun(unsigned char v, int sl)
{
int sr;
switch (sl) {
switch (sl)
{
case 1:
case 2:
case 3:
@ -222,31 +262,33 @@ int sr;
return v;
}
/*------------------------------------------------------------------------------
* Scales the colours in a CMAP chunk if they all look like 4-bit colour, so
* that they use all 8-bits. This is done by copying the high nybble into the
* low nybble, so for example 0xf0 becomes 0xff.
*------------------------------------------------------------------------------*/
static void scalecmap(ILBM *ilbm)
static void
scalecmap(ILBM * ilbm)
{
int i;
if (!ilbm->cmap.data) return;
if (!ilbm->cmap.data)
return;
for (i = 0; i < ilbm->cmap.size; i++)
if (ilbm->cmap.data[i] & 0x0f) return;
if (ilbm->cmap.data[i] & 0x0f)
return;
for (i = 0; i < ilbm->cmap.size; i++)
ilbm->cmap.data[i] |= ilbm->cmap.data[i] >> 4;
}
/*------------------------------------------------------------------------------
* Deplanes and converts an array of bitplanes to a single scanline of DATA32
* (unsigned int) values. DATA32 is ARGB.
*------------------------------------------------------------------------------*/
static void deplane(DATA32 *row, int w, ILBM *ilbm, unsigned char *plane[])
static void
deplane(DATA32 * row, int w, ILBM * ilbm, unsigned char *plane[])
{
unsigned long l;
int i, o, x;
@ -258,114 +300,147 @@ unsigned char bit, r, g, b, a, v, h, *pal;
if (ilbm->ctbl.data && ilbm->ctbl.size >= (ilbm->row + 1) * 2 * 16)
pal = ilbm->ctbl.data + ilbm->row * 2 * 16;
if (ilbm->ham) r = g = b = 0;
if (ilbm->ham)
r = g = b = 0;
bit = 0x80;
o = 0;
for (x = 0; x < w; x++) {
for (x = 0; x < w; x++)
{
l = 0;
for (i = ilbm->depth - 1; i >= 0; i--) {
for (i = ilbm->depth - 1; i >= 0; i--)
{
l = l << 1;
if (plane[i][o] & bit) l = l | 1;
if (plane[i][o] & bit)
l = l | 1;
}
a = (ilbm->mask == 0 || (ilbm->mask == 1 && (plane[ilbm->depth][o] & bit)) || ilbm->mask == 2)? 0xff: 0x00;
a = (ilbm->mask == 0
|| (ilbm->mask == 1 && (plane[ilbm->depth][o] & bit))
|| ilbm->mask == 2) ? 0xff : 0x00;
if (ilbm->depth == 32) {
if (ilbm->depth == 32)
{
a = (l >> 24) & 0xff;
b = (l >> 16) & 0xff;
g = (l >> 8) & 0xff;
r = l & 0xff;
}
else if (ilbm->depth == 24) {
else if (ilbm->depth == 24)
{
b = (l >> 16) & 0xff;
g = (l >> 8) & 0xff;
r = l & 0xff;
}
else if (ilbm->ham) {
else if (ilbm->ham)
{
v = l & ((1 << (ilbm->depth - 2)) - 1);
h = (l & ~v) >> (ilbm->depth - 2);
if (h == 0x00) {
if (!pal) {
if ((v + 1) * 3 <= ilbm->cmap.size) {
if (h == 0x00)
{
if (!pal)
{
if ((v + 1) * 3 <= ilbm->cmap.size)
{
r = ilbm->cmap.data[v * 3];
g = ilbm->cmap.data[v * 3 + 1];
b = ilbm->cmap.data[v * 3 + 2];
}
else r = g = b = 0;
else
r = g = b = 0;
}
else {
else
{
r = scalegun(pal[v * 2] & 0x0f, 4);
g = scalegun((pal[v * 2 + 1] & 0xf0) >> 4, 4);
b = scalegun((pal[v * 2 + 1] & 0x0f), 4);
}
}
else if (h == 0x01) b = scalegun(v, 8 - (ilbm->depth - 2));
else if (h == 0x02) r = scalegun(v, 8 - (ilbm->depth - 2));
else g = scalegun(v, 8 - (ilbm->depth - 2));
else if (h == 0x01)
b = scalegun(v, 8 - (ilbm->depth - 2));
else if (h == 0x02)
r = scalegun(v, 8 - (ilbm->depth - 2));
else
g = scalegun(v, 8 - (ilbm->depth - 2));
}
else if (ilbm->hbrite) {
else if (ilbm->hbrite)
{
v = l & ((1 << (ilbm->depth - 1)) - 1);
h = (l & ~v) >> (ilbm->depth - 1);
if (!pal) {
if ((v + 1) * 3 <= ilbm->cmap.size) {
if (!pal)
{
if ((v + 1) * 3 <= ilbm->cmap.size)
{
r = ilbm->cmap.data[v * 3];
g = ilbm->cmap.data[v * 3 + 1];
b = ilbm->cmap.data[v * 3 + 2];
}
else r = g = b = 0;
else
r = g = b = 0;
}
else {
else
{
r = scalegun(pal[v * 2] & 0x0f, 4);
g = scalegun((pal[v * 2 + 1] & 0xf0) >> 4, 4);
b = scalegun((pal[v * 2 + 1] & 0x0f), 4);
}
if (h) {
if (h)
{
r = r >> 1;
g = g >> 1;
b = b >> 1;
}
if (ilbm->mask == 2 && v == L2RWORD(ilbm->bmhd.data + 12)) a = 0x00;
if (ilbm->mask == 2 && v == L2RWORD(ilbm->bmhd.data + 12))
a = 0x00;
}
else if (ilbm->cmap.size == 0 && !pal) {
else if (ilbm->cmap.size == 0 && !pal)
{
v = l & ((1 << ilbm->depth) - 1);
r = scalegun(v, ilbm->depth);
g = r;
b = r;
}
else {
else
{
v = l & 0xff;
if (!pal) {
if ((v + 1) * 3 <= ilbm->cmap.size) {
if (!pal)
{
if ((v + 1) * 3 <= ilbm->cmap.size)
{
r = ilbm->cmap.data[v * 3];
g = ilbm->cmap.data[v * 3 + 1];
b = ilbm->cmap.data[v * 3 + 2];
}
else r = g = b = 0;
else
r = g = b = 0;
}
else {
else
{
r = scalegun(pal[v * 2] & 0x0f, 4);
g = scalegun((pal[v * 2 + 1] & 0xf0) >> 4, 4);
b = scalegun((pal[v * 2 + 1] & 0x0f), 4);
}
if (ilbm->mask == 2 && v == L2RWORD(ilbm->bmhd.data + 12)) a = 0x00;
if (ilbm->mask == 2 && v == L2RWORD(ilbm->bmhd.data + 12))
a = 0x00;
}
row[x] = ((unsigned long)a << 24) | ((unsigned long)r << 16) | ((unsigned long)g << 8) | (unsigned long)b;
row[x] =
((unsigned long)a << 24) | ((unsigned long)r << 16) |
((unsigned long)g << 8) | (unsigned long)b;
bit = bit >> 1;
if (bit == 0) {
if (bit == 0)
{
o++;
bit = 0x80;
}
}
}
/*------------------------------------------------------------------------------
* Loads an image. If im->loader is non-zero, or immediate_load is non-zero, or
* progress is non-zero, then the file is fully loaded, otherwise only the width
@ -373,7 +448,9 @@ unsigned char bit, r, g, b, a, v, h, *pal;
*
* Imlib2 doesn't support reading comment chunks like ANNO.
*------------------------------------------------------------------------------*/
char load(ImlibImage *im, ImlibProgressFunction progress, char progress_granularity, char immediate_load)
char
load(ImlibImage * im, ImlibProgressFunction progress, char progress_granularity,
char immediate_load)
{
char *env;
int cancel, full, i, n, ok, y, z, gran, nexty, prevy;
@ -383,7 +460,8 @@ ILBM ilbm;
/*----------
* Do nothing if the data is already loaded.
*----------*/
if (im->data) return 0;
if (im->data)
return 0;
/*----------
* Load the chunk(s) we're interested in. If full is not true, then we only
@ -391,13 +469,15 @@ ILBM ilbm;
*----------*/
full = (im->loader || immediate_load || progress);
ok = loadchunks(im->real_file, &ilbm, full);
if (!ok) return 0;
if (!ok)
return 0;
/*----------
* Use and check header.
*----------*/
ok = 0;
if (ilbm.bmhd.size >= 20) {
if (ilbm.bmhd.size >= 20)
{
ok = 1;
im->w = L2RWORD(ilbm.bmhd.data);
@ -408,35 +488,53 @@ ILBM ilbm;
}
ilbm.depth = ilbm.bmhd.data[8];
if (ilbm.depth < 1 || (ilbm.depth > 8 && ilbm.depth != 24 && ilbm.depth != 32)) ok = 0; /* Only 1 to 8, 24, or 32 planes. */
if (ilbm.depth < 1
|| (ilbm.depth > 8 && ilbm.depth != 24 && ilbm.depth != 32))
ok = 0; /* Only 1 to 8, 24, or 32 planes. */
ilbm.rle = ilbm.bmhd.data[10];
if (ilbm.rle < 0 || ilbm.rle > 1) ok = 0; /* Only NONE or RLE compression. */
if (ilbm.rle < 0 || ilbm.rle > 1)
ok = 0; /* Only NONE or RLE compression. */
ilbm.mask = ilbm.bmhd.data[9];
if (ilbm.mask || ilbm.depth == 32) SET_FLAG(im->flags, F_HAS_ALPHA);
else UNSET_FLAG(im->flags, F_HAS_ALPHA);
if (ilbm.mask || ilbm.depth == 32)
SET_FLAG(im->flags, F_HAS_ALPHA);
else
UNSET_FLAG(im->flags, F_HAS_ALPHA);
env = getenv("IMLIB2_LBM_NOMASK");
if (env && (!strcmp(env, "true") || !strcmp(env, "1") || !strcmp(env, "yes") || !strcmp(env, "on"))) UNSET_FLAG(im->flags, F_HAS_ALPHA);
if (env
&& (!strcmp(env, "true") || !strcmp(env, "1") || !strcmp(env, "yes")
|| !strcmp(env, "on")))
UNSET_FLAG(im->flags, F_HAS_ALPHA);
if (!im->format) im->format = strdup("lbm");
if (!im->format)
im->format = strdup("lbm");
ilbm.ham = 0;
ilbm.hbrite = 0;
if (ilbm.depth <= 8) {
if (ilbm.camg.size == 4) {
if (ilbm.camg.data[2] & 0x08) ilbm.ham = 1;
if (ilbm.camg.data[3] & 0x80) ilbm.hbrite = 1;
if (ilbm.depth <= 8)
{
if (ilbm.camg.size == 4)
{
if (ilbm.camg.data[2] & 0x08)
ilbm.ham = 1;
if (ilbm.camg.data[3] & 0x80)
ilbm.hbrite = 1;
}
else { /* Only guess at ham and hbrite if CMAP is present. */
if (ilbm.depth == 6 && full && ilbm.cmap.size >= 3 * 16) ilbm.ham = 1;
if (full && !ilbm.ham && ilbm.depth > 1 && ilbm.cmap.size == 3 * (1 << (ilbm.depth - 1))) ilbm.hbrite = 1;
else
{ /* Only guess at ham and hbrite if CMAP is present. */
if (ilbm.depth == 6 && full && ilbm.cmap.size >= 3 * 16)
ilbm.ham = 1;
if (full && !ilbm.ham && ilbm.depth > 1
&& ilbm.cmap.size == 3 * (1 << (ilbm.depth - 1)))
ilbm.hbrite = 1;
}
}
}
if (!full || !ok) {
if (!full || !ok)
{
im->w = im->h = 0;
freeilbm(&ilbm);
return ok;
@ -454,30 +552,40 @@ ILBM ilbm;
im->data = malloc(im->w * im->h * sizeof(DATA32));
n = ilbm.depth;
if (ilbm.mask == 1) n++;
if (ilbm.mask == 1)
n++;
plane[0] = malloc(((im->w + 15) / 16) * 2 * n);
if (im->data && plane[0]) {
for (i = 1; i < n; i++) plane[i] = plane[i - 1] + ((im->w + 15) / 16) * 2;
if (im->data && plane[0])
{
for (i = 1; i < n; i++)
plane[i] = plane[i - 1] + ((im->w + 15) / 16) * 2;
z = ((im->w + 15) / 16) * 2 * n;
if (progress) {
if (progress)
{
prevy = 0;
if (progress_granularity <= 0) progress_granularity = 1;
if (progress_granularity <= 0)
progress_granularity = 1;
gran = progress_granularity;
nexty = ((im->h * gran) / 100);
}
scalecmap(&ilbm);
for (y = 0; y < im->h; y++) {
for (y = 0; y < im->h; y++)
{
bodyrow(plane[0], z, &ilbm);
deplane(im->data + im->w * y, im->w, &ilbm, plane);
ilbm.row++;
if (progress && (y >= nexty || y == im->h - 1)) {
if (!progress(im, (char)((100 * (y + 1)) / im->h), 0, prevy, im->w, y + 1)) {
if (progress && (y >= nexty || y == im->h - 1))
{
if (!progress
(im, (char)((100 * (y + 1)) / im->h), 0, prevy, im->w,
y + 1))
{
cancel = 1;
break;
}
@ -494,42 +602,46 @@ ILBM ilbm;
* We either had a successful decode, the user cancelled, or we couldn't get
* the memory for im->data or plane[0].
*----------*/
if (!ok) {
if (!ok)
{
im->w = im->h = 0;
if (im->data) free(im->data);
if (im->data)
free(im->data);
im->data = NULL;
}
if (plane[0]) free(plane[0]);
if (plane[0])
free(plane[0]);
freeilbm(&ilbm);
return (cancel) ? 2 : ok;
}
/*------------------------------------------------------------------------------
* Perhaps save only in 32-bit format? The IFF ILBM format has pretty much gone
* the way of the Amiga, who saves in this format any more?
*------------------------------------------------------------------------------*/
#if 0
char save(ImlibImage *im, ImlibProgressFunction progress, char progress_granularity)
char
save(ImlibImage * im, ImlibProgressFunction progress, char progress_granularity)
{
return 0;
}
#endif
/*------------------------------------------------------------------------------
* Identifies the file extensions this loader handles. Standard code from other
* loaders.
*------------------------------------------------------------------------------*/
void formats(ImlibLoader *l)
void
formats(ImlibLoader * l)
{
char *list_formats[] = { "iff", "ilbm", "lbm" };
int i;
l->num_formats = sizeof(list_formats) / sizeof(list_formats[0]);
l->formats = malloc(l->num_formats * sizeof(list_formats[0]));
for (i = 0; i < l->num_formats; i++) l->formats[i] = strdup(list_formats[i]);
for (i = 0; i < l->num_formats; i++)
l->formats[i] = strdup(list_formats[i]);
}

View File

@ -216,13 +216,15 @@ load(ImlibImage * im, ImlibProgressFunction progress,
while (x < w)
{
int k;
/* check 4 chars ahead to see if we need to
fill the buffer */
* fill the buffer */
for (k = 0; k < 4; k++)
{
if (!buf[i + k]) /* fill buffer */
{
if (fseek(f, -k, SEEK_CUR) == -1 || !fgets(buf, 255, f))
if (fseek(f, -k, SEEK_CUR) == -1 ||
!fgets(buf, 255, f))
{
free(idata);
fclose(f);
@ -261,9 +263,10 @@ load(ImlibImage * im, ImlibProgressFunction progress,
for (x = 0; x < w; x++)
{
*ptr2 =
0xff000000 | (((iptr[0] * 255) / v) << 16) |
(((iptr[0] * 255) / v) << 8) | ((iptr[0] *
255) / v);
0xff000000 |
(((iptr[0] * 255) / v) << 16) |
(((iptr[0] * 255) / v) << 8) |
((iptr[0] * 255) / v);
ptr2++;
iptr++;
}
@ -316,13 +319,15 @@ load(ImlibImage * im, ImlibProgressFunction progress,
while (x < w3)
{
int k;
/* check 4 chars ahead to see if we need to
fill the buffer */
* fill the buffer */
for (k = 0; k < 4; k++)
{
if (!buf[i + k]) /* fill buffer */
{
if (fseek(f, -k, SEEK_CUR) == -1 || !fgets(buf, 255, f))
if (fseek(f, -k, SEEK_CUR) == -1 ||
!fgets(buf, 255, f))
{
free(idata);
fclose(f);
@ -361,9 +366,10 @@ load(ImlibImage * im, ImlibProgressFunction progress,
for (x = 0; x < w; x++)
{
*ptr2 =
0xff000000 | (((iptr[0] * 255) / v) << 16) |
(((iptr[1] * 255) / v) << 8) | ((iptr[2] *
255) / v);
0xff000000 |
(((iptr[0] * 255) / v) << 16) |
(((iptr[1] * 255) / v) << 8) |
((iptr[2] * 255) / v);
ptr2++;
iptr += 3;
}
@ -453,9 +459,10 @@ load(ImlibImage * im, ImlibProgressFunction progress,
for (x = 0; x < w; x++)
{
*ptr2 =
0xff000000 | (((ptr[0] * 255) / v) << 16) |
(((ptr[0] * 255) / v) << 8) | ((ptr[0] *
255) / v);
0xff000000 |
(((ptr[0] * 255) / v) << 16) |
(((ptr[0] * 255) / v) << 8) |
((ptr[0] * 255) / v);
ptr2++;
ptr++;
}
@ -520,9 +527,10 @@ load(ImlibImage * im, ImlibProgressFunction progress,
for (x = 0; x < w; x++)
{
*ptr2 =
0xff000000 | (((ptr[0] * 255) / v) << 16) |
(((ptr[1] * 255) / v) << 8) | ((ptr[2] *
255) / v);
0xff000000 |
(((ptr[0] * 255) / v) << 16) |
(((ptr[1] * 255) / v) << 8) |
((ptr[2] * 255) / v);
ptr2++;
ptr += 3;
}
@ -579,9 +587,9 @@ load(ImlibImage * im, ImlibProgressFunction progress,
g = (*ptr >> 2) & 0x7;
b = (*ptr) & 0x3;
*ptr2 =
0xff000000 | (((r << 21) | (r << 18) | (r << 15)) &
0xff0000) | (((g << 13) | (g << 10) |
(g << 7)) & 0xff00) |
0xff000000 |
(((r << 21) | (r << 18) | (r << 15)) & 0xff0000) |
(((g << 13) | (g << 10) | (g << 7)) & 0xff00) |
((b << 6) | (b << 4) | (b << 2) | (b << 0));
ptr2++;
ptr++;
@ -633,9 +641,8 @@ load(ImlibImage * im, ImlibProgressFunction progress,
for (x = 0; x < w; x++)
{
*ptr2 =
(ptr[3] << 24) | (ptr[0] << 16) | (ptr[1] <<
8) |
ptr[2];
(ptr[3] << 24) | (ptr[0] << 16) |
(ptr[1] << 8) | ptr[2];
ptr2++;
ptr += 4;
}
@ -645,10 +652,9 @@ load(ImlibImage * im, ImlibProgressFunction progress,
for (x = 0; x < w; x++)
{
*ptr2 =
(((ptr[3] * 255) /
v) << 24) | (((ptr[0] * 255) /
v) << 16) | (((ptr[1] * 255) /
v) << 8) |
(((ptr[3] * 255) / v) << 24) |
(((ptr[0] * 255) / v) << 16) |
(((ptr[1] * 255) / v) << 8) |
((ptr[2] * 255) / v);
ptr2++;
ptr += 4;

View File

@ -348,17 +348,14 @@ load(ImlibImage * im, ImlibProgressFunction progress,
else
dataptr = im->data + (y * im->w);
for (x = 0;
(x < im->w) && (bufptr + bpp / 8 <= bufend);
x++) /* for each pixel in the row */
for (x = 0; (x < im->w) && (bufptr + bpp / 8 <= bufend); x++) /* for each pixel in the row */
{
switch (bpp)
{
/* 32-bit BGRA pixels */
case 32:
WRITE_RGBA(dataptr,
*(bufptr + 2), /* R */
WRITE_RGBA(dataptr, *(bufptr + 2), /* R */
*(bufptr + 1), /* G */
*(bufptr + 0), /* B */
*(bufptr + 3) /* A */
@ -369,8 +366,7 @@ load(ImlibImage * im, ImlibProgressFunction progress,
/* 24-bit BGR pixels */
case 24:
WRITE_RGBA(dataptr,
*(bufptr + 2), /* R */
WRITE_RGBA(dataptr, *(bufptr + 2), /* R */
*(bufptr + 1), /* G */
*(bufptr + 0), /* B */
(char)0xff /* A */
@ -382,9 +378,7 @@ load(ImlibImage * im, ImlibProgressFunction progress,
/* 8-bit grayscale */
case 8:
WRITE_RGBA(dataptr, /* grayscale */
*bufptr,
*bufptr,
*bufptr, (char)0xff);
*bufptr, *bufptr, *bufptr, (char)0xff);
dataptr++;
bufptr += 1;
break;
@ -424,7 +418,8 @@ load(ImlibImage * im, ImlibProgressFunction progress,
green = *bufptr++;
red = *bufptr++;
alpha = *bufptr++;
for (i = 0; (i < count) && (dataptr < final_pixel); i++)
for (i = 0; (i < count) && (dataptr < final_pixel);
i++)
{
WRITE_RGBA(dataptr, red, green, blue, alpha);
dataptr++;
@ -435,7 +430,8 @@ load(ImlibImage * im, ImlibProgressFunction progress,
blue = *bufptr++;
green = *bufptr++;
red = *bufptr++;
for (i = 0; (i < count) && (dataptr < final_pixel); i++)
for (i = 0; (i < count) && (dataptr < final_pixel);
i++)
{
WRITE_RGBA(dataptr, red, green, blue,
(char)0xff);
@ -445,7 +441,8 @@ load(ImlibImage * im, ImlibProgressFunction progress,
case 8:
alpha = *bufptr++;
for (i = 0; (i < count) && (dataptr < final_pixel); i++)
for (i = 0; (i < count) && (dataptr < final_pixel);
i++)
{
WRITE_RGBA(dataptr, alpha, alpha, alpha,
(char)0xff);
@ -499,7 +496,8 @@ load(ImlibImage * im, ImlibProgressFunction progress,
} /* end if (raw packet) */
} /* end for (each packet) */
/* must now flip a bottom-up image */
if (vinverted) tgaflip(im->data, im->w, im->h);
if (vinverted)
tgaflip(im->data, im->w, im->h);
if (progress)
{
progress(im, 100, 0, 0, im->w, im->h);
@ -545,6 +543,7 @@ tgaflip (DATA32 * in, int w, int h)
for (y = 0; y < (h / 2); y++)
{
DATA32 tmp;
for (x = 0; x < w; x++)
{
tmp = adv[x];

View File

@ -7,7 +7,8 @@
#define OUTBUF_SIZE 16484
static int uncompress_file (int src, int dest)
static int
uncompress_file(int src, int dest)
{
gzFile gf;
DATA8 outbuf[OUTBUF_SIZE];
@ -17,15 +18,18 @@ static int uncompress_file (int src, int dest)
if (!gf)
return 0;
while (1) {
while (1)
{
bytes = gzread(gf, outbuf, OUTBUF_SIZE);
if (!bytes)
break;
else if (bytes == -1) {
else if (bytes == -1)
{
ret = 0;
break;
} else
}
else
write(dest, outbuf, bytes);
}
@ -34,7 +38,8 @@ static int uncompress_file (int src, int dest)
return ret;
}
char load (ImlibImage *im, ImlibProgressFunction progress,
char
load(ImlibImage * im, ImlibProgressFunction progress,
char progress_granularity, char immediate_load)
{
ImlibLoader *loader;
@ -49,10 +54,12 @@ char load (ImlibImage *im, ImlibProgressFunction progress,
* (e.g. "foo.png.gz"
*/
p = strrchr(im->real_file, '.');
if (p && p != im->real_file) {
if (p && p != im->real_file)
{
if (strcasecmp(p + 1, "gz"))
return 0;
} else
}
else
return 0;
strncpy(real_ext, p - sizeof(real_ext) + 1, sizeof(real_ext));
@ -65,11 +72,13 @@ char load (ImlibImage *im, ImlibProgressFunction progress,
if (stat(im->real_file, &st) < 0)
return 0;
if ((src = open (im->real_file, O_RDONLY)) < 0) {
if ((src = open(im->real_file, O_RDONLY)) < 0)
{
return 0;
}
if ((dest = mkstemp (tmp)) < 0) {
if ((dest = mkstemp(tmp)) < 0)
{
close(src);
return 0;
}
@ -78,12 +87,14 @@ char load (ImlibImage *im, ImlibProgressFunction progress,
close(src);
close(dest);
if (!res) {
if (!res)
{
unlink(tmp);
return 0;
}
if (!(loader = __imlib_FindBestLoaderForFile (real_ext, 0))) {
if (!(loader = __imlib_FindBestLoaderForFile(real_ext, 0)))
{
unlink(tmp);
return 0;
}
@ -102,7 +113,8 @@ char load (ImlibImage *im, ImlibProgressFunction progress,
return 1;
}
void formats (ImlibLoader *l)
void
formats(ImlibLoader * l)
{
/* this is the only bit you have to change... */
char *list_formats[] = { "gz" };