Testing GXA icon blit; Cleanup FB and pictureviwer code; This is work in progress, any bugs possible

git-svn-id: file:///home/bas/coolstream_public_svn/THIRDPARTY/applications/neutrino-experimental@258 e54a6e83-5905-42d5-8d5c-058d10e6a962
This commit is contained in:
focus
2010-02-04 20:18:42 +00:00
parent d974484c3e
commit 2f6462c65d
12 changed files with 319 additions and 524 deletions

View File

@@ -45,6 +45,7 @@
#include <global.h>
//#include <cnxtfb.h>
#include <video_cs.h>
#include <init_cs.h>
extern cVideo * videoDecoder;
extern CPictureViewer * g_PicViewer;
@@ -91,6 +92,9 @@ extern CPictureViewer * g_PicViewer;
#define GXA_CMD_NOT_TEXT 0x00018000
#define GXA_CMD_QMARK 0x00001000
#define GXA_BMP1_TYPE_REG 0x0048
#define GXA_BMP1_ADDR_REG 0x004C
/*
static unsigned int _read_gxa(volatile unsigned char *base_addr, unsigned int offset)
{
@@ -191,6 +195,8 @@ CFrameBuffer* CFrameBuffer::getInstance()
void CFrameBuffer::init(const char * const fbDevice)
{
int tr = 0xFF;
fd = open(fbDevice, O_RDWR);
if(!fd) fd = open(fbDevice, O_RDWR);
@@ -238,12 +244,36 @@ void CFrameBuffer::init(const char * const fbDevice)
/* tell the GXA where the framebuffer to draw on starts */
smem_start = (unsigned int) fix.smem_start;
printf("smem_start %x\n", smem_start);
_write_gxa(gxa_base, GXA_BMP2_TYPE_REG, (3 << 16) | screeninfo.xres);
_write_gxa(gxa_base, GXA_BMP2_ADDR_REG, (unsigned int) fix.smem_start);
_write_gxa(gxa_base, GXA_CONTENT_ID_REG, 0);
#endif
cache_size = 0;
/* Windows Colors */
paletteSetColor(0x1, 0x010101, tr);
paletteSetColor(0x2, 0x800000, tr);
paletteSetColor(0x3, 0x008000, tr);
paletteSetColor(0x4, 0x808000, tr);
paletteSetColor(0x5, 0x000080, tr);
paletteSetColor(0x6, 0x800080, tr);
paletteSetColor(0x7, 0x008080, tr);
paletteSetColor(0x8, 0xA0A0A0, tr);
paletteSetColor(0x9, 0x505050, tr);
paletteSetColor(0xA, 0xFF0000, tr);
paletteSetColor(0xB, 0x00FF00, tr);
paletteSetColor(0xC, 0xFFFF00, tr);
paletteSetColor(0xD, 0x0000FF, tr);
paletteSetColor(0xE, 0xFF00FF, tr);
paletteSetColor(0xF, 0x00FFFF, tr);
paletteSetColor(0x10, 0xFFFFFF, tr);
paletteSetColor(0x11, 0x000000, tr);
paletteSetColor(COL_BACKGROUND, 0x000000, 0xffff);
paletteSet();
useBackground(false);
#if 0
if ((tty=open("/dev/vc/0", O_RDWR))<0) {
perror("open (tty)");
@@ -900,6 +930,32 @@ bool CFrameBuffer::paintIcon8(const std::string & filename, const int x, const i
return true;
}
bool CFrameBuffer::blitToPrimary(unsigned int * data, int dx, int dy, int sw, int sh)
{
u32 cmd;
void * uKva;
#ifdef USE_NEVIS_GXA
uKva = cs_phys_addr(data);
printf("CFrameBuffer::blitToPrimary: data %x Kva %x\n", data, uKva);
if(uKva == NULL)
return false;
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) | sw);
_write_gxa(gxa_base, GXA_BMP1_ADDR_REG, (unsigned int) uKva);
_write_gxa(gxa_base, cmd, GXA_POINT(dx, dy)); /* destination pos */
_write_gxa(gxa_base, cmd, GXA_POINT(sw, sh)); /* source width */
_write_gxa(gxa_base, cmd, GXA_POINT(0, 0)); /* source pos */
return true;
#else
return false;
#endif
}
/* paint icon at position x/y,
if height h is given, center vertically between y and y+h
offset is a color offset (probably only useful with palette) */
@@ -956,7 +1012,8 @@ bool CFrameBuffer::paintIcon(const std::string & filename, const int x, const in
tmpIcon.height = height = (header.height_hi << 8) | header.height_lo;
dsize = width*height*sizeof(fb_pixel_t);
tmpIcon.data = (fb_pixel_t*) malloc(dsize);
tmpIcon.data = (fb_pixel_t*) cs_malloc_uncached(dsize);
data = tmpIcon.data;
unsigned char pixbuf[768];
@@ -997,6 +1054,9 @@ _display:
if (h != 0)
yy += (h - height) / 2;
if(blitToPrimary(data, x, y, width, height))
return true;
uint8_t * d = ((uint8_t *)getFrameBufferPointer()) + x * sizeof(fb_pixel_t) + stride * yy;
fb_pixel_t * d2;
@@ -1466,38 +1526,9 @@ void CFrameBuffer::switch_signal (int signal)
}
}
void CFrameBuffer::ClearFrameBuffer()
void CFrameBuffer::Clear()
{
int tr;
tr = 0xFF;
//paletteSetColor(0, 0xFFFFFF, 0xFF);
//Windows Colors
paletteSetColor(0x1, 0x010101, tr);
paletteSetColor(0x2, 0x800000, tr);
paletteSetColor(0x3, 0x008000, tr);
paletteSetColor(0x4, 0x808000, tr);
paletteSetColor(0x5, 0x000080, tr);
paletteSetColor(0x6, 0x800080, tr);
paletteSetColor(0x7, 0x008080, tr);
paletteSetColor(0x8, 0xA0A0A0, tr);
paletteSetColor(0x9, 0x505050, tr);
paletteSetColor(0xA, 0xFF0000, tr);
paletteSetColor(0xB, 0x00FF00, tr);
paletteSetColor(0xC, 0xFFFF00, tr);
paletteSetColor(0xD, 0x0000FF, tr);
paletteSetColor(0xE, 0xFF00FF, tr);
paletteSetColor(0xF, 0x00FFFF, tr);
paletteSetColor(0x10, 0xFFFFFF, tr);
paletteSetColor(0x11, 0x000000, tr);
useBackground(false);
paintBackground();
//background
paletteSetColor(COL_BACKGROUND, 0x000000, 0xffff);
paletteSet();
memset(getFrameBufferPointer(), 0, stride * yRes);
}
void CFrameBuffer::showFrame(const std::string & filename)

