summaryrefslogtreecommitdiff
path: root/apps/misc.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/misc.c')
-rw-r--r--apps/misc.c69
1 files changed, 68 insertions, 1 deletions
diff --git a/apps/misc.c b/apps/misc.c
index f878bad833..36f45d46e0 100644
--- a/apps/misc.c
+++ b/apps/misc.c
@@ -99,6 +99,10 @@
99#endif 99#endif
100#endif 100#endif
101 101
102#ifndef PLUGIN
103#include "core_alloc.h" /*core_load_bmp()*/
104#endif
105
102#ifdef HAVE_HARDWARE_CLICK 106#ifdef HAVE_HARDWARE_CLICK
103#include "piezo.h" 107#include "piezo.h"
104#endif 108#endif
@@ -1572,4 +1576,67 @@ enum current_activity get_current_activity(void)
1572 return current_activity[current_activity_top?current_activity_top-1:0]; 1576 return current_activity[current_activity_top?current_activity_top-1:0];
1573} 1577}
1574 1578
1575#endif 1579/* core_load_bmp opens bitmp filename and allocates space for it
1580* you must set bm->data with the result from core_get_data(handle)
1581* you must also call core_free(handle) when finished with the bitmap
1582* returns handle, ALOC_ERR(0) on failure
1583* ** Extended error info truth table **
1584* [ Handle ][buf_reqd]
1585* [ > 0 ][ > 0 ] buf_reqd indicates how many bytes were used
1586* [ALOC_ERR][ > 0 ] buf_reqd indicates how many bytes are needed
1587* [ALOC_ERR][READ_ERR] there was an error reading the file or it is empty
1588*/
1589int core_load_bmp(const char * filename, struct bitmap *bm, const int bmformat,
1590 ssize_t *buf_reqd, struct buflib_callbacks *ops)
1591{
1592 ssize_t buf_size;
1593 ssize_t size_read = 0;
1594 int handle = CLB_ALOC_ERR;
1595
1596 int fd = open(filename, O_RDONLY);
1597 *buf_reqd = CLB_READ_ERR;
1598
1599 if (fd < 0) /* Exit if file opening failed */
1600 {
1601 DEBUGF("read_bmp_file: can't open '%s', rc: %d\n", filename, fd);
1602 return CLB_ALOC_ERR;
1603 }
1604
1605 buf_size = read_bmp_fd(fd, bm, 0, bmformat|FORMAT_RETURN_SIZE, NULL);
1606
1607 if (buf_size > 0)
1608 {
1609
1610 handle = core_alloc_ex(filename, (size_t) buf_size, ops);
1611
1612 if (handle > 0)
1613 {
1614 core_pin(handle);
1615 bm->data = core_get_data(handle);
1616 lseek(fd, 0, SEEK_SET); /* reset to beginning of file */
1617 size_read = read_bmp_fd(fd, bm, buf_size, bmformat, NULL);
1618
1619 if (size_read > 0) /* free unused alpha channel, if any */
1620 {
1621 core_shrink(handle, bm->data, size_read);
1622 *buf_reqd = size_read;
1623 }
1624 bm->data = NULL; /* do this to force a crash later if the
1625 caller doesnt call core_get_data() */
1626 core_unpin(handle);
1627 }
1628 else
1629 *buf_reqd = buf_size; /* couldn't allocate pass bytes needed */
1630
1631 if (size_read <= 0)
1632 {
1633 /* error reading file */
1634 core_free(handle); /* core_free() ignores free handles (<= 0) */
1635 handle = CLB_ALOC_ERR;
1636 }
1637 }
1638
1639 close(fd);
1640 return handle;
1641}
1642#endif /* ndef __PCTOOL__ */