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


Origin commit data
------------------
Commit: 3fb6607ba0
Author: [CST] Focus <focus.cst@gmail.com>
Date: 2010-02-05 (Fri, 05 Feb 2010)
This commit is contained in:
[CST] Focus
2010-02-05 15:26:57 +00:00
parent a8160d1e91
commit e7fb4b55fd
16 changed files with 498 additions and 405 deletions

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);
}