View File

@@ -116,9 +116,7 @@ class CFrameBuffer
int cache_size;
public:
#ifndef FB_USE_PALETTE
fb_pixel_t realcolor[256];
#endif
~CFrameBuffer();
@@ -156,11 +154,7 @@ class CFrameBuffer
//paint functions
inline void paintPixel(fb_pixel_t * const dest, const uint8_t color) const
{
#ifdef FB_USE_PALETTE
*dest = color;
#else
*dest = realcolor[color];
#endif
};
void paintPixel(int x, int y, const fb_pixel_t col);
@@ -209,7 +203,7 @@ class CFrameBuffer
void SaveScreen(int x, int y, int dx, int dy, fb_pixel_t * const memp);
void RestoreScreen(int x, int y, int dx, int dy, fb_pixel_t * const memp);
void ClearFrameBuffer();
void Clear();
void showFrame(const std::string & filename);
bool loadBackgroundPic(const std::string & filename, bool show = true);
bool Lock(void);
@@ -221,6 +215,7 @@ class CFrameBuffer
#else
inline void waitForIdle(void) {};
#endif
bool blitToPrimary(unsigned int * data, int dx, int dy, int sw, int sh);
};

View File

@@ -4,6 +4,7 @@ INCLUDES = \
-I$(top_srcdir)/src \
-I$(top_srcdir)/src/zapit/include \
-I$(top_srcdir)/lib/libconfigfile \
-I$(top_srcdir)/lib/libcoolstream \
@FREETYPE_CFLAGS@ \
-I$(top_srcdir)/lib

View File

