2008-11-05 09:21:04 -08:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include <config.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_EVIL
|
|
|
|
# include <Evil.h>
|
|
|
|
#endif
|
|
|
|
|
2008-03-01 07:27:20 -08:00
|
|
|
#include "evas_common.h"
|
|
|
|
#include "evas_private.h"
|
|
|
|
|
2011-04-15 00:08:14 -07:00
|
|
|
#define FILE_BUFFER_SIZE 1024 * 32
|
2008-03-01 07:27:20 -08:00
|
|
|
#define FILE_BUFFER_UNREAD_SIZE 16
|
|
|
|
|
2009-12-22 15:11:57 -08:00
|
|
|
static Eina_Bool evas_image_load_file_head_pmaps(Image_Entry *ie, const char *file, const char *key, int *error) EINA_ARG_NONNULL(1, 2, 4);
|
|
|
|
static Eina_Bool evas_image_load_file_data_pmaps(Image_Entry *ie, const char *file, const char *key, int *error) EINA_ARG_NONNULL(1, 2, 4);
|
2008-03-01 07:27:20 -08:00
|
|
|
|
|
|
|
Evas_Image_Load_Func evas_image_load_pmaps_func = {
|
2009-12-24 05:15:34 -08:00
|
|
|
EINA_TRUE,
|
2008-03-01 07:27:20 -08:00
|
|
|
evas_image_load_file_head_pmaps,
|
2011-08-10 23:04:08 -07:00
|
|
|
evas_image_load_file_data_pmaps,
|
2011-12-13 08:58:20 -08:00
|
|
|
NULL,
|
|
|
|
EINA_FALSE
|
2008-03-01 07:27:20 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
/* The buffer to load pmaps images */
|
|
|
|
typedef struct Pmaps_Buffer Pmaps_Buffer;
|
|
|
|
|
|
|
|
struct Pmaps_Buffer
|
|
|
|
{
|
2011-12-14 01:53:25 -08:00
|
|
|
Eina_File *file;
|
|
|
|
void *map;
|
|
|
|
size_t position;
|
2008-03-01 07:27:20 -08:00
|
|
|
|
|
|
|
/* the buffer */
|
|
|
|
DATA8 buffer[FILE_BUFFER_SIZE];
|
|
|
|
DATA8 unread[FILE_BUFFER_UNREAD_SIZE];
|
|
|
|
DATA8 *current;
|
|
|
|
DATA8 *end;
|
|
|
|
char type[3];
|
|
|
|
unsigned char unread_len:7;
|
|
|
|
unsigned char last_buffer:1;
|
|
|
|
|
|
|
|
/* image properties */
|
|
|
|
int w;
|
|
|
|
int h;
|
|
|
|
int max;
|
|
|
|
|
|
|
|
/* interface */
|
|
|
|
int (*int_get) (Pmaps_Buffer *b, int *val);
|
|
|
|
int (*color_get) (Pmaps_Buffer *b, DATA32 *color);
|
|
|
|
};
|
|
|
|
|
|
|
|
/* internal used functions */
|
2009-12-22 15:11:57 -08:00
|
|
|
static Eina_Bool pmaps_buffer_open(Pmaps_Buffer *b, const char *filename, int *error);
|
2008-03-01 07:27:20 -08:00
|
|
|
static void pmaps_buffer_close(Pmaps_Buffer *b);
|
2009-12-22 15:11:57 -08:00
|
|
|
static Eina_Bool pmaps_buffer_header_parse(Pmaps_Buffer *b, int *error);
|
2008-03-01 07:27:20 -08:00
|
|
|
static int pmaps_buffer_plain_int_get(Pmaps_Buffer *b, int *val);
|
|
|
|
static int pmaps_buffer_1byte_int_get(Pmaps_Buffer *b, int *val);
|
|
|
|
static int pmaps_buffer_2byte_int_get(Pmaps_Buffer *b, int *val);
|
|
|
|
static int pmaps_buffer_gray_get(Pmaps_Buffer *b, DATA32 *color);
|
|
|
|
static int pmaps_buffer_rgb_get(Pmaps_Buffer *b, DATA32 *color);
|
|
|
|
static int pmaps_buffer_plain_bw_get(Pmaps_Buffer *b, DATA32 *color);
|
|
|
|
|
|
|
|
static size_t pmaps_buffer_plain_update(Pmaps_Buffer *b);
|
|
|
|
static size_t pmaps_buffer_raw_update(Pmaps_Buffer *b);
|
|
|
|
static int pmaps_buffer_comment_skip(Pmaps_Buffer *b);
|
|
|
|
|
2009-12-22 15:11:57 -08:00
|
|
|
static Eina_Bool
|
|
|
|
evas_image_load_file_head_pmaps(Image_Entry *ie, const char *file, const char *key __UNUSED__, int *error)
|
2008-03-01 07:27:20 -08:00
|
|
|
{
|
|
|
|
Pmaps_Buffer b;
|
|
|
|
|
2009-12-22 15:11:57 -08:00
|
|
|
if (!pmaps_buffer_open(&b, file, error))
|
2008-03-01 07:27:20 -08:00
|
|
|
{
|
|
|
|
pmaps_buffer_close(&b);
|
2009-12-22 15:11:57 -08:00
|
|
|
return EINA_FALSE;
|
2008-03-01 07:27:20 -08:00
|
|
|
}
|
|
|
|
|
2009-12-22 15:11:57 -08:00
|
|
|
if (!pmaps_buffer_header_parse(&b, error))
|
2008-03-01 07:27:20 -08:00
|
|
|
{
|
|
|
|
pmaps_buffer_close(&b);
|
2009-12-22 15:11:57 -08:00
|
|
|
return EINA_FALSE;
|
2008-03-01 07:27:20 -08:00
|
|
|
}
|
|
|
|
|
2008-06-03 02:09:39 -07:00
|
|
|
ie->w = b.w;
|
|
|
|
ie->h = b.h;
|
2008-03-01 07:27:20 -08:00
|
|
|
|
|
|
|
pmaps_buffer_close(&b);
|
2009-12-22 15:11:57 -08:00
|
|
|
*error = EVAS_LOAD_ERROR_NONE;
|
|
|
|
return EINA_TRUE;
|
2008-03-01 07:27:20 -08:00
|
|
|
}
|
|
|
|
|
2009-12-22 15:11:57 -08:00
|
|
|
static Eina_Bool
|
|
|
|
evas_image_load_file_data_pmaps(Image_Entry *ie, const char *file, const char *key __UNUSED__, int *error)
|
2008-03-01 07:27:20 -08:00
|
|
|
{
|
|
|
|
Pmaps_Buffer b;
|
|
|
|
int pixels;
|
|
|
|
DATA32 *ptr;
|
|
|
|
|
2009-12-22 15:11:57 -08:00
|
|
|
if (!pmaps_buffer_open(&b, file, error))
|
2008-03-01 07:27:20 -08:00
|
|
|
{
|
|
|
|
pmaps_buffer_close(&b);
|
2009-12-22 15:11:57 -08:00
|
|
|
return EINA_FALSE;
|
2008-03-01 07:27:20 -08:00
|
|
|
}
|
|
|
|
|
2009-12-22 15:11:57 -08:00
|
|
|
if (!pmaps_buffer_header_parse(&b, error))
|
2008-03-01 07:27:20 -08:00
|
|
|
{
|
|
|
|
pmaps_buffer_close(&b);
|
2009-12-22 15:11:57 -08:00
|
|
|
return EINA_FALSE;
|
2008-03-01 07:27:20 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
pixels = b.w * b.h;
|
|
|
|
|
2008-06-03 02:09:39 -07:00
|
|
|
evas_cache_image_surface_alloc(ie, b.w, b.h);
|
2009-12-22 15:11:57 -08:00
|
|
|
ptr = evas_cache_image_pixels(ie);
|
|
|
|
if (!ptr)
|
2008-03-01 07:27:20 -08:00
|
|
|
{
|
|
|
|
pmaps_buffer_close(&b);
|
2009-12-22 15:11:57 -08:00
|
|
|
*error = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED;
|
|
|
|
return EINA_FALSE;
|
2008-03-01 07:27:20 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (b.type[1] != '4')
|
|
|
|
{
|
|
|
|
while (pixels > 0 && b.color_get(&b, ptr))
|
|
|
|
{
|
|
|
|
pixels--;
|
|
|
|
ptr++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
while (pixels > 0
|
|
|
|
&& (b.current != b.end || pmaps_buffer_raw_update(&b)))
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 7; i >= 0 && pixels > 0; i--)
|
|
|
|
{
|
|
|
|
if (*b.current & (1 << i))
|
|
|
|
*ptr = 0xff000000;
|
|
|
|
else
|
|
|
|
*ptr = 0xffffffff;
|
|
|
|
ptr++;
|
|
|
|
pixels--;
|
|
|
|
}
|
|
|
|
b.current++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* if there are some pix missing, give them a proper default */
|
|
|
|
memset(ptr, 0xff, 4 * pixels);
|
|
|
|
pmaps_buffer_close(&b);
|
|
|
|
|
2009-12-22 15:11:57 -08:00
|
|
|
*error = EVAS_LOAD_ERROR_NONE;
|
|
|
|
return EINA_TRUE;
|
2008-03-01 07:27:20 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* internal used functions */
|
2009-12-22 15:11:57 -08:00
|
|
|
static Eina_Bool
|
|
|
|
pmaps_buffer_open(Pmaps_Buffer *b, const char *filename, int *error)
|
2008-03-01 07:27:20 -08:00
|
|
|
{
|
|
|
|
size_t len;
|
|
|
|
|
2011-12-14 01:53:25 -08:00
|
|
|
b->file = eina_file_open(filename, EINA_FALSE);
|
2008-03-01 07:27:20 -08:00
|
|
|
if (!b->file)
|
2009-12-22 15:11:57 -08:00
|
|
|
{
|
|
|
|
*error = EVAS_LOAD_ERROR_DOES_NOT_EXIST;
|
|
|
|
return EINA_FALSE;
|
|
|
|
}
|
2008-03-01 07:27:20 -08:00
|
|
|
|
2011-12-14 01:53:25 -08:00
|
|
|
b->map = eina_file_map_all(b->file, EINA_FILE_SEQUENTIAL);
|
|
|
|
if (!b->map)
|
|
|
|
{
|
|
|
|
*error = EVAS_LOAD_ERROR_DOES_NOT_EXIST;
|
|
|
|
eina_file_close(b->file);
|
|
|
|
b->file = NULL;
|
|
|
|
return EINA_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
b->position = 0;
|
2008-03-01 07:27:20 -08:00
|
|
|
*b->buffer = 0;
|
|
|
|
*b->unread = 0;
|
|
|
|
b->last_buffer = 0;
|
|
|
|
b->unread_len = 0;
|
|
|
|
|
|
|
|
len = pmaps_buffer_plain_update(b);
|
|
|
|
|
|
|
|
if (len < 3)
|
2009-12-22 15:11:57 -08:00
|
|
|
{
|
|
|
|
*error = EVAS_LOAD_ERROR_CORRUPT_FILE;
|
2011-12-14 01:53:25 -08:00
|
|
|
eina_file_map_free(b->file, b->map);
|
|
|
|
eina_file_close(b->file);
|
|
|
|
b->map = NULL;
|
2011-01-13 22:50:32 -08:00
|
|
|
b->file = NULL;
|
2009-12-22 15:11:57 -08:00
|
|
|
return EINA_FALSE;
|
|
|
|
}
|
2008-03-01 07:27:20 -08:00
|
|
|
|
|
|
|
/* copy the type */
|
|
|
|
b->type[0] = b->buffer[0];
|
|
|
|
b->type[1] = b->buffer[1];
|
|
|
|
b->type[2] = 0;
|
|
|
|
/* skip the PX */
|
|
|
|
b->current = b->buffer + 2;
|
|
|
|
|
2009-12-22 15:11:57 -08:00
|
|
|
*error = EVAS_LOAD_ERROR_NONE;
|
|
|
|
return EINA_TRUE;
|
2008-03-01 07:27:20 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
pmaps_buffer_close(Pmaps_Buffer *b)
|
|
|
|
{
|
|
|
|
if (b->file)
|
2011-12-14 01:53:25 -08:00
|
|
|
{
|
|
|
|
if (b->map) eina_file_map_free(b->file, b->map);
|
|
|
|
b->map = NULL;
|
|
|
|
eina_file_close(b->file);
|
|
|
|
b->file = NULL;
|
|
|
|
}
|
2008-03-01 07:27:20 -08:00
|
|
|
}
|
|
|
|
|
2009-12-22 15:11:57 -08:00
|
|
|
static Eina_Bool
|
|
|
|
pmaps_buffer_header_parse(Pmaps_Buffer *b, int *error)
|
2008-03-01 07:27:20 -08:00
|
|
|
{
|
|
|
|
/* if there is no P at the beginning it is not a file we can parse */
|
|
|
|
if (b->type[0] != 'P')
|
2009-12-22 15:11:57 -08:00
|
|
|
{
|
|
|
|
*error = EVAS_LOAD_ERROR_UNKNOWN_FORMAT;
|
|
|
|
return EINA_FALSE;
|
|
|
|
}
|
2008-03-01 07:27:20 -08:00
|
|
|
|
|
|
|
/* get the width */
|
|
|
|
if (!pmaps_buffer_plain_int_get(b, &(b->w)) || b->w < 1)
|
2009-12-22 15:11:57 -08:00
|
|
|
{
|
|
|
|
*error = EVAS_LOAD_ERROR_CORRUPT_FILE;
|
|
|
|
return EINA_FALSE;
|
|
|
|
}
|
2008-03-01 07:27:20 -08:00
|
|
|
|
|
|
|
/* get the height */
|
|
|
|
if (!pmaps_buffer_plain_int_get(b, &(b->h)) || b->h < 1)
|
2009-12-22 15:11:57 -08:00
|
|
|
{
|
|
|
|
*error = EVAS_LOAD_ERROR_CORRUPT_FILE;
|
|
|
|
return EINA_FALSE;
|
|
|
|
}
|
2008-03-01 07:27:20 -08:00
|
|
|
|
|
|
|
/* get the maximum value. P1 and P4 don't have a maximum value. */
|
|
|
|
if (!(b->type[1] == '1' || b->type[1] == '4')
|
|
|
|
&& (!pmaps_buffer_plain_int_get(b, &(b->max)) || b->max < 1))
|
2009-12-22 15:11:57 -08:00
|
|
|
{
|
|
|
|
*error = EVAS_LOAD_ERROR_UNKNOWN_FORMAT;
|
|
|
|
return EINA_FALSE;
|
|
|
|
}
|
2008-03-01 07:27:20 -08:00
|
|
|
|
|
|
|
/* set up the color get callback */
|
|
|
|
switch (b->type[1])
|
|
|
|
{
|
|
|
|
/* Black and White */
|
|
|
|
case '1':
|
|
|
|
b->color_get = pmaps_buffer_plain_bw_get;
|
|
|
|
break;
|
|
|
|
case '4':
|
|
|
|
/* Binary black and white use another format */
|
|
|
|
b->color_get = NULL;
|
|
|
|
break;
|
|
|
|
case '2':
|
|
|
|
case '5':
|
|
|
|
b->color_get = pmaps_buffer_gray_get;
|
|
|
|
break;
|
|
|
|
case '3':
|
|
|
|
case '6':
|
|
|
|
b->color_get = pmaps_buffer_rgb_get;
|
|
|
|
break;
|
|
|
|
case '7':
|
|
|
|
/* XXX write me */
|
|
|
|
return 0;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/* set up the int get callback */
|
|
|
|
switch (b->type[1])
|
|
|
|
{
|
|
|
|
/* RAW */
|
|
|
|
case '5':
|
|
|
|
case '6':
|
|
|
|
if (b->max < 256)
|
|
|
|
b->int_get = pmaps_buffer_1byte_int_get;
|
|
|
|
else
|
|
|
|
b->int_get = pmaps_buffer_2byte_int_get;
|
|
|
|
|
|
|
|
if (b->current == b->end && !pmaps_buffer_raw_update(b))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
b->current++;
|
|
|
|
break;
|
|
|
|
/* Plain */
|
|
|
|
case '2':
|
|
|
|
case '3':
|
|
|
|
b->int_get = pmaps_buffer_plain_int_get;
|
|
|
|
break;
|
|
|
|
/* Black and White Bitmaps don't use that callback */
|
|
|
|
case '1':
|
|
|
|
case '4':
|
|
|
|
b->int_get = NULL;
|
|
|
|
/* we need to skip the next character fpr P4 it
|
|
|
|
* doesn't hurt if we do it for the P1 as well */
|
|
|
|
b->current++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static size_t
|
|
|
|
pmaps_buffer_plain_update(Pmaps_Buffer *b)
|
|
|
|
{
|
|
|
|
size_t r;
|
2011-12-14 01:53:25 -08:00
|
|
|
size_t max;
|
2008-03-01 07:27:20 -08:00
|
|
|
|
|
|
|
/* if we already are in the last buffer we can not update it */
|
|
|
|
if (b->last_buffer)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* if we have unread bytes we need to put them before the new read
|
|
|
|
* stuff */
|
|
|
|
if (b->unread_len)
|
|
|
|
memcpy(b->buffer, b->unread, b->unread_len);
|
2011-12-14 01:53:25 -08:00
|
|
|
|
|
|
|
max = FILE_BUFFER_SIZE - b->unread_len - 1;
|
|
|
|
if (b->position + max > eina_file_size_get(b->file))
|
|
|
|
max = eina_file_size_get(b->file) - b->position;
|
|
|
|
|
|
|
|
memcpy(&b->buffer[b->unread_len], b->map + b->position, max);
|
|
|
|
b->position += max;
|
|
|
|
r = max + b->unread_len;
|
2008-03-01 07:27:20 -08:00
|
|
|
|
|
|
|
/* we haven't read anything nor have we bytes in the unread buffer */
|
|
|
|
if (r == 0)
|
|
|
|
{
|
|
|
|
b->buffer[0] = '\0';
|
|
|
|
b->end = b->buffer;
|
|
|
|
b->last_buffer = 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (r < FILE_BUFFER_SIZE - 1)
|
|
|
|
{
|
|
|
|
/*we reached eof */ ;
|
|
|
|
b->last_buffer = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
b->buffer[r] = 0;
|
2011-12-14 01:53:25 -08:00
|
|
|
|
2011-04-15 00:08:14 -07:00
|
|
|
b->unread[0] = '\0';
|
|
|
|
b->unread_len = 0;
|
2008-03-01 07:27:20 -08:00
|
|
|
|
|
|
|
b->buffer[r] = '\0';
|
|
|
|
b->current = b->buffer;
|
|
|
|
b->end = b->buffer + r;
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
static size_t
|
|
|
|
pmaps_buffer_raw_update(Pmaps_Buffer *b)
|
|
|
|
{
|
|
|
|
size_t r;
|
2011-12-14 01:53:25 -08:00
|
|
|
size_t max;
|
2008-03-01 07:27:20 -08:00
|
|
|
|
|
|
|
if (b->last_buffer)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (b->unread_len)
|
|
|
|
memcpy(b->buffer, b->unread, b->unread_len);
|
|
|
|
|
2011-12-14 01:53:25 -08:00
|
|
|
max = FILE_BUFFER_SIZE - b->unread_len;
|
|
|
|
if (b->position + max > eina_file_size_get(b->file))
|
|
|
|
max = eina_file_size_get(b->file) - b->position;
|
|
|
|
|
|
|
|
memcpy(&b->buffer[b->unread_len], b->map + b->position, max);
|
|
|
|
b->position += max;
|
|
|
|
r = max + b->unread_len;
|
2008-03-01 07:27:20 -08:00
|
|
|
|
2011-04-15 00:08:14 -07:00
|
|
|
if (r < FILE_BUFFER_SIZE)
|
2008-03-01 07:27:20 -08:00
|
|
|
{
|
2011-04-15 00:08:14 -07:00
|
|
|
/*we reached eof */
|
2008-03-01 07:27:20 -08:00
|
|
|
b->last_buffer = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
b->end = b->buffer + r;
|
|
|
|
b->current = b->buffer;
|
|
|
|
|
|
|
|
if (b->unread_len)
|
|
|
|
{
|
|
|
|
/* the buffer is now read */
|
2011-04-15 00:08:14 -07:00
|
|
|
*b->unread = 0;
|
2008-03-01 07:27:20 -08:00
|
|
|
b->unread_len = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
pmaps_buffer_plain_int_get(Pmaps_Buffer *b, int *val)
|
|
|
|
{
|
|
|
|
char *start;
|
|
|
|
DATA8 lastc;
|
|
|
|
|
|
|
|
/* first skip all white space
|
|
|
|
* Note: we are skipping here actually every character than is not
|
|
|
|
* a digit */
|
|
|
|
while (!isdigit(*b->current))
|
|
|
|
{
|
|
|
|
if (*b->current == '\0')
|
|
|
|
{
|
|
|
|
if (!pmaps_buffer_plain_update(b))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (*b->current == '#' && !pmaps_buffer_comment_skip(b))
|
|
|
|
return 0;
|
|
|
|
b->current++;
|
|
|
|
}
|
|
|
|
|
|
|
|
start = (char *)b->current;
|
|
|
|
/* now find the end of the number */
|
|
|
|
while (isdigit(*b->current))
|
|
|
|
b->current++;
|
|
|
|
|
|
|
|
lastc = *b->current;
|
|
|
|
*b->current = '\0';
|
|
|
|
*val = atoi(start);
|
|
|
|
*b->current = lastc;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
pmaps_buffer_1byte_int_get(Pmaps_Buffer *b, int *val)
|
|
|
|
{
|
|
|
|
/* are we at the end of the buffer? */
|
|
|
|
if (b->current == b->end && !pmaps_buffer_raw_update(b))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
*val = *b->current;
|
|
|
|
b->current++;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
static int
|
|
|
|
pmaps_buffer_2byte_int_get(Pmaps_Buffer *b, int *val)
|
|
|
|
{
|
|
|
|
/* are we at the end of the buffer? */
|
|
|
|
if (b->current == b->end && !pmaps_buffer_raw_update(b))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
*val = (int)(*b->current << 8);
|
|
|
|
b->current++;
|
|
|
|
|
|
|
|
/* are we at the end of the buffer? */
|
|
|
|
if (b->current == b->end && !pmaps_buffer_raw_update(b))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
*val |= *b->current;
|
|
|
|
b->current++;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
pmaps_buffer_comment_skip(Pmaps_Buffer *b)
|
|
|
|
{
|
|
|
|
while (*b->current != '\n')
|
|
|
|
{
|
|
|
|
if (*b->current == '\0')
|
|
|
|
{
|
|
|
|
if (!pmaps_buffer_plain_update(b))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
b->current++;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
pmaps_buffer_rgb_get(Pmaps_Buffer *b, DATA32 *color)
|
|
|
|
{
|
|
|
|
int vr, vg, vb;
|
|
|
|
|
|
|
|
if (!b->int_get(b, &vr) || !b->int_get(b, &vg) || !b->int_get(b, &vb))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (b->max != 255)
|
|
|
|
{
|
|
|
|
vr = (vr * 255) / b->max;
|
|
|
|
vg = (vg * 255) / b->max;
|
|
|
|
vb = (vb * 255) / b->max;
|
|
|
|
}
|
|
|
|
if (vr > 255)
|
|
|
|
vr = 255;
|
|
|
|
if (vg > 255)
|
|
|
|
vg = 255;
|
|
|
|
if (vb > 255)
|
|
|
|
vb = 255;
|
|
|
|
|
2010-06-07 22:39:46 -07:00
|
|
|
*color = ARGB_JOIN(0xff, vr, vg, vb);
|
2008-03-01 07:27:20 -08:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
pmaps_buffer_gray_get(Pmaps_Buffer *b, DATA32 *color)
|
|
|
|
{
|
|
|
|
int val;
|
|
|
|
|
|
|
|
if (!b->int_get(b, &val))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (b->max != 255)
|
|
|
|
val = (val * 255) / b->max;
|
|
|
|
if (val > 255)
|
|
|
|
val = 255;
|
2010-06-07 22:39:46 -07:00
|
|
|
*color = ARGB_JOIN(0xff, val, val, val);
|
2008-03-01 07:27:20 -08:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
pmaps_buffer_plain_bw_get(Pmaps_Buffer *b, DATA32 *val)
|
|
|
|
{
|
|
|
|
/* first skip all white space
|
|
|
|
* Note: we are skipping here actually every character than is not
|
|
|
|
* a digit */
|
|
|
|
while (!isdigit(*b->current))
|
|
|
|
{
|
|
|
|
if (*b->current == '\0')
|
|
|
|
{
|
|
|
|
if (!pmaps_buffer_raw_update(b))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (*b->current == '#' && !pmaps_buffer_comment_skip(b))
|
|
|
|
return 0;
|
|
|
|
b->current++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*b->current == '0')
|
|
|
|
*val = 0xffffffff;
|
|
|
|
else
|
|
|
|
*val = 0xff000000;
|
|
|
|
|
|
|
|
b->current++;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* external functions */
|
2009-06-16 06:01:36 -07:00
|
|
|
static int
|
2008-03-01 07:27:20 -08:00
|
|
|
module_open(Evas_Module *em)
|
|
|
|
{
|
|
|
|
if (!em)
|
|
|
|
return 0;
|
|
|
|
em->functions = (void *)(&evas_image_load_pmaps_func);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2009-06-16 06:01:36 -07:00
|
|
|
static void
|
cleanup: fix some "unused" errors from -Wextra.
As we're heading for a release we better remove as much errors as
possible and as the first step I'm removing warnings due unused
parameters, variables and functions. These tend to pollute real errors
spotted by -Wall and clang/llvm.
This does not fixes all, just the clear that could be set to
__UNUSED__, particularly to do (and I'd like some help from the
authors):
* src/lib/engines/common/evas_font_{draw,query}.c (tasn):
intl_props is just used while doing BIDI, but also used in other
#ifdef blocks :-/
* evas_map_* (raster):
huge amount of warnings, code is quite confusing and thus I'm not
touching it. I have no idea whenever the commented blocks or extra
parameters are intended to be used or no.
* src/modules/engines/fbevas_fb_main.c (raster?):
is fb_setvt() to be used? If not do you mind removing it?
* src/modules/engines/gl_{common,x11} (raster):
huge amount of warnings, code is quite nested and full of #ifdefs
that does not help to give a clear picture of what's going on.
* src/bin/evas_cserve_main.c (raster):
I could have ignored most of the errors, but is the code correct? I
mean, there is no unload of images being applied. If you confirm
none of those warnings are harmful I can flag them as unused.
* src/lib/engines/common_8 (dottedmag):
lots of unused functions that were acquired from common_16, they
are unused and if they will not, then they should be removed.
SVN revision: 52421
2010-09-18 12:17:41 -07:00
|
|
|
module_close(Evas_Module *em __UNUSED__)
|
2008-03-01 07:27:20 -08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2009-06-16 06:01:36 -07:00
|
|
|
static Evas_Module_Api evas_modapi = {
|
2008-03-01 07:27:20 -08:00
|
|
|
EVAS_MODULE_API_VERSION,
|
|
|
|
"pmaps",
|
2009-06-16 06:01:36 -07:00
|
|
|
"none",
|
|
|
|
{
|
|
|
|
module_open,
|
|
|
|
module_close
|
|
|
|
}
|
2008-03-01 07:27:20 -08:00
|
|
|
};
|
|
|
|
|
2009-06-16 06:01:36 -07:00
|
|
|
EVAS_MODULE_DEFINE(EVAS_MODULE_TYPE_IMAGE_LOADER, image_loader, pmaps);
|
|
|
|
|
|
|
|
#ifndef EVAS_STATIC_BUILD_PMAPS
|
|
|
|
EVAS_EINA_MODULE_DEFINE(image_loader, pmaps);
|
|
|
|
#endif
|