Mode fb and picviewer cleanup; unify channel logo display code

git-svn-id: file:///home/bas/coolstream_public_svn/THIRDPARTY/applications/neutrino-experimental@259 e54a6e83-5905-42d5-8d5c-058d10e6a962
This commit is contained in:
focus
2010-02-05 15:26:57 +00:00
parent 2f6462c65d
commit 3fb6607ba0
16 changed files with 498 additions and 405 deletions

View File

@@ -26,11 +26,7 @@
class CFBWindow
{
public:
#ifdef FB_USE_PALETTE
typedef unsigned short color_t;
#else
typedef unsigned int color_t;
#endif
typedef void * font_t;
typedef void * private_data_t;

View File

@@ -228,7 +228,7 @@ void CFrameBuffer::init(const char * const fbDevice)
}
#ifdef USE_NEVIS_GXA
/* Open 7dev/mem for HW-register access */
/* Open /dev/mem for HW-register access */
devmem_fd = open("/dev/mem", O_RDWR | O_SYNC);
if (devmem_fd < 0) {
perror("Unable to open /dev/mem");
@@ -331,6 +331,14 @@ nolfb:
CFrameBuffer::~CFrameBuffer()
{
std::map<std::string, rawIcon>::iterator it;
for(it = icon_cache.begin(); it != icon_cache.end(); it++) {
/* printf("FB: delete cached icon %s: %x\n", it->first.c_str(), (int) it->second.data); */
cs_free_uncached(it->second.data);
}
icon_cache.clear();
if (background) {
delete[] background;
background = NULL;
@@ -740,32 +748,20 @@ void CFrameBuffer::paintVLineRel(int x, int y, int dy, const fb_pixel_t col)
return;
#ifdef USE_NEVIS_GXA
/* draw a single vertical line from point x/y with hight dx */
unsigned int cmd = GXA_CMD_NOT_TEXT | GXA_SRC_BMP_SEL(2) | GXA_DST_BMP_SEL(2) | GXA_PARAM_COUNT(2) | GXA_CMD_NOT_ALPHA;
/* draw a single vertical line from point x/y with hight dx */
unsigned int cmd = GXA_CMD_NOT_TEXT | GXA_SRC_BMP_SEL(2) | GXA_DST_BMP_SEL(2) | GXA_PARAM_COUNT(2) | GXA_CMD_NOT_ALPHA;
_write_gxa(gxa_base, GXA_FG_COLOR_REG, (unsigned int) col); /* setup the drawing color */
_write_gxa(gxa_base, GXA_LINE_CONTROL_REG, 0x00000404); /* X is major axis, skip last pixel */
_write_gxa(gxa_base, cmd, GXA_POINT(x, y + dy)); /* end point */
_write_gxa(gxa_base, cmd, GXA_POINT(x, y)); /* start point */
_write_gxa(gxa_base, GXA_FG_COLOR_REG, (unsigned int) col); /* setup the drawing color */
_write_gxa(gxa_base, GXA_LINE_CONTROL_REG, 0x00000404); /* X is major axis, skip last pixel */
_write_gxa(gxa_base, cmd, GXA_POINT(x, y + dy)); /* end point */
_write_gxa(gxa_base, cmd, GXA_POINT(x, y)); /* start point */
#else /* USE_NEVIS_GXA */
#if 0
fb_fillrect fillrect;
fillrect.dx = x;
fillrect.dy = y;
fillrect.width = 1;
fillrect.height = dy;
fillrect.color = col;
fillrect.rop = ROP_COPY;
ioctl(fd, FBIO_FILL_RECT, &fillrect);
return;
#else
uint8_t * pos = ((uint8_t *)getFrameBufferPointer()) + x * sizeof(fb_pixel_t) + stride * y;
for(int count=0;count<dy;count++) {
*(fb_pixel_t *)pos = col;
pos += stride;
}
#endif
#endif /* USE_NEVIS_GXA */
}
@@ -820,68 +816,22 @@ void CFrameBuffer::setIconBasePath(const std::string & iconPath)
iconBasePath = iconPath;
}
int CFrameBuffer::getIconHeight(const char * const filename)
void CFrameBuffer::getIconSize(const char * const filename, int* width, int *height)
{
struct rawHeader header;
uint16_t height;
int icon_fd;
std::map<std::string, rawIcon>::iterator it;
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());
*width = 0;
*height = 0;
/* if code ask for size, lets cache it. assume we have enough ram for cache */
/* FIXME offset seems never used in code, always default = 1 ? */
if(paintIcon(filename, 0, 0, 0, 1, false)) {
it = icon_cache.find(filename);
if(it != icon_cache.end()) {
*width = it->second.width;
*height = it->second.height;
}
}
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)
@@ -932,12 +882,12 @@ bool CFrameBuffer::paintIcon8(const std::string & filename, const int x, const i
bool CFrameBuffer::blitToPrimary(unsigned int * data, int dx, int dy, int sw, int sh)
{
#ifdef USE_NEVIS_GXA
u32 cmd;
void * uKva;
#ifdef USE_NEVIS_GXA
uKva = cs_phys_addr(data);
printf("CFrameBuffer::blitToPrimary: data %x Kva %x\n", data, uKva);
printf("CFrameBuffer::blitToPrimary: data %x Kva %x\n", (int) data, (int) uKva);
if(uKva == NULL)
return false;
@@ -960,7 +910,7 @@ printf("CFrameBuffer::blitToPrimary: data %x Kva %x\n", data, uKva);
if height h is given, center vertically between y and y+h
offset is a color offset (probably only useful with palette) */
bool CFrameBuffer::paintIcon(const std::string & filename, const int x, const int y,
const int h, const unsigned char offset)
const int h, const unsigned char offset, bool paint)
{
struct rawHeader header;
int width, height;
@@ -1050,13 +1000,17 @@ bool CFrameBuffer::paintIcon(const std::string & filename, const int x, const in
height = it->second.height;
//printf("paintIcon: already cached %s %d x %d\n", newname.c_str(), width, height);
}
if(!paint)
return true;
_display:
if (h != 0)
yy += (h - height) / 2;
if(blitToPrimary(data, x, y, width, height))
return true;
blit2FB(data, width, height, x, yy, 0, 0, true);
return true;
#if 0
uint8_t * d = ((uint8_t *)getFrameBufferPointer()) + x * sizeof(fb_pixel_t) + stride * yy;
fb_pixel_t * d2;
@@ -1075,14 +1029,17 @@ _display:
}
return true;
#endif
}
#if 0
bool CFrameBuffer::paintIcon(const char * const filename, const int x, const int y,
const int h, const unsigned char offset)
{
//printf("%s(%s, %d, %d, %d)\n", __FUNCTION__, filename, x, y, offset);
return paintIcon(std::string(filename), x, y, h, offset);
}
#endif
void CFrameBuffer::loadPal(const std::string & filename, const unsigned char offset, const unsigned char endidx)
{
@@ -1552,3 +1509,105 @@ void CFrameBuffer::Unlock()
{
locked = false;
}
void * CFrameBuffer::convertRGB2FB(unsigned char *rgbbuff, unsigned long x, unsigned long y, int transp)
{
unsigned long i;
unsigned int *fbbuff;
unsigned long count = x*y;
fbbuff = (unsigned int *) malloc(count * sizeof(unsigned int));
if(fbbuff == NULL)
{
printf("convertRGB2FB: Error: malloc\n");
return NULL;
}
for(i = 0; i < count ; i++)
fbbuff[i] = (transp << 24) | ((rgbbuff[i*3] << 16) & 0xFF0000) | ((rgbbuff[i*3+1] << 8) & 0xFF00) | (rgbbuff[i*3+2] & 0xFF);
return (void *) fbbuff;
}
void CFrameBuffer::blit2FB(void *fbbuff, uint32_t width, uint32_t height, uint32_t xoff, uint32_t yoff, uint32_t xp, uint32_t yp, bool transp)
{
int xc, yc;
xc = (width > xRes) ? xRes : width;
yc = (height > yRes) ? yRes : height;
#ifdef USE_NEVIS_GXA
u32 cmd;
void * uKva;
uKva = cs_phys_addr(fbbuff);
printf("CFrameBuffer::blit2FB: data %x Kva %x\n", (int) fbbuff, (int) uKva);
if(uKva != NULL) {
cmd = GXA_CMD_BLT | GXA_CMD_NOT_TEXT | GXA_SRC_BMP_SEL(1) | GXA_DST_BMP_SEL(2) | GXA_PARAM_COUNT(3);
_write_gxa(gxa_base, GXA_BMP1_TYPE_REG, (3 << 16) | width);
_write_gxa(gxa_base, GXA_BMP1_ADDR_REG, (unsigned int) uKva);
_write_gxa(gxa_base, cmd, GXA_POINT(xoff, yoff)); /* destination pos */
_write_gxa(gxa_base, cmd, GXA_POINT(xc, yc)); /* source width, FIXME real or adjusted xc, yc ? */
_write_gxa(gxa_base, cmd, GXA_POINT(xp, yp)); /* source pos */
return;
}
#endif
fb_pixel_t* data = (fb_pixel_t *) fbbuff;
uint8_t * d = ((uint8_t *)getFrameBufferPointer()) + xoff * sizeof(fb_pixel_t) + stride * yoff;
fb_pixel_t * d2;
for (int count = 0; count < yc; count++ ) {
fb_pixel_t *pixpos = &data[(count + yp) * width];
d2 = (fb_pixel_t *) d;
for (int count2 = 0; count2 < xc; count2++ ) {
fb_pixel_t pix = *(pixpos + xp);
if (!transp || (pix != 0)) {
*d2 = pix;
}
d2++;
pixpos++;
}
d += stride;
}
#if 0
for(int i = 0; i < yc; i++){
memcpy(clfb + (i + yoff)*stride + xoff*4, ip + (i + yp)*width + xp, xc*4);
}
#endif
}
void CFrameBuffer::displayRGB(unsigned char *rgbbuff, int x_size, int y_size, int x_pan, int y_pan, int x_offs, int y_offs, bool clearfb, int transp)
{
void *fbbuff = NULL;
if(rgbbuff == NULL)
return;
/* correct panning */
if(x_pan > x_size - (int)xRes) x_pan = 0;
if(y_pan > y_size - (int)yRes) y_pan = 0;
/* correct offset */
if(x_offs + x_size > (int)xRes) x_offs = 0;
if(y_offs + y_size > (int)yRes) y_offs = 0;
/* blit buffer 2 fb */
fbbuff = convertRGB2FB(rgbbuff, x_size, y_size, transp);
if(fbbuff==NULL)
return;
/* ClearFB if image is smaller */
/* if(x_size < (int)xRes || y_size < (int)yRes) */
if(clearfb)
CFrameBuffer::getInstance()->Clear();
blit2FB(fbbuff, x_size, y_size, x_offs, y_offs, x_pan, y_pan);
free(fbbuff);
}

View File

@@ -122,9 +122,6 @@ 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);
@@ -173,11 +170,10 @@ class CFrameBuffer
void setIconBasePath(const std::string & iconPath);
void getIconSize(const char * const filename, int* width, int *height);
/* h is the height of the target "window", if != 0 the icon gets centered in that window */
bool paintIcon (const char * const filename, const int x, const int y,
const int h = 0, const unsigned char offset = 1);
bool paintIcon (const std::string & filename, const int x, const int y,
const int h = 0, const unsigned char offset = 1);
const int h = 0, const unsigned char offset = 1, bool paint = true);
bool paintIcon8(const std::string & filename, const int x, const int y, const unsigned char offset = 0);
void loadPal (const std::string & filename, const unsigned char offset = 0, const unsigned char endidx = 255);
@@ -215,6 +211,9 @@ class CFrameBuffer
#else
inline void waitForIdle(void) {};
#endif
void* convertRGB2FB(unsigned char *rgbbuff, unsigned long x, unsigned long y, int transp = 0xFF);
void displayRGB(unsigned char *rgbbuff, int x_size, int y_size, int x_pan, int y_pan, int x_offs, int y_offs, bool clearfb = true, int transp = 0xFF);
void blit2FB(void *fbbuff, uint32_t width, uint32_t height, uint32_t xoff, uint32_t yoff, uint32_t xp = 0, uint32_t yp = 0, bool transp = false);
bool blitToPrimary(unsigned int * data, int dx, int dy, int sw, int sh);
};

