trunk 20080912
[gitenigma.git] / lib / picviewer / pictureviewer.cpp
blob7ab23dad08be73c2c19399db75872f44a40f7d1d
1 /*
2 * $Id: pictureviewer.cpp,v 1.46 2008/01/19 16:46:53 dbluelle Exp $
4 * (C) 2005 by digi_casi <digi_casi@tuxbox.org>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #include <config.h>
23 #include <lib/driver/streamwd.h>
24 #include <lib/system/info.h>
25 #include <lib/system/init.h>
26 #include <lib/system/init_num.h>
27 #include <lib/system/econfig.h>
28 #include <lib/gdi/fb.h>
29 #include <lib/base/estring.h>
30 #include <lib/gui/actions.h>
31 #include <lib/gui/guiactions.h>
32 #include <lib/dvb/servicedvb.h>
33 #include <sys/types.h>
34 #include <sys/wait.h>
35 #include <sys/stat.h>
36 #include <stdio.h>
37 #include <unistd.h>
38 #include <errno.h>
39 #include <dirent.h>
40 #include <src/enigma_main.h>
41 #include <lib/gui/eskin.h>
42 #include <lib/gui/elabel.h>
43 #include <lib/gdi/font.h>
44 #include <lib/picviewer/pictureviewer.h>
45 #include "fb_display.h"
46 #include <lib/picviewer/format_config.h>
47 #include <lib/driver/eavswitch.h>
49 /* resize.cpp */
50 extern unsigned char *simple_resize(unsigned char *orgin, int ox, int oy, int dx, int dy);
51 extern unsigned char *color_average_resize(unsigned char *orgin, int ox, int oy, int dx, int dy);
53 #ifdef FBV_SUPPORT_GIF
54 extern int fh_gif_getsize(const char *, int *, int *, int, int);
55 extern int fh_gif_load(const char *, unsigned char *, int, int);
56 extern int fh_gif_id(const char *);
57 #endif
58 #ifdef FBV_SUPPORT_JPEG
59 extern int fh_jpeg_getsize(const char *, int *, int *, int, int);
60 extern int fh_jpeg_load(const char *, unsigned char *, int, int);
61 extern int fh_jpeg_id(const char *);
62 #endif
63 #ifdef FBV_SUPPORT_PNG
64 extern int fh_png_getsize(const char *, int *, int *, int, int);
65 extern int fh_png_load(const char *, unsigned char *, int, int);
66 extern int fh_png_id(const char *);
67 #endif
68 #ifdef FBV_SUPPORT_BMP
69 extern int fh_bmp_getsize(const char *, int *, int *, int, int);
70 extern int fh_bmp_load(const char *, unsigned char *, int, int);
71 extern int fh_bmp_id(const char *);
72 #endif
73 #ifdef FBV_SUPPORT_CRW
74 extern int fh_crw_getsize(const char *, int *, int *, int, int);
75 extern int fh_crw_load(const char *, unsigned char *, int, int);
76 extern int fh_crw_id(const char *);
77 #endif
79 void ePictureViewer::nextPicture()
81 if (++myIt == slideshowList.end())
82 myIt = slideshowList.begin();
85 void ePictureViewer::previousPicture()
87 if (myIt == slideshowList.begin())
89 myIt = slideshowList.end();
90 myIt--;
92 else
93 myIt--;
96 void ePictureViewer::showNameOnLCD(const eString& filename)
98 unsigned int pos = filename.find_last_of("/");
99 pos = (pos == eString::npos) ? 0 : pos + 1;
100 eString name = filename.substr(pos, filename.length() - 1);
101 #ifndef DISABLE_LCD
102 pLCD->lcdMain->ServiceName->setText(name);
103 pLCD->lcdMain->show();
104 #endif
107 ePictureViewer::ePictureViewer(const eString &filename)
108 :eWidget(0, 1), slideshowTimer(eApp), filename(filename)
110 // eDebug("[PICTUREVIEWER] Constructor...");
112 addActionMap(&i_cursorActions->map);
113 addActionMap(&i_shortcutActions->map);
114 addActionToHelpList(i_shortcutActions->blue.setDescription(_("display next picture")));
115 addActionToHelpList(i_shortcutActions->red.setDescription(_("display previous picture")));
116 addActionToHelpList(i_shortcutActions->green.setDescription(_("start slideshow")));
117 addActionToHelpList(i_shortcutActions->yellow.setDescription(_("stop slideshow")));
118 addActionToHelpList(i_shortcutActions->number0.setDescription(_("toggle fit to screen width/fit to screen")));
119 addActionToHelpList(i_shortcutActions->number1.setDescription(_("zoom out")));
120 addActionToHelpList(i_shortcutActions->number3.setDescription(_("zoom in")));
121 addActionToHelpList(i_shortcutActions->number5.setDescription(_("toggle 16/9 mode")));
122 addActionToHelpList(i_shortcutActions->number2.setDescription(_("move picture up")));
123 addActionToHelpList(i_shortcutActions->number4.setDescription(_("move picture left")));
124 addActionToHelpList(i_shortcutActions->number6.setDescription(_("move picture right")));
125 addActionToHelpList(i_shortcutActions->number8.setDescription(_("move picture down")));
127 move(ePoint(70, 50));
128 resize(eSize(590, 470));
129 eLabel *l = new eLabel(this);
130 l->move(ePoint(150, clientrect.height() / 2));
131 l->setFont(eSkin::getActive()->queryFont("epg.title"));
132 l->resize(eSize(clientrect.width() - 100, 30));
133 l->setText(_("Loading slide... please wait."));
135 #ifndef DISABLE_LCD
136 pLCD = eZapLCD::getInstance();
137 #endif
139 fh_root = NULL;
140 m_scaling = COLOR;
142 m_NextPic_Name = "";
143 m_NextPic_Buffer = NULL;
144 m_NextPic_X = 0;
145 m_NextPic_Y = 0;
146 m_NextPic_XPos = 0;
147 m_NextPic_YPos = 0;
148 m_NextPic_XPan = 0;
149 m_NextPic_YPan = 0;
150 m_bFitScreen = false;
152 m_startx = 20, m_starty = 20, m_endx = 699, m_endy = 555;
153 eConfig::getInstance()->getKey("/enigma/plugins/needoffsets/left", m_startx); // left
154 eConfig::getInstance()->getKey("/enigma/plugins/needoffsets/top", m_starty); // top
155 eConfig::getInstance()->getKey("/enigma/plugins/needoffsets/right", m_endx); // right
156 eConfig::getInstance()->getKey("/enigma/plugins/needoffsets/bottom", m_endy); // bottom
158 int showbusysign = 1;
159 eConfig::getInstance()->getKey("/picviewer/showbusysign", showbusysign);
160 showBusySign = (showbusysign == 1);
161 unsigned int v_pin8 = 0;
162 eConfig::getInstance()->getKey("/elitedvb/video/pin8", v_pin8);
163 switchto43 = false;
164 if ((v_pin8 == 3) || // always 16:9
165 ((v_pin8 > 1) && (eServiceInterface::getInstance()->getService()->getAspectRatio() == 1)))
167 m_aspect = 16.0 / 9;
169 else
171 m_aspect = 4.0 / 3;
172 switchto43 = true;
175 format169 = 0;
176 eConfig::getInstance()->getKey("/picviewer/format169", format169);
177 if (format169)
179 eAVSwitch::getInstance()->setAspectRatio(r169);
180 m_aspect = 16.0 / 9;
182 m_busy_buffer = NULL;
184 init_handlers();
186 CONNECT(slideshowTimer.timeout, ePictureViewer::slideshowTimeout);
187 // eDebug("[PICTUREVIEWER] Constructor done.");
190 ePictureViewer::~ePictureViewer()
192 if (m_busy_buffer != NULL)
194 delete [] m_busy_buffer;
195 m_busy_buffer = NULL;
197 if (m_NextPic_Buffer != NULL)
199 delete [] m_NextPic_Buffer;
200 m_NextPic_Buffer = NULL;
203 CFormathandler *tmp = NULL;
204 while(fh_root)
206 tmp = fh_root;
207 fh_root = fh_root->next;
208 delete tmp;
210 // restore original screen size
211 eStreamWatchdog::getInstance()->reloadSettings();
214 void ePictureViewer::add_format(int (*picsize)(const char *, int *, int *, int, int ), int (*picread)(const char *, unsigned char *, int, int), int (*id)(const char*))
216 CFormathandler *fhn;
217 fhn = new CFormathandler;
218 fhn->get_size = picsize;
219 fhn->get_pic = picread;
220 fhn->id_pic = id;
221 fhn->next = fh_root;
222 fh_root = fhn;
225 void ePictureViewer::init_handlers(void)
227 #ifdef FBV_SUPPORT_GIF
228 add_format(fh_gif_getsize, fh_gif_load, fh_gif_id);
229 #endif
230 #ifdef FBV_SUPPORT_JPEG
231 add_format(fh_jpeg_getsize, fh_jpeg_load, fh_jpeg_id);
232 #endif
233 #ifdef FBV_SUPPORT_PNG
234 add_format(fh_png_getsize, fh_png_load, fh_png_id);
235 #endif
236 #ifdef FBV_SUPPORT_BMP
237 add_format(fh_bmp_getsize, fh_bmp_load, fh_bmp_id);
238 #endif
239 #ifdef FBV_SUPPORT_CRW
240 add_format(fh_crw_getsize, fh_crw_load, fh_crw_id);
241 #endif
244 ePictureViewer::CFormathandler *ePictureViewer::fh_getsize(const char *name, int *x, int *y, int width_wanted, int height_wanted)
246 CFormathandler *fh;
247 for (fh = fh_root; fh != NULL; fh = fh->next)
249 if (fh->id_pic(name))
250 if (fh->get_size(name, x, y, width_wanted, height_wanted) == FH_ERROR_OK)
251 return(fh);
253 return(NULL);
256 bool ePictureViewer::DecodeImage(const std::string& name, bool unscaled)
258 // eDebug("DecodeImage {");
260 int x, y, xs, ys, imx, imy;
261 getCurrentRes(&xs, &ys);
263 // Show red block for "next ready" in view state
264 if (showBusySign)
265 showBusy(m_startx + 3, m_starty + 3, 10, 0xff, 0, 0);
267 CFormathandler *fh;
268 if (unscaled || m_bFitScreen)
269 fh = fh_getsize(name.c_str(), &x, &y, m_endx - m_startx, INT_MAX);
270 else
271 fh = fh_getsize(name.c_str(), &x, &y, m_endx - m_startx, m_endy - m_starty);
272 if (fh)
274 if (m_NextPic_Buffer != NULL)
276 delete [] m_NextPic_Buffer;
278 m_NextPic_Buffer = new unsigned char[x * y * 3];
279 if (m_NextPic_Buffer == NULL)
281 eDebug("Error: malloc");
282 return false;
285 // eDebug("---Decoding start(%d/%d)", x, y);
286 if (fh->get_pic(name.c_str(), m_NextPic_Buffer, x, y) == FH_ERROR_OK)
288 // eDebug("---Decoding done");
289 if (m_bFitScreen || (((x > (m_endx - m_startx)) || y > (m_endy - m_starty)) && m_scaling != NONE && !unscaled))
291 double aspect_ratio_correction = m_aspect / ((double)xs / ys);
292 if (m_bFitScreen || (aspect_ratio_correction * y * (m_endx - m_startx) / x) <= (m_endy - m_starty))
294 imx = (m_endx - m_startx);
295 imy = (int)(aspect_ratio_correction * y * (m_endx - m_startx) / x);
297 else
299 imx = (int)((1.0 / aspect_ratio_correction) * x * (m_endy - m_starty) / y);
300 imy = m_endy - m_starty;
302 if (m_scaling == SIMPLE)
303 m_NextPic_Buffer = simple_resize(m_NextPic_Buffer, x, y, imx, imy);
304 else
305 m_NextPic_Buffer = color_average_resize(m_NextPic_Buffer, x, y, imx, imy);
306 x = imx; y = imy;
308 m_NextPic_X = x;
309 m_NextPic_Y = y;
310 if (m_bFitScreen)
312 m_NextPic_XPos = m_startx;
313 m_NextPic_YPos = m_starty;
314 m_NextPic_XPan = 0;
315 m_NextPic_YPan = 0;
317 else
319 if (x < (m_endx - m_startx))
320 m_NextPic_XPos = (m_endx - m_startx - x) / 2 + m_startx;
321 else
322 m_NextPic_XPos = m_startx;
323 if (y < (m_endy - m_starty))
324 m_NextPic_YPos = (m_endy - m_starty-y) / 2 + m_starty;
325 else
326 m_NextPic_YPos = m_starty;
327 if (x > (m_endx - m_startx))
328 m_NextPic_XPan = (x - (m_endx - m_startx)) / 2;
329 else
330 m_NextPic_XPan = 0;
331 if (y > (m_endy - m_starty))
332 m_NextPic_YPan = (y - (m_endy - m_starty)) / 2;
333 else
334 m_NextPic_YPan = 0;
337 else
339 // eDebug("Unable to read file !");
340 delete [] m_NextPic_Buffer;
341 m_NextPic_Buffer = new unsigned char[3];
342 if (m_NextPic_Buffer == NULL)
344 eDebug("Error: malloc");
345 return false;
347 memset(m_NextPic_Buffer, 0 , 3);
348 m_NextPic_X = 1;
349 m_NextPic_Y = 1;
350 m_NextPic_XPos = 0;
351 m_NextPic_YPos = 0;
352 m_NextPic_XPan = 0;
353 m_NextPic_YPan = 0;
356 else
358 // eDebug("Unable to read file or format not recognized!");
359 if (m_NextPic_Buffer != NULL)
361 delete [] m_NextPic_Buffer;
363 m_NextPic_Buffer = new unsigned char[3];
364 if (m_NextPic_Buffer == NULL)
366 eDebug("Error: malloc");
367 return false;
369 memset(m_NextPic_Buffer, 0 , 3);
370 m_NextPic_X = 1;
371 m_NextPic_Y = 1;
372 m_NextPic_XPos = 0;
373 m_NextPic_YPos = 0;
374 m_NextPic_XPan = 0;
375 m_NextPic_YPan = 0;
377 m_NextPic_Name = name;
378 hideBusy();
379 // eDebug("DecodeImage }");
380 return(m_NextPic_Buffer != NULL);
383 bool ePictureViewer::ShowImage(const std::string& filename, bool unscaled)
385 // eDebug("Show Image {");
386 unsigned int pos = filename.find_last_of("/");
387 if (pos == eString::npos)
388 pos = filename.length() - 1;
389 eString directory = pos ? filename.substr(0, pos) : "";
390 // eDebug("---directory: %s", directory.c_str());
391 slideshowList.clear();
392 int includesubdirs = 0;
393 eConfig::getInstance()->getKey("/picviewer/includesubdirs", includesubdirs);
394 listDirectory(directory, includesubdirs);
395 for (myIt = slideshowList.begin(); myIt != slideshowList.end(); myIt++)
397 eString tmp = *myIt;
398 // eDebug("[PICTUREVIEWER] comparing: %s:%s", tmp.c_str(), filename.c_str());
399 if (tmp == filename)
400 break;
402 DecodeImage(filename, unscaled);
403 struct fb_var_screeninfo *screenInfo = fbClass::getInstance()->getScreenInfo();
404 if (screenInfo->bits_per_pixel != 16)
406 fbClass::getInstance()->lock();
407 fbClass::getInstance()->SetMode(720, 576, 16);
408 #if HAVE_DVB_API_VERSION == 3
409 fbClass::getInstance()->setTransparency(0);
410 #endif
412 #ifndef DISABLE_LCD
413 pLCD->lcdMenu->hide();
414 #endif
415 showNameOnLCD(filename);
416 DisplayNextImage();
417 // eDebug("Show Image }");
418 return true;
421 void ePictureViewer::slideshowTimeout()
423 eString tmp = *myIt;
424 // eDebug("[PICTUREVIEWER] slideshowTimeout: show %s", tmp.c_str());
425 DecodeImage(*myIt, false);
426 showNameOnLCD(tmp);
427 DisplayNextImage();
428 nextPicture();
429 int timeout = 5;
430 eConfig::getInstance()->getKey("/picviewer/slideshowtimeout", timeout);
431 slideshowTimer.start(timeout * 1000, true);
434 int ePictureViewer::eventHandler(const eWidgetEvent &evt)
436 static eString serviceName;
437 fflush(stdout);
438 switch(evt.type)
440 case eWidgetEvent::evtAction:
442 if (evt.action == &i_cursorActions->cancel)
443 close(0);
444 else
445 if (evt.action == &i_cursorActions->help)
447 fbClass::getInstance()->SetMode(720, 576, 8);
448 fbClass::getInstance()->PutCMAP();
449 fbClass::getInstance()->unlock();
450 eWidget::eventHandler(evt);
451 struct fb_var_screeninfo *screenInfo = fbClass::getInstance()->getScreenInfo();
452 if (screenInfo->bits_per_pixel != 16)
454 fbClass::getInstance()->lock();
455 fbClass::getInstance()->SetMode(720, 576, 16);
456 #if HAVE_DVB_API_VERSION == 3
457 fbClass::getInstance()->setTransparency(0);
458 #endif
460 DecodeImage(*myIt, false);
461 showNameOnLCD(*myIt);
462 DisplayNextImage();
463 return 1;
465 else
466 if (evt.action == &i_shortcutActions->yellow)
468 slideshowTimer.stop();
469 previousPicture();
471 if (evt.action == &i_shortcutActions->green)
473 nextPicture();
474 slideshowTimeout();
476 else
477 if (evt.action == &i_shortcutActions->number0)
479 // Toggle FitToScreenWidth mode
480 m_bFitScreen = !m_bFitScreen;
481 DecodeImage(*myIt, false);
482 DisplayNextImage();
484 else
485 if (evt.action == &i_shortcutActions->number1)
487 m_bFitScreen=false;
488 Zoom(2.0/3);
490 else
491 if (evt.action == &i_shortcutActions->number2)
493 Move(0,-50);
495 else
496 if (evt.action == &i_shortcutActions->number3)
498 Zoom(1.5);
500 else
501 if (evt.action == &i_shortcutActions->number4)
503 Move(-50,0);
505 else
506 if (evt.action == &i_shortcutActions->number5)
508 format169 = 1-format169;
509 eConfig::getInstance()->setKey("/picviewer/format169", format169);
510 if (format169)
512 m_aspect = 16.0 / 9;
513 eAVSwitch::getInstance()->setAspectRatio(r169);
515 else
517 m_aspect = 4.0 / 3;
518 eAVSwitch::getInstance()->setAspectRatio(r43);
521 else
522 if (evt.action == &i_shortcutActions->number6)
524 Move(50,0);
526 else
527 if (evt.action == &i_shortcutActions->number8)
529 Move(0,50);
531 else
532 if (evt.action == &i_cursorActions->down ||
533 evt.action == &i_cursorActions->right ||
534 evt.action == &i_shortcutActions->blue)
536 nextPicture();
537 DecodeImage(*myIt, false);
538 showNameOnLCD(*myIt);
539 DisplayNextImage();
541 else
542 if (evt.action == &i_cursorActions->up ||
543 evt.action == &i_cursorActions->left ||
544 evt.action == &i_shortcutActions->red)
546 previousPicture();
547 DecodeImage(*myIt, false);
548 showNameOnLCD(*myIt);
549 DisplayNextImage();
551 break;
553 case eWidgetEvent::execBegin:
555 #ifndef DISABLE_LCD
556 serviceName = pLCD->lcdMain->ServiceName->getText();
557 #endif
558 ShowImage(filename, false);
559 break;
561 case eWidgetEvent::execDone:
563 fbClass::getInstance()->SetMode(720, 576, 8);
564 fbClass::getInstance()->PutCMAP();
565 fbClass::getInstance()->unlock();
566 if (switchto43 && format169)
567 eAVSwitch::getInstance()->setAspectRatio(r43);
568 showNameOnLCD(serviceName);
569 #ifndef DISABLE_LCD
570 pLCD->lcdMain->hide();
571 pLCD->lcdMenu->show();
572 #endif
573 break;
575 default:
576 return eWidget::eventHandler(evt);
578 return 1;
581 void ePictureViewer::listDirectory(eString directory, int includesubdirs)
583 // eDebug("[PICTUREVIEWER] listDirectory: dir %s", directory.c_str());
584 std::list<eString> piclist;
585 std::list<eString>::iterator picIt;
586 std::list<eString> dirlist;
587 std::list<eString>::iterator dirIt;
588 piclist.clear();
589 dirlist.clear();
590 DIR *d = opendir(directory.c_str());
591 if (d)
593 while (struct dirent *e = readdir(d))
595 eString filename = eString(e->d_name);
596 // eDebug("[PICTUREVIEWER] listDirectory: processing %s", filename.c_str());
597 if ((filename != ".") && (filename != ".."))
599 struct stat s;
600 eString fullFilename = directory + "/" + filename;
601 if (lstat(fullFilename.c_str(), &s) < 0)
603 // eDebug("--- file no good :(");
604 continue;
607 if (S_ISREG(s.st_mode))
609 if (filename.right(4).upper() == ".JPG" ||
610 filename.right(5).upper() == ".JPEG" ||
611 filename.right(4).upper() == ".CRW" ||
612 filename.right(4).upper() == ".PNG" ||
613 filename.right(4).upper() == ".BMP" ||
614 filename.right(4).upper() == ".GIF")
616 eString tmp = directory + "/" + filename;
617 piclist.push_back(tmp);
620 else
621 if ((includesubdirs == 1) && (S_ISDIR(s.st_mode) || S_ISLNK(s.st_mode)))
623 eString tmp = directory + "/" + filename;
624 dirlist.push_back(tmp);
628 closedir(d);
630 if (!piclist.empty())
632 piclist.sort();
633 for (picIt = piclist.begin(); picIt != piclist.end(); picIt++)
635 eString tmp = *picIt;
636 slideshowList.push_back(tmp);
639 if (!dirlist.empty())
641 dirlist.sort();
642 for (dirIt = dirlist.begin(); dirIt != dirlist.end(); dirIt++)
644 eString tmp = *dirIt;
645 listDirectory(tmp, includesubdirs);
650 bool ePictureViewer::DisplayNextImage()
652 // eDebug("DisplayNextImage {");
653 if (m_NextPic_Buffer != NULL)
654 fb_display(m_NextPic_Buffer, m_NextPic_X, m_NextPic_Y, m_NextPic_XPan, m_NextPic_YPan, m_NextPic_XPos, m_NextPic_YPos);
655 // eDebug("DisplayNextImage }");
656 return true;
659 void ePictureViewer::Zoom(float factor)
661 // eDebug("Zoom %f {",factor);
662 showBusy(m_startx + 3, m_starty + 3, 10, 0xff, 0xff, 0);
664 int oldx = m_NextPic_X;
665 int oldy = m_NextPic_Y;
666 unsigned char *oldBuf = m_NextPic_Buffer;
667 m_NextPic_X = (int)(factor * m_NextPic_X);
668 m_NextPic_Y = (int)(factor * m_NextPic_Y);
670 if (m_scaling == COLOR)
671 m_NextPic_Buffer = color_average_resize(m_NextPic_Buffer, oldx, oldy, m_NextPic_X, m_NextPic_Y);
672 else
673 m_NextPic_Buffer = simple_resize(m_NextPic_Buffer, oldx, oldy, m_NextPic_X, m_NextPic_Y);
675 if (m_NextPic_Buffer == oldBuf)
677 // resize failed
678 hideBusy();
679 return;
682 if (m_NextPic_X < (m_endx - m_startx))
683 m_NextPic_XPos = (m_endx - m_startx - m_NextPic_X) / 2 + m_startx;
684 else
685 m_NextPic_XPos = m_startx;
686 if (m_NextPic_Y < (m_endy - m_starty))
687 m_NextPic_YPos = (m_endy - m_starty - m_NextPic_Y) / 2 + m_starty;
688 else
689 m_NextPic_YPos = m_starty;
690 if (m_NextPic_X > (m_endx - m_startx))
691 m_NextPic_XPan = (m_NextPic_X - (m_endx - m_startx)) / 2;
692 else
693 m_NextPic_XPan = 0;
694 if (m_NextPic_Y > (m_endy - m_starty))
695 m_NextPic_YPan = (m_NextPic_Y - (m_endy - m_starty)) / 2;
696 else
697 m_NextPic_YPan = 0;
698 fb_display(m_NextPic_Buffer, m_NextPic_X, m_NextPic_Y, m_NextPic_XPan, m_NextPic_YPan, m_NextPic_XPos, m_NextPic_YPos);
699 // eDebug("Zoom }");
701 void ePictureViewer::Move(int dx, int dy)
703 // eDebug("Move %d %d {", dx, dy);
704 showBusy(m_startx + 3, m_starty + 3, 10, 0, 0xff, 0);
706 int xs, ys;
707 getCurrentRes(&xs, &ys);
708 m_NextPic_XPan += dx;
709 if (m_NextPic_XPan + xs >= m_NextPic_X)
710 m_NextPic_XPan = m_NextPic_X - xs - 1;
711 if (m_NextPic_XPan < 0)
712 m_NextPic_XPan = 0;
714 m_NextPic_YPan += dy;
715 if (m_NextPic_YPan + ys >= m_NextPic_Y)
716 m_NextPic_YPan = m_NextPic_Y - ys - 1;
717 if(m_NextPic_YPan < 0)
718 m_NextPic_YPan = 0;
720 if (m_NextPic_X < (m_endx - m_startx))
721 m_NextPic_XPos = (m_endx - m_startx - m_NextPic_X) / 2 + m_startx;
722 else
723 m_NextPic_XPos = m_startx;
724 if (m_NextPic_Y < (m_endy - m_starty))
725 m_NextPic_YPos = (m_endy - m_starty - m_NextPic_Y) / 2 + m_starty;
726 else
727 m_NextPic_YPos = m_starty;
728 // dbout("Display x(%d) y(%d) xpan(%d) ypan(%d) xpos(%d) ypos(%d)\n",m_NextPic_X, m_NextPic_Y,
729 // m_NextPic_XPan, m_NextPic_YPan, m_NextPic_XPos, m_NextPic_YPos);
731 fb_display(m_NextPic_Buffer, m_NextPic_X, m_NextPic_Y, m_NextPic_XPan, m_NextPic_YPan, m_NextPic_XPos, m_NextPic_YPos);
732 // eDebug("Move }");
736 void ePictureViewer::showBusy(int sx, int sy, int width, char r, char g, char b)
738 // eDebug("Show Busy{");
740 unsigned char rgb_buffer[3];
741 unsigned char *fb_buffer=0;
742 unsigned char *busy_buffer_wrk;
743 int cpp;
744 struct fb_var_screeninfo *var = fbClass::getInstance()->getScreenInfo();
746 bool yuv_fb = eSystemInfo::getInstance()->getHwType() == eSystemInfo::DM600PVR && var->bits_per_pixel == 16;
748 rgb_buffer[0] = r;
749 rgb_buffer[1] = g;
750 rgb_buffer[2] = b;
752 if (!yuv_fb)
754 fb_buffer = (unsigned char *) convertRGB2FB(rgb_buffer, 1, var->bits_per_pixel, &cpp);
755 if (fb_buffer == NULL)
757 eDebug("Error: malloc");
758 return;
761 else
762 cpp=2;
764 if (m_busy_buffer != NULL)
766 delete [] m_busy_buffer;
767 m_busy_buffer = NULL;
769 m_busy_buffer = new unsigned char[width * width * cpp];
770 if (m_busy_buffer == NULL)
772 eDebug("Error: malloc");
773 return;
776 busy_buffer_wrk = m_busy_buffer;
777 unsigned char *fb = fbClass::getInstance()->lfb;
778 unsigned int stride = fbClass::getInstance()->Stride();
780 for (int y = sy ; y < sy + width; y++)
782 for(int x = sx ; x < sx + width; x++)
784 if (yuv_fb)
786 int offs = y * stride + x;
787 busy_buffer_wrk[0]=fb[offs]; // save old Y
788 busy_buffer_wrk[1]=fb[offs + 720 * 576]; // save old UV
789 fb[offs]=(lut_r_y[r] + lut_g_y[g] + lut_b_y[b]) >> 8;
790 if (x & 1)
791 fb[offs + 720 * 576]=((lut_r_v[r] + lut_g_v[g] + lut_b_v[b]) >> 8) + 128;
792 else
793 fb[offs + 720 * 576]=((lut_r_u[r] + lut_g_u[g] + lut_b_u[b]) >> 8) + 128;
795 else
797 memcpy(busy_buffer_wrk, fb + y * stride + x, cpp);
798 memcpy(fb + y * stride + x * cpp, fb_buffer, cpp);
800 busy_buffer_wrk += cpp;
804 m_busy_x = sx;
805 m_busy_y = sy;
806 m_busy_width = width;
807 m_busy_cpp = cpp;
808 delete [] fb_buffer;
809 // eDebug("Show Busy}");
812 void ePictureViewer::hideBusy()
814 //eDebug("Hide Busy {");
816 if (m_busy_buffer != NULL)
818 unsigned char *fb = fbClass::getInstance()->lfb;
819 unsigned int stride = fbClass::getInstance()->Stride();
820 unsigned char *busy_buffer_wrk = m_busy_buffer;
821 struct fb_var_screeninfo *var = fbClass::getInstance()->getScreenInfo();
822 bool yuv_fb = eSystemInfo::getInstance()->getHwType() == eSystemInfo::DM600PVR && var->bits_per_pixel == 16;
824 for (int y = m_busy_y; y < m_busy_y + m_busy_width; y++)
826 for (int x = m_busy_x; x < m_busy_x + m_busy_width; x++)
828 if (yuv_fb)
830 int offs = y * stride + x;
831 fb[offs]=*(busy_buffer_wrk++);
832 fb[offs + 720 * 576]=*(busy_buffer_wrk++);
834 else
836 memcpy(fb + y * stride + x, busy_buffer_wrk, m_busy_cpp);
837 busy_buffer_wrk += m_busy_cpp;
841 delete [] m_busy_buffer;
842 m_busy_buffer = NULL;
844 // eDebug("Hide Busy}");