@@ -1,3 +1,7 @@
/* FrameBuffer Image Display Function
* (c) smoku/2000
*/
#include <linux/fb.h>
#include <config.h>
@@ -14,336 +18,83 @@
#include "fb_display.h"
#include "pictureviewer.h"
#include "driver/framebuffer.h"
/*
* FrameBuffer Image Display Function
* (c) smoku/2000
*
*/
/* Public Use Functions:
*
* extern void fb_display(unsigned char *rgbbuff,
* int x_size, int y_size,
* int x_pan, int y_pan,
* int x_offs, int y_offs);
*
* extern void getCurrentRes(int *x,int *y);
*
*/
static unsigned short red[256], green[256], blue[256];
static struct fb_cmap map332 = {0, 256, red, green, blue, NULL};
//static unsigned short red_b[256], green_b[256], blue_b[256];
//static struct fb_cmap map_back = {0, 256, red_b, green_b, blue_b, NULL};
static unsigned char *lfb = 0;
int openFB(const char *name);
//void closeFB(int fh);
//void getVarScreenInfo(int fh, struct fb_var_screeninfo *var);
//void setVarScreenInfo(int fh, struct fb_var_screeninfo *var);
void getFixScreenInfo(struct fb_fix_screeninfo *fix);
void set332map();
void blit2FB(void *fbbuff,
unsigned int pic_xs, unsigned int pic_ys,
unsigned int scr_xs, unsigned int scr_ys,
unsigned int xp, unsigned int yp,
unsigned int xoffs, unsigned int yoffs,
int cpp);
void clearFB(int bpp,int cpp);
inline unsigned short make16color(uint32_t r, uint32_t g,
uint32_t b, uint32_t rl,
uint32_t ro, uint32_t gl,
uint32_t go, uint32_t bl,
uint32_t bo, uint32_t tl,
uint32_t to);
unsigned int xoffs, unsigned int yoffs);
void fb_display(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)
{
struct fb_var_screeninfo *var;
unsigned short *fbbuff = NULL;
int bp = 0;
if(rgbbuff==NULL)
return;
/* read current video mode */
var = CFrameBuffer::getInstance()->getScreenInfo();
lfb = (unsigned char *)CFrameBuffer::getInstance()->getFrameBufferPointer();
struct fb_var_screeninfo *var;
unsigned short *fbbuff = NULL;
/* correct panning */
if(x_pan > x_size - (int)var->xres) x_pan = 0;
if(y_pan > y_size - (int)var->yres) y_pan = 0;
/* correct offset */
if(x_offs + x_size > (int)var->xres) x_offs = 0;
if(y_offs + y_size > (int)var->yres) y_offs = 0;
if(rgbbuff == NULL)
return;
//printf("fb_display: bits_per_pixel: %d\n", var->bits_per_pixel);
//printf("fb_display: var->xres %d var->yres %d x_size %d y_size %d\n", var->xres, var->yres, x_size, y_size);
/* blit buffer 2 fb */
fbbuff = (unsigned short *) convertRGB2FB(rgbbuff, x_size, y_size, var->bits_per_pixel, &bp, transp);
if(fbbuff==NULL)
return;
/* ClearFB if image is smaller */
//if(x_size < (int)var->xres || y_size < (int)var->yres)
if(clearfb)
clearFB(var->bits_per_pixel, bp);
blit2FB(fbbuff, x_size, y_size, var->xres, var->yres, x_pan, y_pan, x_offs, y_offs, bp);
free(fbbuff);
}
/* read current video mode */
var = CFrameBuffer::getInstance()->getScreenInfo();
lfb = (unsigned char *)CFrameBuffer::getInstance()->getFrameBufferPointer();
void getCurrentRes(int *x, int *y)
{
struct fb_var_screeninfo *var;
var = CFrameBuffer::getInstance()->getScreenInfo();
*x = var->xres;
*y = var->yres;
//printf("getCurrentRes: %dx%d\n", var->xres, var->yres);
}
/* correct panning */
if(x_pan > x_size - (int)var->xres) x_pan = 0;
if(y_pan > y_size - (int)var->yres) y_pan = 0;
/* correct offset */
if(x_offs + x_size > (int)var->xres) x_offs = 0;
if(y_offs + y_size > (int)var->yres) y_offs = 0;
void make332map(struct fb_cmap *map)
{
int rs, gs, bs, i;
int r = 8, g = 8, b = 4;
/* blit buffer 2 fb */
fbbuff = (unsigned short *) convertRGB2FB(rgbbuff, x_size, y_size, transp);
if(fbbuff==NULL)
return;
map->red = red;
map->green = green;
map->blue = blue;
rs = 256 / (r - 1);
gs = 256 / (g - 1);
bs = 256 / (b - 1);
for (i = 0; i < 256; i++) {
map->red[i] = (rs * ((i / (g * b)) % r)) * 255;
map->green[i] = (gs * ((i / b) % g)) * 255;
map->blue[i] = (bs * ((i) % b)) * 255;
}
}
/*
void set8map(int fh, struct fb_cmap *map)
{
if (ioctl(fh, FBIOPUTCMAP, map) < 0) {
fprintf(stderr, "Error putting colormap");
exit(1);
}
}
void get8map(int fh, struct fb_cmap *map)
{
if (ioctl(fh, FBIOGETCMAP, map) < 0) {
fprintf(stderr, "Error getting colormap");
exit(1);
}
}
*/
void set332map()
{
make332map(&map332);
CFrameBuffer::getInstance()->paletteSet(&map332);
/* ClearFB if image is smaller */
//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);
}
void blit2FB(void *fbbuff,
unsigned int pic_xs, unsigned int pic_ys,
unsigned int scr_xs, unsigned int scr_ys,
unsigned int xp, unsigned int yp,
unsigned int xoffs, unsigned int yoffs,
int cpp)
unsigned int xoffs, unsigned int yoffs)
{
int i, xc, yc;
unsigned char *cp; unsigned short *sp; unsigned int *ip;
ip = (unsigned int *) fbbuff;
sp = (unsigned short *) ip;
cp = (unsigned char *) sp;
int i, xc, yc;
unsigned char *cp; unsigned short *sp; unsigned int *ip;
ip = (unsigned int *) fbbuff;
sp = (unsigned short *) ip;
cp = (unsigned char *) sp;
xc = (pic_xs > scr_xs) ? scr_xs : pic_xs;
yc = (pic_ys > scr_ys) ? scr_ys : pic_ys;
xc = (pic_xs > scr_xs) ? scr_xs : pic_xs;
yc = (pic_ys > scr_ys) ? scr_ys : pic_ys;
unsigned int stride = CFrameBuffer::getInstance()->getStride();
switch(cpp){
case 1:
set332map();
for(i = 0; i < yc; i++){
memcpy(lfb+(i+yoffs)*stride+xoffs*cpp, cp + (i+yp)*pic_xs+xp,xc*cpp);
}
break;
case 2:
for(i = 0; i < yc; i++){
memcpy(lfb+(i+yoffs)*stride+xoffs*cpp, sp + (i+yp)*pic_xs+xp, xc*cpp);
}
break;
case 4:
for(i = 0; i < yc; i++){
memcpy(lfb+(i+yoffs)*stride+xoffs*cpp, ip + (i+yp)*pic_xs+xp, xc*cpp);
}
break;
}
}
void clearFB(int /*bpp*/, int cpp)
{
int x,y;
getCurrentRes(&x,&y);
unsigned int stride = CFrameBuffer::getInstance()->getStride();
//printf("clearFB: stride %d y %d cpp %d bpp %d total %d\n", stride, y, cpp, bpp, stride*y*cpp);
switch(cpp){
case 2:
{
uint32_t rl, ro, gl, go, bl, bo, tl, to;
unsigned int i;
struct fb_var_screeninfo *var;
var = CFrameBuffer::getInstance()->getScreenInfo();
rl = (var->red).length;
ro = (var->red).offset;
gl = (var->green).length;
go = (var->green).offset;
bl = (var->blue).length;
bo = (var->blue).offset;
tl = (var->transp).length;
to = (var->transp).offset;
short black=make16color(0,0,0, rl, ro, gl, go, bl, bo, tl, to);
unsigned short *s_fbbuff = (unsigned short *) malloc(y*stride/2 * sizeof(unsigned short));
if(s_fbbuff==NULL)
{
printf("Error: malloc\n");
return;
}
for(i = 0; i < y*stride/2; i++)
s_fbbuff[i] = black;
memcpy(lfb, s_fbbuff, y*stride);
free(s_fbbuff);
}
break;
case 4:
{
uint32_t col = 0xFF000000;
uint32_t * dest = (uint32_t *) lfb;
for(unsigned int i = 0; i < stride*y/4; i ++)
dest[i] = col;
}
break;
default:
//memset(lfb, 0xFF, stride*y);
memset(lfb, 0, stride*y);
break;
for(i = 0; i < yc; i++){
memcpy(lfb+(i+yoffs)*stride+xoffs*4, ip + (i+yp)*pic_xs+xp, xc*4);
}
}
inline unsigned char make8color(unsigned char r, unsigned char g, unsigned char b)
void* convertRGB2FB(unsigned char *rgbbuff, unsigned long x, unsigned long y, int transp)
{
return (
(((r >> 5) & 7) << 5) |
(((g >> 5) & 7) << 2) |
((b >> 6) & 3) );
}
inline unsigned short make15color(unsigned char r, unsigned char g, unsigned char b)
{
return (
(((b >> 3) & 31) << 10) |
(((g >> 3) & 31) << 5) |
((r >> 3) & 31) );
}
inline unsigned short make16color(uint32_t r, uint32_t g, uint32_t b,
uint32_t rl, uint32_t ro,
uint32_t gl, uint32_t go,
uint32_t bl, uint32_t bo,
uint32_t /*tl*/, uint32_t /*to*/)
{
return (
// ((0xFF >> (8 - tl)) << to) |
((r >> (8 - rl)) << ro) |
((g >> (8 - gl)) << go) |
((b >> (8 - bl)) << bo));
}
void* convertRGB2FB(unsigned char *rgbbuff, unsigned long x, unsigned long y, int bpp, int *cpp, int transp)
{
unsigned long i;
void *fbbuff = NULL;
unsigned char *c_fbbuff;
unsigned short *s_fbbuff;
unsigned int *i_fbbuff;
unsigned long count = x*y;
uint32_t rl, ro, gl, go, bl, bo, tl, to;
struct fb_var_screeninfo *var;
var = CFrameBuffer::getInstance()->getScreenInfo();
rl = (var->red).length;
ro = (var->red).offset;
gl = (var->green).length;
go = (var->green).offset;
bl = (var->blue).length;
bo = (var->blue).offset;
tl = (var->transp).length;
to = (var->transp).offset;
switch(bpp)
{
case 8:
*cpp = 1;
c_fbbuff = (unsigned char *) malloc(count * sizeof(unsigned char));
if(c_fbbuff==NULL)
{
printf("Error: malloc\n");
return NULL;
}
for(i = 0; i < count; i++)
c_fbbuff[i] = make8color(rgbbuff[i*3], rgbbuff[i*3+1], rgbbuff[i*3+2]);
fbbuff = (void *) c_fbbuff;
break;
case 15:
*cpp = 2;
#if HAVE_DVB_API_VERSION < 3
s_fbbuff = (unsigned short *) malloc(count * sizeof(unsigned short));
if(s_fbbuff==NULL)
{
printf("Error: malloc\n");
return NULL;
}
for(i = 0; i < count ; i++)
s_fbbuff[i] = make15color(rgbbuff[i*3], rgbbuff[i*3+1], rgbbuff[i*3+2]);
#else
s_fbbuff = (unsigned short*) make15color_errdiff(rgbbuff, x, y);
#endif
fbbuff = (void *) s_fbbuff;
break;
case 16:
*cpp = 2;
#if HAVE_DVB_API_VERSION < 3
s_fbbuff = (unsigned short *) malloc(count * sizeof(unsigned short));
if(s_fbbuff==NULL)
{
printf("Error: malloc\n");
return NULL;
}
for(i = 0; i < count ; i++)
s_fbbuff[i]=make16color(rgbbuff[i*3], rgbbuff[i*3+1], rgbbuff[i*3+2], rl, ro, gl, go, bl, bo, tl, to);
#else
s_fbbuff = (unsigned short*) make15color_errdiff(rgbbuff, x, y);
#endif
fbbuff = (void *) s_fbbuff;
break;
case 24:
case 32:
*cpp = 4;
i_fbbuff = (unsigned int *) malloc(count * sizeof(unsigned int));
if(i_fbbuff==NULL)
{
printf("Error: malloc\n");
return NULL;
}
// red rgbbuff[i*3] green rgbbuff[i*3+1] blue rgbbuff[i*3+2]
for(i = 0; i < count ; i++)
i_fbbuff[i] = (transp << 24) | ((rgbbuff[i*3] << 16) & 0xFF0000) | ((rgbbuff[i*3+1] << 8) & 0xFF00) | (rgbbuff[i*3+2] & 0xFF);
//i_fbbuff[i] = (transp << 24) | ((rgbbuff[i*3+2] << 16) & 0xFF0000) | ((rgbbuff[i*3+1] << 8) & 0xFF00) | (rgbbuff[i*3] & 0xFF);
fbbuff = (void *) i_fbbuff;
break;
default:
fprintf(stderr, "Unsupported video mode! You've got: %dbpp\n", bpp);
exit(1);
}
return fbbuff;
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;
}

View File

@@ -1,6 +1,6 @@
#ifndef __pictureviewer_fbdisplay__
#define __pictureviewer_fbdisplay__
void* convertRGB2FB(unsigned char *rgbbuff, unsigned long x, unsigned long y, int bpp, int *cpp, int transp = 0xFF);
void* convertRGB2FB(unsigned char *rgbbuff, unsigned long x, unsigned long y, int transp = 0xFF);
extern void fb_display(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);
extern void getCurrentRes(int *x,int *y);
unsigned char * make15color_errdiff(unsigned char * orgin,int x, int y);

View File

@@ -10,6 +10,8 @@
#include <stdlib.h>
#include <sys/types.h>
#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);
@@ -86,107 +88,109 @@ CPictureViewer::CFormathandler * CPictureViewer::fh_getsize (const char *name, i
bool CPictureViewer::DecodeImage (const std::string & name, bool showBusySign, bool unscaled)
{
// dbout("DecodeImage {\n");
if (name == m_NextPic_Name) {
// dbout("DecodeImage }\n");
return true;
}
int x, y, xs, ys, imx, imy;
getCurrentRes (&xs, &ys);
// Show red block for "next ready" in view state
if (showBusySign)
showBusy (m_startx + 3, m_starty + 3, 10, 0xff, 00, 00);
CFormathandler *fh;
if (unscaled)
fh = fh_getsize (name.c_str (), &x, &y, INT_MAX, INT_MAX);
else
fh = fh_getsize (name.c_str (), &x, &y, m_endx - m_startx, m_endy - m_starty);
if (fh) {
if (m_NextPic_Buffer != NULL) {
free (m_NextPic_Buffer);
// dbout("DecodeImage {\n");
if (name == m_NextPic_Name) {
// dbout("DecodeImage }\n");
return true;
}
m_NextPic_Buffer = (unsigned char *) malloc (x * y * 3);
if (m_NextPic_Buffer == NULL) {
printf ("Error: malloc\n");
return false;
}
// dbout("---Decoding Start(%d/%d)\n",x,y);
if (fh->get_pic (name.c_str (), &m_NextPic_Buffer, &x, &y) == FH_ERROR_OK) {
// dbout("---Decoding Done\n");
if ((x > (m_endx - m_startx) || y > (m_endy - m_starty)) && m_scaling != NONE && !unscaled) {
if ((m_aspect_ratio_correction * y * (m_endx - m_startx) / x) <= (m_endy - m_starty)) {
imx = (m_endx - m_startx);
imy = (int) (m_aspect_ratio_correction * y * (m_endx - m_startx) / x);
} else {
imx = (int) ((1.0 / m_aspect_ratio_correction) * x * (m_endy - m_starty) / y);
imy = (m_endy - m_starty);
int x, y, xs, ys, imx, imy;
xs = CFrameBuffer::getInstance()->getScreenWidth(true);
ys = CFrameBuffer::getInstance()->getScreenHeight(true);
// Show red block for "next ready" in view state
if (showBusySign)
showBusy (m_startx + 3, m_starty + 3, 10, 0xff, 00, 00);
CFormathandler *fh;
if (unscaled)
fh = fh_getsize (name.c_str (), &x, &y, INT_MAX, INT_MAX);
else
fh = fh_getsize (name.c_str (), &x, &y, m_endx - m_startx, m_endy - m_starty);
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 ("DecodeImage: Error: malloc\n");
return false;
}
// dbout("---Decoding Start(%d/%d)\n",x,y);
if (fh->get_pic (name.c_str (), &m_NextPic_Buffer, &x, &y) == FH_ERROR_OK) {
// dbout("---Decoding Done\n");
if ((x > (m_endx - m_startx) || y > (m_endy - m_starty)) && m_scaling != NONE && !unscaled) {
if ((m_aspect_ratio_correction * y * (m_endx - m_startx) / x) <= (m_endy - m_starty)) {
imx = (m_endx - m_startx);
imy = (int) (m_aspect_ratio_correction * y * (m_endx - m_startx) / x);
} else {
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);
x = imx;
y = imy;
}
m_NextPic_X = x;
m_NextPic_Y = y;
if (x < (m_endx - m_startx))
m_NextPic_XPos = (m_endx - m_startx - x) / 2 + m_startx;
else
m_NextPic_XPos = m_startx;
if (y < (m_endy - m_starty))
m_NextPic_YPos = (m_endy - m_starty - y) / 2 + m_starty;
else
m_NextPic_YPos = m_starty;
if (x > (m_endx - m_startx))
m_NextPic_XPan = (x - (m_endx - m_startx)) / 2;
else
m_NextPic_XPan = 0;
if (y > (m_endy - m_starty))
m_NextPic_YPan = (y - (m_endy - m_starty)) / 2;
else
m_NextPic_YPan = 0;
} else {
printf ("Unable to read file !\n");
free (m_NextPic_Buffer);
m_NextPic_Buffer = (unsigned char *) malloc (3);
if (m_NextPic_Buffer == NULL) {
printf ("DecodeImage: Error: malloc\n");
return false;
}
memset (m_NextPic_Buffer, 0, 3);
m_NextPic_X = 1;
m_NextPic_Y = 1;
m_NextPic_XPos = 0;
m_NextPic_YPos = 0;
m_NextPic_XPan = 0;
m_NextPic_YPan = 0;
}
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);
x = imx;
y = imy;
}
m_NextPic_X = x;
m_NextPic_Y = y;
if (x < (m_endx - m_startx))
m_NextPic_XPos = (m_endx - m_startx - x) / 2 + m_startx;
else
m_NextPic_XPos = m_startx;
if (y < (m_endy - m_starty))
m_NextPic_YPos = (m_endy - m_starty - y) / 2 + m_starty;
else
m_NextPic_YPos = m_starty;
if (x > (m_endx - m_startx))
m_NextPic_XPan = (x - (m_endx - m_startx)) / 2;
else
m_NextPic_XPan = 0;
if (y > (m_endy - m_starty))
m_NextPic_YPan = (y - (m_endy - m_starty)) / 2;
else
m_NextPic_YPan = 0;
} else {
printf ("Unable to read file !\n");
free (m_NextPic_Buffer);
m_NextPic_Buffer = (unsigned char *) malloc (3);
if (m_NextPic_Buffer == NULL) {
printf ("Error: malloc\n");
return false;
}
memset (m_NextPic_Buffer, 0, 3);
m_NextPic_X = 1;
m_NextPic_Y = 1;
m_NextPic_XPos = 0;
m_NextPic_YPos = 0;
m_NextPic_XPan = 0;
m_NextPic_YPan = 0;
printf ("Unable to read file or format not recognized!\n");
if (m_NextPic_Buffer != NULL) {
free (m_NextPic_Buffer);
}
m_NextPic_Buffer = (unsigned char *) malloc (3);
if (m_NextPic_Buffer == NULL) {
printf ("DecodeImage: Error: malloc\n");
return false;
}
memset (m_NextPic_Buffer, 0, 3);
m_NextPic_X = 1;
m_NextPic_Y = 1;
m_NextPic_XPos = 0;
m_NextPic_YPos = 0;
m_NextPic_XPan = 0;
m_NextPic_YPan = 0;
}
} else {
printf ("Unable to read file or format not recognized!\n");
if (m_NextPic_Buffer != NULL) {
free (m_NextPic_Buffer);
}
m_NextPic_Buffer = (unsigned char *) malloc (3);
if (m_NextPic_Buffer == NULL) {
printf ("Error: malloc\n");
return false;
}
memset (m_NextPic_Buffer, 0, 3);
m_NextPic_X = 1;
m_NextPic_Y = 1;
m_NextPic_XPos = 0;
m_NextPic_YPos = 0;
m_NextPic_XPan = 0;
m_NextPic_YPan = 0;
}
m_NextPic_Name = name;
hideBusy ();
// dbout("DecodeImage }\n");
return (m_NextPic_Buffer != NULL);
m_NextPic_Name = name;
hideBusy ();
// dbout("DecodeImage }\n");
return (m_NextPic_Buffer != NULL);
}
void CPictureViewer::SetVisible (int startx, int endx, int starty, int endy)
@@ -278,70 +282,77 @@ void CPictureViewer::Zoom (float factor)
void CPictureViewer::Move (int dx, int dy)
{
// dbout("Move %d %d\n",dx,dy);
showBusy (m_startx + 3, m_starty + 3, 10, 0x00, 0xff, 00);
int xs, ys;
int xs, ys;
getCurrentRes (&xs, &ys);
m_CurrentPic_XPan += dx;
if (m_CurrentPic_XPan + xs >= m_CurrentPic_X)
m_CurrentPic_XPan = m_CurrentPic_X - xs - 1;
if (m_CurrentPic_XPan < 0)
m_CurrentPic_XPan = 0;
// dbout("Move %d %d\n",dx,dy);
showBusy (m_startx + 3, m_starty + 3, 10, 0x00, 0xff, 00);
m_CurrentPic_YPan += dy;
if (m_CurrentPic_YPan + ys >= m_CurrentPic_Y)
m_CurrentPic_YPan = m_CurrentPic_Y - ys - 1;
if (m_CurrentPic_YPan < 0)
m_CurrentPic_YPan = 0;
xs = CFrameBuffer::getInstance()->getScreenWidth(true);
ys = CFrameBuffer::getInstance()->getScreenHeight(true);
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;
// 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);
m_CurrentPic_XPan += dx;
if (m_CurrentPic_XPan + xs >= m_CurrentPic_X)
m_CurrentPic_XPan = m_CurrentPic_X - xs - 1;
if (m_CurrentPic_XPan < 0)
m_CurrentPic_XPan = 0;
fb_display (m_CurrentPic_Buffer, m_CurrentPic_X, m_CurrentPic_Y, m_CurrentPic_XPan, m_CurrentPic_YPan, m_CurrentPic_XPos, m_CurrentPic_YPos);
m_CurrentPic_YPan += dy;
if (m_CurrentPic_YPan + ys >= m_CurrentPic_Y)
m_CurrentPic_YPan = m_CurrentPic_Y - ys - 1;
if (m_CurrentPic_YPan < 0)
m_CurrentPic_YPan = 0;
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;
// 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);
}
CPictureViewer::CPictureViewer ()
{
fh_root = NULL;
m_scaling = COLOR;
//m_aspect = 4.0 / 3;
m_aspect = 16.0 / 9;
m_CurrentPic_Name = "";
m_CurrentPic_Buffer = NULL;
m_CurrentPic_X = 0;
m_CurrentPic_Y = 0;
m_CurrentPic_XPos = 0;
m_CurrentPic_YPos = 0;
m_CurrentPic_XPan = 0;
m_CurrentPic_YPan = 0;
m_NextPic_Name = "";
m_NextPic_Buffer = NULL;
m_NextPic_X = 0;
m_NextPic_Y = 0;
m_NextPic_XPos = 0;
m_NextPic_YPos = 0;
m_NextPic_XPan = 0;
m_NextPic_YPan = 0;
int xs, ys;
getCurrentRes (&xs, &ys);
m_startx = 0;
m_endx = xs - 1;
m_starty = 0;
m_endy = ys - 1;
m_aspect_ratio_correction = m_aspect / ((double) xs / ys);
int xs, ys;
m_busy_buffer = NULL;
fh_root = NULL;
m_scaling = COLOR;
//m_aspect = 4.0 / 3;
m_aspect = 16.0 / 9;
m_CurrentPic_Name = "";
m_CurrentPic_Buffer = NULL;
m_CurrentPic_X = 0;
m_CurrentPic_Y = 0;
m_CurrentPic_XPos = 0;
m_CurrentPic_YPos = 0;
m_CurrentPic_XPan = 0;
m_CurrentPic_YPan = 0;
m_NextPic_Name = "";
m_NextPic_Buffer = NULL;
m_NextPic_X = 0;
m_NextPic_Y = 0;
m_NextPic_XPos = 0;
m_NextPic_YPos = 0;
m_NextPic_XPan = 0;
m_NextPic_YPan = 0;
init_handlers ();
xs = CFrameBuffer::getInstance()->getScreenWidth(true);
ys = CFrameBuffer::getInstance()->getScreenHeight(true);
m_startx = 0;
m_endx = xs - 1;
m_starty = 0;
m_endy = ys - 1;
m_aspect_ratio_correction = m_aspect / ((double) xs / ys);
m_busy_buffer = NULL;
init_handlers ();
}
void CPictureViewer::showBusy (int sx, int sy, int width, char r, char g, char b)
@@ -350,17 +361,17 @@ void CPictureViewer::showBusy (int sx, int sy, int width, char r, char g, char b
unsigned char rgb_buffer[3];
unsigned char *fb_buffer;
unsigned char *busy_buffer_wrk;
int cpp;
int cpp = 4;
struct fb_var_screeninfo *var;
var = CFrameBuffer::getInstance ()->getScreenInfo ();
var = CFrameBuffer::getInstance()->getScreenInfo ();
rgb_buffer[0] = r;
rgb_buffer[1] = g;
rgb_buffer[2] = b;
fb_buffer = (unsigned char *) convertRGB2FB (rgb_buffer, 1, 1, var->bits_per_pixel, &cpp);
fb_buffer = (unsigned char *) convertRGB2FB (rgb_buffer, 1, 1);
if (fb_buffer == NULL) {
printf ("Error: malloc\n");
printf ("showBusy: Error: malloc 1\n");
return;
}
if (m_busy_buffer != NULL) {
@@ -369,11 +380,11 @@ void CPictureViewer::showBusy (int sx, int sy, int width, char r, char g, char b
}
m_busy_buffer = (unsigned char *) malloc (width * width * cpp);
if (m_busy_buffer == NULL) {
printf ("Error: malloc\n");
printf ("showBusy: Error: malloc 2: \n");
return;
}
busy_buffer_wrk = m_busy_buffer;
unsigned char *fb = (unsigned char *) CFrameBuffer::getInstance ()->getFrameBufferPointer ();
unsigned char *fb = (unsigned char *) CFrameBuffer::getInstance()->getFrameBufferPointer();
unsigned int stride = CFrameBuffer::getInstance ()->getStride ();
for (int y = sy; y < sy + width; y++) {
@@ -433,13 +444,21 @@ bool CPictureViewer::DisplayLogo (uint64_t channel_id, int posx, int posy, int w
{
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);
if(!access(fname, F_OK)) {
ret = DisplayImage(fname, posx, posy, width, height);
}
if(!access(fname, F_OK)) {
//ret = DisplayImage(fname, posx, posy, 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);
cs_free_uncached(data);
}
}
return ret;
}
@@ -471,8 +490,6 @@ bool CPictureViewer::DisplayImage (const std::string & name, int posx, int posy,
if (m_NextPic_Name != name || m_NextPic_X != width || m_NextPic_Y != height) {
//getCurrentRes (&xs, &ys);
fh = fh_getsize (name.c_str (), &x, &y, INT_MAX, INT_MAX);
if (fh) {
if (m_NextPic_Buffer != NULL)
@@ -480,7 +497,7 @@ bool CPictureViewer::DisplayImage (const std::string & name, int posx, int posy,
m_NextPic_Buffer = (unsigned char *) malloc (x * y * 3);
if (m_NextPic_Buffer == NULL) {
printf ("Error: malloc\n");
printf ("DisplayImage: Error: malloc\n");
return false;
}
if (fh->get_pic (name.c_str (), &m_NextPic_Buffer, &x, &y) == FH_ERROR_OK) {
@@ -488,6 +505,7 @@ bool CPictureViewer::DisplayImage (const std::string & name, int posx, int 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;
@@ -532,7 +550,7 @@ fb_pixel_t * CPictureViewer::getImage (const std::string & name, int width, int
buffer = (unsigned char *) malloc (x * y * 3);
if (buffer == NULL) {
printf ("Error: malloc\n");
printf ("getImage: Error: malloc\n");
return false;
}
if (fh->get_pic (name.c_str (), &buffer, &x, &y) == FH_ERROR_OK) {
@@ -544,8 +562,7 @@ printf("getImage: decoded %s, %d x %d \n", name.c_str (), x, y);
y = height;
}
struct fb_var_screeninfo *var = CFrameBuffer::getInstance()->getScreenInfo();
int bp;
ret = (fb_pixel_t *) convertRGB2FB(buffer, x, y, var->bits_per_pixel, &bp, 0);
ret = (fb_pixel_t *) convertRGB2FB(buffer, x, y, 0);
free(buffer);
} else {
printf ("Error decoding file %s\n", name.c_str ());
@@ -571,12 +588,14 @@ fb_pixel_t * CPictureViewer::getIcon (const std::string & name, int *width, int
}
rgbbuff = (unsigned char *) malloc (x * y * 3);
if (rgbbuff == NULL) {
printf ("Error: malloc\n");
printf ("getIcon: Error: malloc\n");
return NULL;
}
if (fh->get_pic (name.c_str (), &rgbbuff, &x, &y) == FH_ERROR_OK) {
int count = x*y;
fbbuff = (fb_pixel_t *) malloc(count * sizeof(fb_pixel_t));
//fbbuff = (fb_pixel_t *) malloc(count * sizeof(fb_pixel_t));
fbbuff = (fb_pixel_t *) cs_malloc_uncached(count * sizeof(fb_pixel_t));
//printf("getIcon: decoded %s, %d x %d buf %x\n", name.c_str (), x, y, fbbuff);
for(int i = 0; i < count ; i++) {