View File

@@ -11,6 +11,5 @@ INCLUDES = \
noinst_LIBRARIES = libneutrino_pictureviewer.a
libneutrino_pictureviewer_a_SOURCES = \
pictureviewer.cpp fb_display.cpp \
png.cpp bmp.cpp resize.cpp jpeg.cpp \
gif.cpp crw.cpp make15color_errdiff.cpp
pictureviewer.cpp png.cpp bmp.cpp \
jpeg.cpp gif.cpp crw.cpp

View File

@@ -51,9 +51,10 @@ void fb_display(unsigned char *rgbbuff, int x_size, int y_size, int x_pan, int y
return;
/* ClearFB if image is smaller */
//if(x_size < (int)var->xres || y_size < (int)var->yres)
/* if(x_size < (int)var->xres || y_size < (int)var->yres) */
if(clearfb)
CFrameBuffer::getInstance()->Clear();
blit2FB(fbbuff, x_size, y_size, var->xres, var->yres, x_pan, y_pan, x_offs, y_offs);
free(fbbuff);
}

View File

@@ -2,7 +2,6 @@
#include <neutrino.h>
#include "pictureviewer.h"
#include "config.h"
#include "fb_display.h"
#include "driver/framebuffer.h"
@@ -12,11 +11,6 @@
#include "init_cs.h"
/* resize.cpp */
extern unsigned char *simple_resize (unsigned char *orgin, int ox, int oy, int dx, int dy);
extern unsigned char *color_average_resize (unsigned char *orgin, int ox, int oy, int dx, int dy);
#ifdef FBV_SUPPORT_GIF
extern int fh_gif_getsize (const char *, int *, int *, int, int);
extern int fh_gif_load (const char *, unsigned char **, int *, int *);
@@ -77,13 +71,13 @@ void CPictureViewer::init_handlers (void)
CPictureViewer::CFormathandler * CPictureViewer::fh_getsize (const char *name, int *x, int *y, int width_wanted, int height_wanted)
{
CFormathandler *fh;
for (fh = fh_root; fh != NULL; fh = fh->next) {
if (fh->id_pic (name))
if (fh->get_size (name, x, y, width_wanted, height_wanted) == FH_ERROR_OK)
return (fh);
}
return (NULL);
CFormathandler *fh;
for (fh = fh_root; fh != NULL; fh = fh->next) {
if (fh->id_pic (name))
if (fh->get_size (name, x, y, width_wanted, height_wanted) == FH_ERROR_OK)
return (fh);
}
return (NULL);
}
bool CPictureViewer::DecodeImage (const std::string & name, bool showBusySign, bool unscaled)
@@ -128,10 +122,7 @@ bool CPictureViewer::DecodeImage (const std::string & name, bool showBusySign, b
imx = (int) ((1.0 / m_aspect_ratio_correction) * x * (m_endy - m_starty) / y);
imy = (m_endy - m_starty);
}
if (m_scaling == SIMPLE)
m_NextPic_Buffer = simple_resize (m_NextPic_Buffer, x, y, imx, imy);
else
m_NextPic_Buffer = color_average_resize (m_NextPic_Buffer, x, y, imx, imy);
m_NextPic_Buffer = Resize(m_NextPic_Buffer, x, y, imx, imy, m_scaling);
x = imx;
y = imy;
}
@@ -195,89 +186,88 @@ bool CPictureViewer::DecodeImage (const std::string & name, bool showBusySign, b
void CPictureViewer::SetVisible (int startx, int endx, int starty, int endy)
{
m_startx = startx;
m_endx = endx;
m_starty = starty;
m_endy = endy;
m_startx = startx;
m_endx = endx;
m_starty = starty;
m_endy = endy;
}
bool CPictureViewer::ShowImage (const std::string & filename, bool unscaled)
{
// dbout("Show Image {\n");
// Wird eh ueberschrieben ,also schonmal freigeben... (wenig speicher)
if (m_CurrentPic_Buffer != NULL) {
free (m_CurrentPic_Buffer);
m_CurrentPic_Buffer = NULL;
}
DecodeImage (filename, true, unscaled);
DisplayNextImage ();
// dbout("Show Image }\n");
return true;
// dbout("Show Image {\n");
// Wird eh ueberschrieben ,also schonmal freigeben... (wenig speicher)
if (m_CurrentPic_Buffer != NULL) {
free (m_CurrentPic_Buffer);
m_CurrentPic_Buffer = NULL;
}
DecodeImage (filename, true, unscaled);
DisplayNextImage ();
// dbout("Show Image }\n");
return true;
}
bool CPictureViewer::DisplayNextImage ()
{
// dbout("DisplayNextImage {\n");
if (m_CurrentPic_Buffer != NULL) {
free (m_CurrentPic_Buffer);
m_CurrentPic_Buffer = NULL;
}
if (m_NextPic_Buffer != NULL)
fb_display (m_NextPic_Buffer, m_NextPic_X, m_NextPic_Y, m_NextPic_XPan, m_NextPic_YPan, m_NextPic_XPos, m_NextPic_YPos);
// dbout("DisplayNextImage fb_disp done\n");
m_CurrentPic_Buffer = m_NextPic_Buffer;
m_NextPic_Buffer = NULL;
m_CurrentPic_Name = m_NextPic_Name;
m_CurrentPic_X = m_NextPic_X;
m_CurrentPic_Y = m_NextPic_Y;
m_CurrentPic_XPos = m_NextPic_XPos;
m_CurrentPic_YPos = m_NextPic_YPos;
m_CurrentPic_XPan = m_NextPic_XPan;
m_CurrentPic_YPan = m_NextPic_YPan;
// dbout("DisplayNextImage }\n");
return true;
// dbout("DisplayNextImage {\n");
if (m_CurrentPic_Buffer != NULL) {
free (m_CurrentPic_Buffer);
m_CurrentPic_Buffer = NULL;
}
if (m_NextPic_Buffer != NULL)
//fb_display (m_NextPic_Buffer, m_NextPic_X, m_NextPic_Y, m_NextPic_XPan, m_NextPic_YPan, m_NextPic_XPos, m_NextPic_YPos);
CFrameBuffer::getInstance()->displayRGB(m_NextPic_Buffer, m_NextPic_X, m_NextPic_Y, m_NextPic_XPan, m_NextPic_YPan, m_NextPic_XPos, m_NextPic_YPos);
// dbout("DisplayNextImage fb_disp done\n");
m_CurrentPic_Buffer = m_NextPic_Buffer;
m_NextPic_Buffer = NULL;
m_CurrentPic_Name = m_NextPic_Name;
m_CurrentPic_X = m_NextPic_X;
m_CurrentPic_Y = m_NextPic_Y;
m_CurrentPic_XPos = m_NextPic_XPos;
m_CurrentPic_YPos = m_NextPic_YPos;
m_CurrentPic_XPan = m_NextPic_XPan;
m_CurrentPic_YPan = m_NextPic_YPan;
// dbout("DisplayNextImage }\n");
return true;
}
void CPictureViewer::Zoom (float factor)
{
// dbout("Zoom %f\n",factor);
showBusy (m_startx + 3, m_starty + 3, 10, 0xff, 0xff, 00);
// dbout("Zoom %f\n",factor);
showBusy (m_startx + 3, m_starty + 3, 10, 0xff, 0xff, 00);
int oldx = m_CurrentPic_X;
int oldy = m_CurrentPic_Y;
unsigned char *oldBuf = m_CurrentPic_Buffer;
m_CurrentPic_X = (int) (factor * m_CurrentPic_X);
m_CurrentPic_Y = (int) (factor * m_CurrentPic_Y);
int oldx = m_CurrentPic_X;
int oldy = m_CurrentPic_Y;
unsigned char *oldBuf = m_CurrentPic_Buffer;
m_CurrentPic_X = (int) (factor * m_CurrentPic_X);
m_CurrentPic_Y = (int) (factor * m_CurrentPic_Y);
if (m_scaling == COLOR)
m_CurrentPic_Buffer = color_average_resize (m_CurrentPic_Buffer, oldx, oldy, m_CurrentPic_X, m_CurrentPic_Y);
else
m_CurrentPic_Buffer = simple_resize (m_CurrentPic_Buffer, oldx, oldy, m_CurrentPic_X, m_CurrentPic_Y);
m_CurrentPic_Buffer = Resize(m_CurrentPic_Buffer, oldx, oldy, m_CurrentPic_X, m_CurrentPic_Y, m_scaling);
if (m_CurrentPic_Buffer == oldBuf) {
// resize failed
hideBusy ();
return;
}
if (m_CurrentPic_Buffer == oldBuf) {
// resize failed
hideBusy ();
return;
}
if (m_CurrentPic_X < (m_endx - m_startx))
m_CurrentPic_XPos = (m_endx - m_startx - m_CurrentPic_X) / 2 + m_startx;
else
m_CurrentPic_XPos = m_startx;
if (m_CurrentPic_Y < (m_endy - m_starty))
m_CurrentPic_YPos = (m_endy - m_starty - m_CurrentPic_Y) / 2 + m_starty;
else
m_CurrentPic_YPos = m_starty;
if (m_CurrentPic_X > (m_endx - m_startx))
m_CurrentPic_XPan = (m_CurrentPic_X - (m_endx - m_startx)) / 2;
else
m_CurrentPic_XPan = 0;
if (m_CurrentPic_Y > (m_endy - m_starty))
m_CurrentPic_YPan = (m_CurrentPic_Y - (m_endy - m_starty)) / 2;
else
m_CurrentPic_YPan = 0;
fb_display (m_CurrentPic_Buffer, m_CurrentPic_X, m_CurrentPic_Y, m_CurrentPic_XPan, m_CurrentPic_YPan, m_CurrentPic_XPos, m_CurrentPic_YPos);
if (m_CurrentPic_X < (m_endx - m_startx))
m_CurrentPic_XPos = (m_endx - m_startx - m_CurrentPic_X) / 2 + m_startx;
else
m_CurrentPic_XPos = m_startx;
if (m_CurrentPic_Y < (m_endy - m_starty))
m_CurrentPic_YPos = (m_endy - m_starty - m_CurrentPic_Y) / 2 + m_starty;
else
m_CurrentPic_YPos = m_starty;
if (m_CurrentPic_X > (m_endx - m_startx))
m_CurrentPic_XPan = (m_CurrentPic_X - (m_endx - m_startx)) / 2;
else
m_CurrentPic_XPan = 0;
if (m_CurrentPic_Y > (m_endy - m_starty))
m_CurrentPic_YPan = (m_CurrentPic_Y - (m_endy - m_starty)) / 2;
else
m_CurrentPic_YPan = 0;
//fb_display (m_CurrentPic_Buffer, m_CurrentPic_X, m_CurrentPic_Y, m_CurrentPic_XPan, m_CurrentPic_YPan, m_CurrentPic_XPos, m_CurrentPic_YPos);
CFrameBuffer::getInstance()->displayRGB(m_CurrentPic_Buffer, m_CurrentPic_X, m_CurrentPic_Y, m_CurrentPic_XPan, m_CurrentPic_YPan, m_CurrentPic_XPos, m_CurrentPic_YPos);
}
void CPictureViewer::Move (int dx, int dy)
@@ -313,7 +303,8 @@ void CPictureViewer::Move (int dx, int dy)
// dbout("Display x(%d) y(%d) xpan(%d) ypan(%d) xpos(%d) ypos(%d)\n",m_CurrentPic_X, m_CurrentPic_Y,
// m_CurrentPic_XPan, m_CurrentPic_YPan, m_CurrentPic_XPos, m_CurrentPic_YPos);
fb_display (m_CurrentPic_Buffer, m_CurrentPic_X, m_CurrentPic_Y, m_CurrentPic_XPan, m_CurrentPic_YPan, m_CurrentPic_XPos, m_CurrentPic_YPos);
//fb_display (m_CurrentPic_Buffer, m_CurrentPic_X, m_CurrentPic_Y, m_CurrentPic_XPan, m_CurrentPic_YPan, m_CurrentPic_XPos, m_CurrentPic_YPos);
CFrameBuffer::getInstance()->displayRGB(m_CurrentPic_Buffer, m_CurrentPic_X, m_CurrentPic_Y, m_CurrentPic_XPan, m_CurrentPic_YPan, m_CurrentPic_XPos, m_CurrentPic_YPos);
}
CPictureViewer::CPictureViewer ()
@@ -357,185 +348,177 @@ CPictureViewer::CPictureViewer ()
void CPictureViewer::showBusy (int sx, int sy, int width, char r, char g, char b)
{
// dbout("Show Busy{\n");
unsigned char rgb_buffer[3];
unsigned char *fb_buffer;
unsigned char *busy_buffer_wrk;
int cpp = 4;
struct fb_var_screeninfo *var;
var = CFrameBuffer::getInstance()->getScreenInfo ();
// dbout("Show Busy{\n");
unsigned char rgb_buffer[3];
unsigned char *fb_buffer;
unsigned char *busy_buffer_wrk;
int cpp = 4;
rgb_buffer[0] = r;
rgb_buffer[1] = g;
rgb_buffer[2] = b;
rgb_buffer[0] = r;
rgb_buffer[1] = g;
rgb_buffer[2] = b;
fb_buffer = (unsigned char *) convertRGB2FB (rgb_buffer, 1, 1);
if (fb_buffer == NULL) {
printf ("showBusy: Error: malloc 1\n");
return;
}
if (m_busy_buffer != NULL) {
free (m_busy_buffer);
m_busy_buffer = NULL;
}
m_busy_buffer = (unsigned char *) malloc (width * width * cpp);
if (m_busy_buffer == NULL) {
printf ("showBusy: Error: malloc 2: \n");
return;
}
busy_buffer_wrk = m_busy_buffer;
unsigned char *fb = (unsigned char *) CFrameBuffer::getInstance()->getFrameBufferPointer();
unsigned int stride = CFrameBuffer::getInstance ()->getStride ();
for (int y = sy; y < sy + width; y++) {
for (int x = sx; x < sx + width; x++) {
memcpy (busy_buffer_wrk, fb + y * stride + x * cpp, cpp);
busy_buffer_wrk += cpp;
memcpy (fb + y * stride + x * cpp, fb_buffer, cpp);
fb_buffer = (unsigned char *) CFrameBuffer::getInstance()->convertRGB2FB (rgb_buffer, 1, 1);
if (fb_buffer == NULL) {
printf ("showBusy: Error: malloc 1\n");
return;
}
}
m_busy_x = sx;
m_busy_y = sy;
m_busy_width = width;
m_busy_cpp = cpp;
free (fb_buffer);
// dbout("Show Busy}\n");
if (m_busy_buffer != NULL) {
free (m_busy_buffer);
m_busy_buffer = NULL;
}
m_busy_buffer = (unsigned char *) malloc (width * width * cpp);
if (m_busy_buffer == NULL) {
printf ("showBusy: Error: malloc 2: \n");
return;
}
busy_buffer_wrk = m_busy_buffer;
unsigned char *fb = (unsigned char *) CFrameBuffer::getInstance()->getFrameBufferPointer();
unsigned int stride = CFrameBuffer::getInstance ()->getStride ();
for (int y = sy; y < sy + width; y++) {
for (int x = sx; x < sx + width; x++) {
memcpy (busy_buffer_wrk, fb + y * stride + x * cpp, cpp);
busy_buffer_wrk += cpp;
memcpy (fb + y * stride + x * cpp, fb_buffer, cpp);
}
}
m_busy_x = sx;
m_busy_y = sy;
m_busy_width = width;
m_busy_cpp = cpp;
free (fb_buffer);
// dbout("Show Busy}\n");
}
void CPictureViewer::hideBusy ()
{
// dbout("Hide Busy{\n");
if (m_busy_buffer != NULL) {
unsigned char *fb = (unsigned char *) CFrameBuffer::getInstance ()->getFrameBufferPointer ();
unsigned int stride = CFrameBuffer::getInstance ()->getStride ();
unsigned char *busy_buffer_wrk = m_busy_buffer;
// dbout("Hide Busy{\n");
if (m_busy_buffer != NULL) {
unsigned char *fb = (unsigned char *) CFrameBuffer::getInstance ()->getFrameBufferPointer ();
unsigned int stride = CFrameBuffer::getInstance ()->getStride ();
unsigned char *busy_buffer_wrk = m_busy_buffer;
for (int y = m_busy_y; y < m_busy_y + m_busy_width; y++) {
for (int x = m_busy_x; x < m_busy_x + m_busy_width; x++) {
memcpy (fb + y * stride + x * m_busy_cpp, busy_buffer_wrk, m_busy_cpp);
busy_buffer_wrk += m_busy_cpp;
}
for (int y = m_busy_y; y < m_busy_y + m_busy_width; y++) {
for (int x = m_busy_x; x < m_busy_x + m_busy_width; x++) {
memcpy (fb + y * stride + x * m_busy_cpp, busy_buffer_wrk, m_busy_cpp);
busy_buffer_wrk += m_busy_cpp;
}
}
free (m_busy_buffer);
m_busy_buffer = NULL;
}
free (m_busy_buffer);
m_busy_buffer = NULL;
}
// dbout("Hide Busy}\n");
// dbout("Hide Busy}\n");
}
void CPictureViewer::Cleanup ()
{
if (m_busy_buffer != NULL) {
free (m_busy_buffer);
m_busy_buffer = NULL;
}
if (m_NextPic_Buffer != NULL) {
free (m_NextPic_Buffer);
m_NextPic_Buffer = NULL;
}
if (m_CurrentPic_Buffer != NULL) {
free (m_CurrentPic_Buffer);
m_CurrentPic_Buffer = NULL;
}
if (m_busy_buffer != NULL) {
free (m_busy_buffer);
m_busy_buffer = NULL;
}
if (m_NextPic_Buffer != NULL) {
free (m_NextPic_Buffer);
m_NextPic_Buffer = NULL;
}
if (m_CurrentPic_Buffer != NULL) {
free (m_CurrentPic_Buffer);
m_CurrentPic_Buffer = NULL;
}
}
void CPictureViewer::getSize(const char* name, int* width, int *height)
{
CFormathandler *fh;
fh = fh_getsize(name, width, height, INT_MAX, INT_MAX);
if (fh == NULL) {
*width = 0;
*height = 0;
}
}
#define LOGO_DIR1 "/share/tuxbox/neutrino/icons/logo"
#define LOGO_DIR2 "/var/share/icons/logo"
#define LOGO_FMT ".jpg"
bool CPictureViewer::GetLogoName(uint64_t channel_id, std::string ChannelName, std::string & name, int *width, int *height)
{
int i, j;
char strChanId[16];
sprintf(strChanId, "%llx", channel_id & 0xFFFFFFFFFFFFULL);
/* first the channel-id, then the channelname */
std::string strLogoName[2] = { (std::string)strChanId, ChannelName };
/* first jpg, then gif */
std::string strLogoExt[2] = { ".jpg", ".gif" };
for (i = 0; i < 2; i++)
{
for (j = 0; j < 2; j++)
{
std::string tmp(LOGO_DIR2 "/" + strLogoName[i] + strLogoExt[j]);
if (access(tmp.c_str(), R_OK) != -1)
{
if(width && height)
getSize(tmp.c_str(), width, height);
name = tmp;
return true;
}
}
}
for (i = 0; i < 2; i++)
{
for (j = 0; j < 2; j++)
{
std::string tmp(LOGO_DIR1 "/" + strLogoName[i] + strLogoExt[j]);
if (access(tmp.c_str(), R_OK) != -1)
{
if(width && height)
getSize(tmp.c_str(), width, height);
name = tmp;
return true;
}
}
}
return false;
}
bool CPictureViewer::DisplayLogo (uint64_t channel_id, int posx, int posy, int width, int height)
{
char fname[255];
char fname[255];
bool ret = false;
sprintf(fname, "%s/%llx.jpg", LOGO_DIR2, channel_id & 0xFFFFFFFFFFFFULL);
printf("logo file: %s\n", fname);
if(access(fname, F_OK))
sprintf(fname, "%s/%llx.gif", LOGO_DIR2, channel_id & 0xFFFFFFFFFFFFULL);
sprintf(fname, "%s/%llx.jpg", LOGO_DIR2, channel_id & 0xFFFFFFFFFFFFULL);
printf("logo file: %s\n", fname);
if(access(fname, F_OK))
sprintf(fname, "%s/%llx.gif", LOGO_DIR2, channel_id & 0xFFFFFFFFFFFFULL);
if(!access(fname, F_OK)) {
ret = DisplayImage(fname, posx, posy, width, height);
#if 0
//ret = DisplayImage(fname, posx, posy, width, height);
//fb_pixel_t * data = getImage(fname, width, height);
fb_pixel_t * data = getIcon(fname, &width, &height);
fb_pixel_t * data = getImage(fname, width, height);
//fb_pixel_t * data = getIcon(fname, &width, &height);
if(data) {
CFrameBuffer::getInstance()->blitToPrimary(data, posx, posy, width, height);
CFrameBuffer::getInstance()->blit2FB(data, width, height, posx, posy);
cs_free_uncached(data);
}
#endif
}
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;
CFormathandler *fh;
bool ret = false;
/* TODO: cache or check for same */
fb_pixel_t * data = getImage(name, width, height);
if (m_NextPic_Name != name || m_NextPic_X != width || m_NextPic_Y != height) {
fh = fh_getsize (name.c_str (), &x, &y, INT_MAX, INT_MAX);
if (fh) {
if (m_NextPic_Buffer != NULL)
free (m_NextPic_Buffer);
m_NextPic_Buffer = (unsigned char *) malloc (x * y * 3);
if (m_NextPic_Buffer == NULL) {
printf ("DisplayImage: Error: malloc\n");
return false;
}
if (fh->get_pic (name.c_str (), &m_NextPic_Buffer, &x, &y) == FH_ERROR_OK) {
//printf("DisplayImage: decoded %s, %d x %d to x=%d y=%d\n", name.c_str (), x, y, posx, posy);
//FIXME m_aspect_ratio_correction ?
if(width && height) {
if(x != width || y != height) {
printf("DisplayImage: resize %s, %d x %d to x=%d y=%d\n", name.c_str (), x, y, posx, posy);
//m_NextPic_Buffer = simple_resize (m_NextPic_Buffer, x, y, imx, imy);
m_NextPic_Buffer = color_average_resize (m_NextPic_Buffer, x, y, width, height);
x = width;
y = height;
}
posx += (width-x)/2;
posy += (height-y)/2;
}
//printf("DisplayImage: display %s, %d x %d to x=%d y=%d\n", name.c_str (), x, y, posx, posy);
fb_display (m_NextPic_Buffer, x, y, 0, 0, posx, posy, false, convertSetupAlpha2Alpha(g_settings.infobar_alpha));
m_NextPic_X = x;
m_NextPic_Y = y;
m_NextPic_Name = name;
ret = true;
} else {
printf ("Error decoding file %s\n", name.c_str ());
free (m_NextPic_Buffer);
m_NextPic_Buffer = NULL;
m_NextPic_Name = "";
}
} else {
printf("Error open file %s\n", name.c_str ());
}
} else if(m_NextPic_Buffer) {
m_NextPic_XPos = posx;
m_NextPic_YPos = posy;
fb_display (m_NextPic_Buffer, m_NextPic_X, m_NextPic_Y, 0, 0, m_NextPic_XPos, m_NextPic_YPos, false, convertSetupAlpha2Alpha(g_settings.infobar_alpha));
ret = true;
}
return ret;
if(data) {
CFrameBuffer::getInstance()->blit2FB(data, width, height, posx, posy);
cs_free_uncached(data);
return true;
}
return false;
}
fb_pixel_t * CPictureViewer::getImage (const std::string & name, int width, int height)
@@ -557,19 +540,19 @@ fb_pixel_t * CPictureViewer::getImage (const std::string & name, int width, int
printf("getImage: decoded %s, %d x %d \n", name.c_str (), x, y);
if(x != width || y != height)
{
buffer = color_average_resize (buffer, x, y, width, height);
printf("getImage: resize %s to %d x %d \n", name.c_str (), width, height);
buffer = Resize(buffer, x, y, width, height, COLOR);
x = width;
y = height;
}
struct fb_var_screeninfo *var = CFrameBuffer::getInstance()->getScreenInfo();
ret = (fb_pixel_t *) convertRGB2FB(buffer, x, y, 0);
ret = (fb_pixel_t *) CFrameBuffer::getInstance()->convertRGB2FB(buffer, x, y, convertSetupAlpha2Alpha(g_settings.infobar_alpha));
free(buffer);
} else {
printf ("Error decoding file %s\n", name.c_str ());
free (buffer);
buffer = NULL;
}
}
} else
printf("Error open file %s\n", name.c_str ());
return ret;
@@ -616,3 +599,70 @@ fb_pixel_t * CPictureViewer::getIcon (const std::string & name, int *width, int
return fbbuff;
}
unsigned char * CPictureViewer::Resize(unsigned char *orgin, int ox, int oy, int dx, int dy, ScalingMode type, unsigned char * dst)
{
unsigned char * cr;
if(dst == NULL) {
cr = (unsigned char*) malloc(dx*dy*3);
if(cr==NULL)
{
printf("Error: malloc\n");
return(orgin);
}
} else
cr = dst;
if(type == SIMPLE) {
unsigned char *p,*l;
int i,j,k,ip;
l=cr;
for(j=0;j<dy;j++,l+=dx*3)
{
p=orgin+(j*oy/dy*ox*3);
for(i=0,k=0;i<dx;i++,k+=3)
{
ip=i*ox/dx*3;
memcpy(l+k, p+ip, 3);
}
}
} else {
unsigned char *p,*q;
int i,j,k,l,ya,yb;
int sq,r,g,b;
p=cr;
int xa_v[dx];
for(i=0;i<dx;i++)
xa_v[i] = i*ox/dx;
int xb_v[dx+1];
for(i=0;i<dx;i++)
{
xb_v[i]= (i+1)*ox/dx;
if(xb_v[i]>=ox)
xb_v[i]=ox-1;
}
for(j=0;j<dy;j++)
{
ya= j*oy/dy;
yb= (j+1)*oy/dy; if(yb>=oy) yb=oy-1;
for(i=0;i<dx;i++,p+=3)
{
for(l=ya,r=0,g=0,b=0,sq=0;l<=yb;l++)
{
q=orgin+((l*ox+xa_v[i])*3);
for(k=xa_v[i];k<=xb_v[i];k++,q+=3,sq++)
{
r+=q[0]; g+=q[1]; b+=q[2];
}
}
p[0]=r/sq; p[1]=g/sq; p[2]=b/sq;
}
}
}
free(orgin);
return(cr);
}

