forked from enlightenment/efl
parent
28dff2e36e
commit
3a85bfb709
|
@ -1,2 +1,3 @@
|
||||||
The Rasterman (Carsten Haitzler) <raster@rasterman.com>
|
The Rasterman (Carsten Haitzler) <raster@rasterman.com>
|
||||||
David Goodlad <dgoodlad@gmail.com>
|
David Goodlad <dgoodlad@gmail.com>
|
||||||
|
Cedric Bail <cedric.bail@free.fr>
|
||||||
|
|
|
@ -126,18 +126,13 @@ extern "C" {
|
||||||
EAPI int eet_shutdown(void);
|
EAPI int eet_shutdown(void);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Turn cacheburst on/off
|
* Clear eet cache
|
||||||
*
|
*
|
||||||
* @param on Set this to 1 to turn on, 0 to turn off.
|
* Eet didn't free items by default. If you are under memory presure, just
|
||||||
*
|
* call this function to recall all memory that are not yet referenced anymore.
|
||||||
* This enables cacheburst mode. This is where eet will not free items from
|
* The cache take care of modification on disk.
|
||||||
* its internal share cache even when their references hit 0. This is
|
|
||||||
* intended to be enabled during bursts where eet may open several eet
|
|
||||||
* files over and over and over again (eg in initialization of an app) and
|
|
||||||
* thius this will avoid repeated openings. It will NOT respect changes
|
|
||||||
* on disk and if you open a LOT of files may use a lot of memory.
|
|
||||||
*/
|
*/
|
||||||
EAPI void eet_cacheburst(int on);
|
EAPI void eet_clearcache(void);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Open an eet file on disk, and returns a handle to it.
|
* Open an eet file on disk, and returns a handle to it.
|
||||||
|
@ -235,6 +230,26 @@ extern "C" {
|
||||||
*/
|
*/
|
||||||
EAPI void *eet_read(Eet_File *ef, const char *name, int *size_ret);
|
EAPI void *eet_read(Eet_File *ef, const char *name, int *size_ret);
|
||||||
|
|
||||||
|
/**
|
||||||
|
|
||||||
|
* Read a specified entry from an eet file and return data
|
||||||
|
* @param ef A valid eet file handle opened for reading.
|
||||||
|
* @param name Name of the entry. eg: "/base/file_i_want".
|
||||||
|
* @param size_ret Number of bytes read from entry and returned.
|
||||||
|
* @return The data stored in that entry in the eet file.
|
||||||
|
*
|
||||||
|
* This function finds an entry in the eet file that is stored under the
|
||||||
|
* name specified, and returns that data if not compressed and successful.
|
||||||
|
* NULL is returned if the lookup fails or if memory errors are
|
||||||
|
* encountered or if the data is comrpessed. The calling program must never
|
||||||
|
* call free() on the returned data. The number of bytes in the returned
|
||||||
|
* data chunk are placed in size_ret.
|
||||||
|
*
|
||||||
|
* If the eet file handle is not valid NULL is returned and size_ret is
|
||||||
|
* filled with 0.
|
||||||
|
*/
|
||||||
|
EAPI void *eet_read_direct (Eet_File *ef, const char *name, int *size_ret);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Write a specified entry to an eet file handle
|
* Write a specified entry to an eet file handle
|
||||||
* @param ef A valid eet file handle opened for writing.
|
* @param ef A valid eet file handle opened for writing.
|
||||||
|
|
|
@ -46,4 +46,40 @@ void _eet_memfile_shutdown();
|
||||||
#define PATH_MAX 4096
|
#define PATH_MAX 4096
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* caluclate hash table entry valu with bitmask size of hash_size */
|
||||||
|
static int
|
||||||
|
eet_hash_gen(const char *key, int hash_size)
|
||||||
|
{
|
||||||
|
int hash_num = 0;
|
||||||
|
int value, i;
|
||||||
|
unsigned char *ptr;
|
||||||
|
|
||||||
|
const int masks[9] =
|
||||||
|
{
|
||||||
|
0x00,
|
||||||
|
0x01,
|
||||||
|
0x03,
|
||||||
|
0x07,
|
||||||
|
0x0f,
|
||||||
|
0x1f,
|
||||||
|
0x3f,
|
||||||
|
0x7f,
|
||||||
|
0xff
|
||||||
|
};
|
||||||
|
|
||||||
|
/* no string - index 0 */
|
||||||
|
if (!key) return 0;
|
||||||
|
|
||||||
|
/* calc hash num */
|
||||||
|
for (i = 0, ptr = (unsigned char *)key, value = (int)(*ptr);
|
||||||
|
value;
|
||||||
|
ptr++, i++, value = (int)(*ptr))
|
||||||
|
hash_num ^= (value | (value << 8)) >> (i & 0x7);
|
||||||
|
|
||||||
|
/* mask it */
|
||||||
|
hash_num &= masks[hash_size];
|
||||||
|
/* return it */
|
||||||
|
return hash_num;
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -567,7 +567,7 @@ eet_data_chunk_put(Eet_Data_Chunk *chnk, Eet_Data_Stream *ds)
|
||||||
{
|
{
|
||||||
int *size;
|
int *size;
|
||||||
int s;
|
int s;
|
||||||
int size_ret;
|
int size_ret = 0;
|
||||||
|
|
||||||
if (!chnk->data) return;
|
if (!chnk->data) return;
|
||||||
/* chunk head */
|
/* chunk head */
|
||||||
|
@ -588,37 +588,6 @@ eet_data_chunk_put(Eet_Data_Chunk *chnk, Eet_Data_Stream *ds)
|
||||||
|
|
||||||
/*---*/
|
/*---*/
|
||||||
|
|
||||||
static int
|
|
||||||
_eet_descriptor_hash_gen(char *key, int hash_size)
|
|
||||||
{
|
|
||||||
int hash_num = 0, i;
|
|
||||||
unsigned char *ptr;
|
|
||||||
const int masks[9] =
|
|
||||||
{
|
|
||||||
0x00,
|
|
||||||
0x01,
|
|
||||||
0x03,
|
|
||||||
0x07,
|
|
||||||
0x0f,
|
|
||||||
0x1f,
|
|
||||||
0x3f,
|
|
||||||
0x7f,
|
|
||||||
0xff
|
|
||||||
};
|
|
||||||
|
|
||||||
/* no string - index 0 */
|
|
||||||
if (!key) return 0;
|
|
||||||
|
|
||||||
/* calc hash num */
|
|
||||||
for (i = 0, ptr = (unsigned char *)key; *ptr; ptr++, i++)
|
|
||||||
hash_num ^= ((int)(*ptr) | ((int)(*ptr) << 8)) >> (i % 8);
|
|
||||||
|
|
||||||
/* mask it */
|
|
||||||
hash_num &= masks[hash_size];
|
|
||||||
/* return it */
|
|
||||||
return hash_num;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
_eet_descriptor_hash_new(Eet_Data_Descriptor *edd)
|
_eet_descriptor_hash_new(Eet_Data_Descriptor *edd)
|
||||||
{
|
{
|
||||||
|
@ -632,7 +601,7 @@ _eet_descriptor_hash_new(Eet_Data_Descriptor *edd)
|
||||||
int hash;
|
int hash;
|
||||||
|
|
||||||
ede = &(edd->elements.set[i]);
|
ede = &(edd->elements.set[i]);
|
||||||
hash = _eet_descriptor_hash_gen((char *) ede->name, 6);
|
hash = eet_hash_gen((char *) ede->name, 6);
|
||||||
if (!edd->elements.hash.buckets[hash].element)
|
if (!edd->elements.hash.buckets[hash].element)
|
||||||
edd->elements.hash.buckets[hash].element = ede;
|
edd->elements.hash.buckets[hash].element = ede;
|
||||||
else
|
else
|
||||||
|
@ -673,7 +642,7 @@ _eet_descriptor_hash_find(Eet_Data_Descriptor *edd, char *name)
|
||||||
int hash;
|
int hash;
|
||||||
Eet_Data_Descriptor_Hash *bucket;
|
Eet_Data_Descriptor_Hash *bucket;
|
||||||
|
|
||||||
hash = _eet_descriptor_hash_gen(name, 6);
|
hash = eet_hash_gen(name, 6);
|
||||||
if (!edd->elements.hash.buckets[hash].element) return NULL;
|
if (!edd->elements.hash.buckets[hash].element) return NULL;
|
||||||
if (!strcmp(edd->elements.hash.buckets[hash].element->name, name))
|
if (!strcmp(edd->elements.hash.buckets[hash].element->name, name))
|
||||||
return edd->elements.hash.buckets[hash].element;
|
return edd->elements.hash.buckets[hash].element;
|
||||||
|
@ -859,11 +828,19 @@ eet_data_read(Eet_File *ef, Eet_Data_Descriptor *edd, char *name)
|
||||||
void *data_dec;
|
void *data_dec;
|
||||||
void *data;
|
void *data;
|
||||||
int size;
|
int size;
|
||||||
|
int required_free = 0;
|
||||||
|
|
||||||
|
data = eet_read_direct (ef, name, &size);
|
||||||
|
if (!data)
|
||||||
|
{
|
||||||
|
required_free = 1;
|
||||||
data = eet_read(ef, name, &size);
|
data = eet_read(ef, name, &size);
|
||||||
if (!data) return NULL;
|
if (!data) return NULL;
|
||||||
|
}
|
||||||
data_dec = eet_data_descriptor_decode(edd, data, size);
|
data_dec = eet_data_descriptor_decode(edd, data, size);
|
||||||
|
if (required_free)
|
||||||
free(data);
|
free(data);
|
||||||
|
|
||||||
return data_dec;
|
return data_dec;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -719,11 +719,21 @@ eet_data_image_read(Eet_File *ef, const char *name,
|
||||||
void *data;
|
void *data;
|
||||||
int size;
|
int size;
|
||||||
unsigned int *d = NULL;
|
unsigned int *d = NULL;
|
||||||
|
int free_data = 0;
|
||||||
|
|
||||||
|
data = eet_read_direct (ef, name, &size);
|
||||||
|
if (!data)
|
||||||
|
{
|
||||||
data = eet_read(ef, name, &size);
|
data = eet_read(ef, name, &size);
|
||||||
|
free_data = 1;
|
||||||
|
}
|
||||||
|
|
||||||
if (!data) return NULL;
|
if (!data) return NULL;
|
||||||
d = eet_data_image_decode(data, size, w, h, alpha, compress, quality, lossy);
|
d = eet_data_image_decode(data, size, w, h, alpha, compress, quality, lossy);
|
||||||
|
|
||||||
|
if (free_data)
|
||||||
free(data);
|
free(data);
|
||||||
|
|
||||||
return d;
|
return d;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -732,14 +742,23 @@ eet_data_image_header_read(Eet_File *ef, const char *name,
|
||||||
unsigned int *w, unsigned int *h, int *alpha,
|
unsigned int *w, unsigned int *h, int *alpha,
|
||||||
int *compress, int *quality, int *lossy)
|
int *compress, int *quality, int *lossy)
|
||||||
{
|
{
|
||||||
void *data;
|
void *data = NULL;
|
||||||
int size;
|
int size = 0;
|
||||||
int d;
|
int d;
|
||||||
|
int free_data = 0;
|
||||||
|
|
||||||
|
data = eet_read_direct (ef, name, &size);
|
||||||
|
if (!data)
|
||||||
|
{
|
||||||
data = eet_read(ef, name, &size);
|
data = eet_read(ef, name, &size);
|
||||||
|
free_data = 1;
|
||||||
|
}
|
||||||
|
|
||||||
if (!data) return 0;
|
if (!data) return 0;
|
||||||
d = eet_data_image_header_decode(data, size, w, h, alpha, compress, quality, lossy);
|
d = eet_data_image_header_decode(data, size, w, h, alpha, compress, quality, lossy);
|
||||||
|
if (free_data)
|
||||||
free(data);
|
free(data);
|
||||||
|
|
||||||
return d;
|
return d;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue