diff --git a/src/driver/framebuffer.cpp b/src/driver/framebuffer.cpp index 1d8ad5adb..9e66ae65a 100644 --- a/src/driver/framebuffer.cpp +++ b/src/driver/framebuffer.cpp @@ -814,6 +814,70 @@ void CFrameBuffer::setIconBasePath(const std::string & iconPath) iconBasePath = iconPath; } +int CFrameBuffer::getIconHeight(const char * const filename) +{ + struct rawHeader header; + uint16_t height; + int icon_fd; + + char *ptr = rindex(filename, '.'); + if (ptr) { + *ptr = 0; + std::string newname = iconBasePath + std::string(filename) + ".gif"; + *ptr = '.'; + if (!access(newname.c_str(), F_OK)) + return g_PicViewer->getHeight(newname.c_str()); + } + + icon_fd = open(filename, O_RDONLY); + + if (icon_fd == -1) + { + printf("Framebuffer getIconHeight: error while loading icon: %s\n", filename); + return 0; + } + else + { + read(icon_fd, &header, sizeof(struct rawHeader)); + height = (header.height_hi << 8) | header.height_lo; + } + + close(icon_fd); + return height; +} + +int CFrameBuffer::getIconWidth(const char * const filename) +{ + struct rawHeader header; + uint16_t width; + int icon_fd; + + char *ptr = rindex(filename, '.'); + if (ptr) { + *ptr = 0; + std::string newname = iconBasePath + std::string(filename) + ".gif"; + *ptr = '.'; + if (!access(newname.c_str(), F_OK)) + return g_PicViewer->getWidth(newname.c_str()); + } + + icon_fd = open(filename, O_RDONLY); + + if (icon_fd == -1) + { + printf("Framebuffer getIconWidth: error while loading icon: %s\n", filename); + width = 0; + } + else + { + read(icon_fd, &header, sizeof(struct rawHeader)); + width = (header.width_hi << 8) | header.width_lo; + } + + close(icon_fd); + return width; +} + bool CFrameBuffer::paintIcon8(const std::string & filename, const int x, const int y, const unsigned char offset) { if (!getActive()) diff --git a/src/driver/framebuffer.h b/src/driver/framebuffer.h index e76f75f12..02626b3b4 100644 --- a/src/driver/framebuffer.h +++ b/src/driver/framebuffer.h @@ -110,6 +110,9 @@ class CFrameBuffer static CFrameBuffer* getInstance(); + int getIconWidth(const char * const filename); // infos about icon dimensions + int getIconHeight(const char * const filename); + void init(const char * const fbDevice = "/dev/fb/0"); int setMode(unsigned int xRes, unsigned int yRes, unsigned int bpp); diff --git a/src/driver/pictureviewer/pictureviewer.cpp b/src/driver/pictureviewer/pictureviewer.cpp index e7069ba11..96ff6def2 100644 --- a/src/driver/pictureviewer/pictureviewer.cpp +++ b/src/driver/pictureviewer/pictureviewer.cpp @@ -443,6 +443,26 @@ printf("logo file: %s\n", fname); return ret; } +int CPictureViewer::getWidth(const char* name) +{ + int x, y; + CFormathandler *fh; + fh = fh_getsize(name, &x, &y, INT_MAX, INT_MAX); + if (fh == NULL) + return -1; + return x; +} + +int CPictureViewer::getHeight(const char* name) +{ + int x, y; + CFormathandler *fh; + fh = fh_getsize(name, &x, &y, INT_MAX, INT_MAX); + if (fh == NULL) + return -1; + return y; +} + bool CPictureViewer::DisplayImage (const std::string & name, int posx, int posy, int width, int height) { int x, y; diff --git a/src/driver/pictureviewer/pictureviewer.h b/src/driver/pictureviewer/pictureviewer.h index 03c1c0673..8cde6c92b 100644 --- a/src/driver/pictureviewer/pictureviewer.h +++ b/src/driver/pictureviewer/pictureviewer.h @@ -65,6 +65,8 @@ class CPictureViewer bool DisplayImage (const std::string & name, int posx, int posy, int width, int height); bool DisplayLogo (uint64_t channel_id, int posx, int posy, int width, int height); fb_pixel_t * getImage (const std::string & name, int width, int height); + int getWidth(const char *name); + int getHeight(const char *name); private: CFormathandler *fh_root;