View File

@@ -64,10 +64,11 @@ class CPictureViewer
static double m_aspect_ratio_correction;
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);
bool GetLogoName(uint64_t channel_id, std::string ChanName, std::string & name, int *width = NULL, int *height = NULL);
fb_pixel_t * getImage (const std::string & name, int width, int height);
fb_pixel_t * getIcon (const std::string & name, int *width, int *height);
int getWidth(const char *name);
int getHeight(const char *name);
void getSize(const char *name, int* width, int *height);
unsigned char * Resize(unsigned char *orgin, int ox, int oy, int dx, int dy, ScalingMode type, unsigned char * dst = NULL);
private:
CFormathandler *fh_root;

View File

@@ -30,7 +30,7 @@ unsigned char * simple_resize(unsigned char * orgin,int ox,int oy,int dx,int dy)
unsigned char * color_average_resize(unsigned char * orgin,int ox,int oy,int dx,int dy)
{
// dbout("color_average_resize{\n");
/* dbout("color_average_resize{\n");*/
unsigned char *cr,*p,*q;
int i,j,k,l,ya,yb;
int sq,r,g,b;
@@ -39,7 +39,7 @@ unsigned char * color_average_resize(unsigned char * orgin,int ox,int oy,int dx,
if(cr==NULL)
{
printf("Error: malloc\n");
// dbout("color_average_resize}\n");
/* dbout("color_average_resize}\n"); */
return(orgin);
}
p=cr;
@@ -72,6 +72,6 @@ unsigned char * color_average_resize(unsigned char * orgin,int ox,int oy,int dx,
}
}
free(orgin);
// dbout("color_average_resize}\n");
/* dbout("color_average_resize}\n"); */
return(cr);
}