mirror of
https://github.com/tuxbox-neutrino/neutrino.git
synced 2025-08-26 15:02:56 +02:00
@@ -486,7 +486,6 @@ src/gui/lua/Makefile
|
||||
src/gui/moviebrowser/Makefile
|
||||
src/gui/widget/Makefile
|
||||
src/gui/widget/yaft/Makefile
|
||||
src/lcddisplay/Makefile
|
||||
src/nhttpd/Makefile
|
||||
src/nhttpd/tuxboxapi/Makefile
|
||||
src/nhttpd/yhttpd_core/Makefile
|
||||
|
@@ -1,10 +0,0 @@
|
||||
noinst_LIBRARIES = liblcddisplay.a
|
||||
|
||||
liblcddisplay_a_SOURCES = lcddisplay.cpp fontrenderer.cpp
|
||||
|
||||
AM_CPPFLAGS = \
|
||||
-I$(top_builddir)
|
||||
|
||||
AM_CXXFLAGS = \
|
||||
@FREETYPE_CFLAGS@ \
|
||||
@PNG_CFLAGS@
|
@@ -1,372 +0,0 @@
|
||||
/*
|
||||
$Header$
|
||||
|
||||
LCD-Daemon - DBoxII-Project
|
||||
|
||||
Copyright (C) 2001 Steffen Hehn 'McClean'
|
||||
Copyright (C) 2003 thegoodguy
|
||||
baseroutines by tmbinc
|
||||
|
||||
|
||||
License: GPL
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include "fontrenderer.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <ft2build.h>
|
||||
#include FT_FREETYPE_H
|
||||
|
||||
#ifdef ENABLE_FRIBIDI
|
||||
#include <fribidi/fribidi.h>
|
||||
#endif
|
||||
|
||||
FT_Error LcdFontRenderClass::myFTC_Face_Requester(FTC_FaceID face_id,
|
||||
FT_Library /*library*/,
|
||||
FT_Pointer request_data,
|
||||
FT_Face* aface)
|
||||
{
|
||||
return ((LcdFontRenderClass*)request_data)->FTC_Face_Requester(face_id, aface);
|
||||
}
|
||||
|
||||
|
||||
LcdFontRenderClass::LcdFontRenderClass(CLCDDisplay * fb)
|
||||
{
|
||||
framebuffer = fb;
|
||||
printf("[LCDFONT] initializing core...");
|
||||
fflush(stdout);
|
||||
if (FT_Init_FreeType(&library))
|
||||
{
|
||||
printf("failed.\n");
|
||||
return;
|
||||
}
|
||||
printf("\n");
|
||||
font=0;
|
||||
pthread_mutex_init(&render_mutex, NULL);
|
||||
}
|
||||
|
||||
LcdFontRenderClass::~LcdFontRenderClass()
|
||||
{
|
||||
FTC_Manager_Done(cacheManager);
|
||||
FT_Done_FreeType(library);
|
||||
}
|
||||
|
||||
void LcdFontRenderClass::InitFontCache()
|
||||
{
|
||||
printf("[LCDFONT] Intializing font cache...");
|
||||
fflush(stdout);
|
||||
if (FTC_Manager_New(library, 3, 0, 0, myFTC_Face_Requester, this, &cacheManager))
|
||||
{
|
||||
printf(" manager failed!\n");
|
||||
return;
|
||||
}
|
||||
if (!cacheManager)
|
||||
{
|
||||
printf(" error.\n");
|
||||
return;
|
||||
}
|
||||
if (FTC_SBitCache_New(cacheManager, &sbitsCache))
|
||||
{
|
||||
printf(" sbit failed!\n");
|
||||
return;
|
||||
}
|
||||
if (FTC_ImageCache_New(cacheManager, &imageCache))
|
||||
{
|
||||
printf(" imagecache failed!\n");
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
FT_Error LcdFontRenderClass::FTC_Face_Requester(FTC_FaceID face_id,
|
||||
FT_Face* aface)
|
||||
{
|
||||
fontListEntry *f=(fontListEntry *)face_id;
|
||||
if (!f)
|
||||
return -1;
|
||||
printf("[LCDFONT] FTC_Face_Requester (%s/%s)\n", f->family, f->style);
|
||||
|
||||
int error;
|
||||
if ((error=FT_New_Face(library, f->filename, 0, aface)))
|
||||
{
|
||||
printf(" failed: %i\n", error);
|
||||
return error;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
FTC_FaceID LcdFontRenderClass::getFaceID(const char *family, const char *style)
|
||||
{
|
||||
for (fontListEntry *f=font; f; f=f->next)
|
||||
{
|
||||
if ((!strcmp(f->family, family)) && (!strcmp(f->style, style)))
|
||||
return (FTC_FaceID)f;
|
||||
}
|
||||
for (fontListEntry *f=font; f; f=f->next)
|
||||
{
|
||||
if (!strcmp(f->family, family))
|
||||
return (FTC_FaceID)f;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
FT_Error LcdFontRenderClass::getGlyphBitmap(FTC_ImageType f, FT_ULong glyph_index, FTC_SBit *sbit)
|
||||
{
|
||||
return FTC_SBitCache_Lookup(sbitsCache, f, glyph_index, sbit, NULL);
|
||||
}
|
||||
|
||||
const char * LcdFontRenderClass::AddFont(const char * const filename)
|
||||
{
|
||||
printf("[LCDFONT] adding font %s...", filename);
|
||||
fflush(stdout);
|
||||
int error;
|
||||
fontListEntry *n=new fontListEntry;
|
||||
|
||||
FT_Face face;
|
||||
if ((error=FT_New_Face(library, filename, 0, &face)))
|
||||
{
|
||||
printf(" failed: %i\n", error);
|
||||
delete n;
|
||||
return NULL;
|
||||
}
|
||||
n->filename = strdup(filename);
|
||||
n->family = strdup(face->family_name);
|
||||
n->style = strdup(face->style_name);
|
||||
FT_Done_Face(face);
|
||||
|
||||
n->next=font;
|
||||
printf("OK (%s/%s)\n", n->family, n->style);
|
||||
font=n;
|
||||
return n->style;
|
||||
}
|
||||
|
||||
LcdFontRenderClass::fontListEntry::~fontListEntry()
|
||||
{
|
||||
free(filename);
|
||||
free(family);
|
||||
free(style);
|
||||
}
|
||||
|
||||
LcdFont *LcdFontRenderClass::getFont(const char *family, const char *style, int size)
|
||||
{
|
||||
FTC_FaceID id=getFaceID(family, style);
|
||||
if (!id)
|
||||
return 0;
|
||||
return new LcdFont(framebuffer, this, id, size);
|
||||
}
|
||||
|
||||
LcdFont::LcdFont(CLCDDisplay * fb, LcdFontRenderClass *render, FTC_FaceID faceid, int isize)
|
||||
{
|
||||
framebuffer=fb;
|
||||
renderer=render;
|
||||
font.face_id=faceid;
|
||||
font.width = isize;
|
||||
font.height = isize;
|
||||
font.flags = FT_LOAD_FORCE_AUTOHINT | FT_LOAD_MONOCHROME;
|
||||
}
|
||||
|
||||
FT_Error LcdFont::getGlyphBitmap(FT_ULong glyph_index, FTC_SBit *sbit)
|
||||
{
|
||||
return renderer->getGlyphBitmap(&font, glyph_index, sbit);
|
||||
}
|
||||
|
||||
extern int UTF8ToUnicode(const char * &text, const bool utf8_encoded); // returns -1 on error
|
||||
#if 0
|
||||
{
|
||||
int unicode_value;
|
||||
|
||||
if (utf8_encoded && ((((unsigned char)(*text)) & 0x80) != 0))
|
||||
{
|
||||
int remaining_unicode_length;
|
||||
if ((((unsigned char)(*text)) & 0xf8) == 0xf0)
|
||||
{
|
||||
unicode_value = ((unsigned char)(*text)) & 0x07;
|
||||
remaining_unicode_length = 3;
|
||||
}
|
||||
else if ((((unsigned char)(*text)) & 0xf0) == 0xe0)
|
||||
{
|
||||
unicode_value = ((unsigned char)(*text)) & 0x0f;
|
||||
remaining_unicode_length = 2;
|
||||
}
|
||||
else if ((((unsigned char)(*text)) & 0xe0) == 0xc0)
|
||||
{
|
||||
unicode_value = ((unsigned char)(*text)) & 0x1f;
|
||||
remaining_unicode_length = 1;
|
||||
}
|
||||
else // cf.: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
|
||||
return -1; // corrupted character or a character with > 4 bytes utf-8 representation
|
||||
|
||||
for (int i = 0; i < remaining_unicode_length; i++)
|
||||
{
|
||||
text++;
|
||||
if (((*text) & 0xc0) != 0x80)
|
||||
{
|
||||
remaining_unicode_length = -1;
|
||||
return -1; // incomplete or corrupted character
|
||||
}
|
||||
unicode_value <<= 6;
|
||||
unicode_value |= ((unsigned char)(*text)) & 0x3f;
|
||||
}
|
||||
if (remaining_unicode_length == -1)
|
||||
return -1; // incomplete or corrupted character
|
||||
}
|
||||
else
|
||||
unicode_value = (unsigned char)(*text);
|
||||
|
||||
return unicode_value;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_FRIBIDI
|
||||
std::string fribidi_shape_char(const char * text);
|
||||
#endif
|
||||
|
||||
void LcdFont::RenderString(int x, int y, const int width, const char * text, const int color, const int selected, const bool utf8_encoded)
|
||||
{
|
||||
int err;
|
||||
pthread_mutex_lock(&renderer->render_mutex);
|
||||
|
||||
#ifdef ENABLE_FRIBIDI
|
||||
std::string Text = fribidi_shape_char(text);
|
||||
text = Text.c_str();
|
||||
#endif
|
||||
|
||||
FTC_ScalerRec scaler;
|
||||
|
||||
scaler.face_id = font.face_id;
|
||||
scaler.width = font.width;
|
||||
scaler.height = font.height;
|
||||
scaler.pixel = true;
|
||||
|
||||
if ((err = FTC_Manager_LookupSize(renderer->cacheManager, &scaler, &size)) != 0)
|
||||
{
|
||||
printf("FTC_Manager_Lookup_Size failed! (%d)\n",err);
|
||||
pthread_mutex_unlock(&renderer->render_mutex);
|
||||
return;
|
||||
}
|
||||
int left=x, step_y=(size->metrics.height >> 6 )*3/4 + 4;
|
||||
|
||||
int pos =0;
|
||||
for (; *text; text++)
|
||||
{
|
||||
pos++;
|
||||
FTC_SBit glyph;
|
||||
//if ((x + size->metrics.x_ppem > (left+width)) || (*text=='\n'))
|
||||
if (x + size->metrics.x_ppem > (left+width))
|
||||
{ //width clip
|
||||
break;
|
||||
}
|
||||
if (*text=='\n')
|
||||
{
|
||||
x = left;
|
||||
y += step_y;
|
||||
}
|
||||
|
||||
int unicode_value = UTF8ToUnicode(text, utf8_encoded);
|
||||
|
||||
if (unicode_value == -1)
|
||||
break;
|
||||
|
||||
int index = FT_Get_Char_Index(size->face, unicode_value);
|
||||
|
||||
if (!index)
|
||||
continue;
|
||||
if (getGlyphBitmap(index, &glyph))
|
||||
{
|
||||
printf("failed to get glyph bitmap.\n");
|
||||
continue;
|
||||
}
|
||||
|
||||
int rx=x+glyph->left;
|
||||
int ry=y-glyph->top;
|
||||
if(pos==selected)
|
||||
{
|
||||
framebuffer->draw_fill_rect(x-2,y-glyph->height-2, x+glyph->width+2, y+2, CLCDDisplay::PIXEL_INV );
|
||||
}
|
||||
|
||||
for (int ay=0; ay<glyph->height; ay++)
|
||||
{
|
||||
int ax=0;
|
||||
int w=glyph->width;
|
||||
int xpos = rx;
|
||||
for (; ax<w; ax++)
|
||||
{
|
||||
unsigned char c = glyph->buffer[ay*abs(glyph->pitch)+(ax>>3)];
|
||||
if((c>>(7-(ax&7)))&1)
|
||||
framebuffer->draw_point(xpos,ry, color);
|
||||
xpos ++;
|
||||
}
|
||||
ry++;
|
||||
}
|
||||
|
||||
x+=glyph->xadvance+1;
|
||||
}
|
||||
pthread_mutex_unlock(&renderer->render_mutex);
|
||||
}
|
||||
|
||||
int LcdFont::getRenderWidth(const char * text, const bool utf8_encoded)
|
||||
{
|
||||
pthread_mutex_lock(&renderer->render_mutex);
|
||||
|
||||
#ifdef ENABLE_FRIBIDI
|
||||
std::string Text = fribidi_shape_char(text);
|
||||
text = Text.c_str();
|
||||
#endif
|
||||
|
||||
FT_Error err;
|
||||
FTC_ScalerRec scaler;
|
||||
scaler.face_id = font.face_id;
|
||||
scaler.width = font.width;
|
||||
scaler.height = font.height;
|
||||
scaler.pixel = true;
|
||||
|
||||
err = FTC_Manager_LookupSize(renderer->cacheManager, &scaler, &size);
|
||||
if (err != 0)
|
||||
{
|
||||
printf("FTC_Manager_Lookup_Size failed! (0x%x)\n", err);
|
||||
pthread_mutex_unlock(&renderer->render_mutex);
|
||||
return -1;
|
||||
}
|
||||
int x=0;
|
||||
for (; *text; text++)
|
||||
{
|
||||
FTC_SBit glyph;
|
||||
|
||||
int unicode_value = UTF8ToUnicode(text, utf8_encoded);
|
||||
|
||||
if (unicode_value == -1)
|
||||
break;
|
||||
|
||||
int index = FT_Get_Char_Index(size->face, unicode_value);
|
||||
|
||||
if (!index)
|
||||
continue;
|
||||
if (getGlyphBitmap(index, &glyph))
|
||||
{
|
||||
printf("failed to get glyph bitmap.\n");
|
||||
continue;
|
||||
}
|
||||
|
||||
x+=glyph->xadvance+1;
|
||||
}
|
||||
pthread_mutex_unlock(&renderer->render_mutex);
|
||||
return x;
|
||||
}
|
||||
|
@@ -1,115 +0,0 @@
|
||||
/*
|
||||
$Header$
|
||||
|
||||
LCD-Daemon - DBoxII-Project
|
||||
|
||||
Copyright (C) 2001 Steffen Hehn 'McClean'
|
||||
baseroutines by tmbinc
|
||||
Homepage: http://dbox.cyberphoria.org/
|
||||
|
||||
|
||||
|
||||
License: GPL
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#ifndef __LCDFONTRENDERER__
|
||||
#define __LCDFONTRENDERER__
|
||||
|
||||
#include "lcddisplay.h"
|
||||
|
||||
#include <ft2build.h>
|
||||
#include FT_FREETYPE_H
|
||||
#include FT_CACHE_H
|
||||
#include FT_CACHE_IMAGE_H
|
||||
#include FT_CACHE_SMALL_BITMAPS_H
|
||||
|
||||
#include <asm/types.h>
|
||||
|
||||
|
||||
|
||||
class LcdFontRenderClass;
|
||||
class LcdFont
|
||||
{
|
||||
CLCDDisplay *framebuffer;
|
||||
#if FREETYPE_MAJOR >= 2 && FREETYPE_MINOR >= 3
|
||||
FTC_ImageTypeRec font;
|
||||
#else
|
||||
FTC_Image_Desc font;
|
||||
FT_Face face;
|
||||
#endif
|
||||
LcdFontRenderClass *renderer;
|
||||
FT_Size size;
|
||||
|
||||
FT_Error getGlyphBitmap(FT_ULong glyph_index, FTC_SBit *sbit);
|
||||
|
||||
public:
|
||||
void RenderString(int x, int y, int width, const char *text, int color, int selected=0, const bool utf8_encoded = false);
|
||||
|
||||
int getRenderWidth(const char *text, const bool utf8_encoded = false);
|
||||
|
||||
LcdFont(CLCDDisplay *fb, LcdFontRenderClass *render, FTC_FaceID faceid, int isize);
|
||||
~LcdFont(){}
|
||||
};
|
||||
|
||||
|
||||
class LcdFontRenderClass
|
||||
{
|
||||
CLCDDisplay *framebuffer;
|
||||
|
||||
struct fontListEntry
|
||||
{
|
||||
char *filename, *style, *family;
|
||||
fontListEntry *next;
|
||||
~fontListEntry();
|
||||
} *font;
|
||||
|
||||
FT_Library library;
|
||||
FTC_Manager cacheManager; /* the cache manager */
|
||||
FTC_ImageCache imageCache; /* the glyph image cache */
|
||||
FTC_SBitCache sbitsCache; /* the glyph small bitmaps cache */
|
||||
|
||||
FTC_FaceID getFaceID(const char *family, const char *style);
|
||||
#if FREETYPE_MAJOR >= 2 && FREETYPE_MINOR >= 3
|
||||
FT_Error getGlyphBitmap(FTC_ImageType font, FT_ULong glyph_index, FTC_SBit *sbit);
|
||||
#else
|
||||
FT_Error getGlyphBitmap(FTC_Image_Desc *font, FT_ULong glyph_index, FTC_SBit *sbit);
|
||||
#endif
|
||||
|
||||
public:
|
||||
pthread_mutex_t render_mutex;
|
||||
const char * AddFont(const char * const filename);
|
||||
void InitFontCache();
|
||||
|
||||
FT_Error FTC_Face_Requester(FTC_FaceID face_id,
|
||||
FT_Face* aface);
|
||||
|
||||
|
||||
static FT_Error myFTC_Face_Requester(FTC_FaceID face_id,
|
||||
FT_Library library,
|
||||
FT_Pointer request_data,
|
||||
FT_Face* aface);
|
||||
|
||||
//FT_Face getFace(const char *family, const char *style);
|
||||
LcdFont *getFont(const char *family, const char *style, int size);
|
||||
LcdFontRenderClass(CLCDDisplay *fb);
|
||||
~LcdFontRenderClass();
|
||||
|
||||
|
||||
friend class LcdFont;
|
||||
};
|
||||
|
||||
#endif /* __LCDFONTRENDERER__ */
|
@@ -1,432 +0,0 @@
|
||||
/*
|
||||
LCD-Daemon - DBoxII-Project
|
||||
|
||||
Copyright (C) 2001 Steffen Hehn 'McClean'
|
||||
baseroutines by Shadow_
|
||||
Homepage: http://dbox.cyberphoria.org/
|
||||
|
||||
|
||||
|
||||
License: GPL
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
#include "lcddisplay.h"
|
||||
|
||||
#include <png.h>
|
||||
|
||||
#include <stdint.h> /* uint8_t */
|
||||
#include <fcntl.h>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <unistd.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
|
||||
CLCDDisplay::CLCDDisplay()
|
||||
{
|
||||
paused=0;
|
||||
available = false;
|
||||
#ifndef HAVE_GENERIC_HARDWARE
|
||||
//open device
|
||||
if ((fd = open(LCD_DEVICE, O_RDWR)) < 0)
|
||||
{
|
||||
perror("LCD (" LCD_DEVICE ")");
|
||||
return;
|
||||
}
|
||||
|
||||
//clear the display
|
||||
if ( ioctl(fd,LCD_IOCTL_CLEAR) < 0)
|
||||
{
|
||||
perror("clear failed");
|
||||
return;
|
||||
}
|
||||
|
||||
//graphic (binary) mode
|
||||
int i=LCD_MODE_BIN;
|
||||
if ( ioctl(fd,LCD_IOCTL_ASC_MODE,&i) < 0 )
|
||||
{
|
||||
perror("graphic mode failed");
|
||||
return;
|
||||
}
|
||||
|
||||
available = true;
|
||||
#endif
|
||||
iconBasePath = "";
|
||||
}
|
||||
|
||||
bool CLCDDisplay::isAvailable()
|
||||
{
|
||||
return available;
|
||||
}
|
||||
|
||||
CLCDDisplay::~CLCDDisplay()
|
||||
{
|
||||
close(fd);
|
||||
}
|
||||
|
||||
void CLCDDisplay::pause()
|
||||
{
|
||||
paused = 1;
|
||||
}
|
||||
|
||||
void CLCDDisplay::resume()
|
||||
{
|
||||
#ifndef HAVE_GENERIC_HARDWARE
|
||||
//clear the display
|
||||
if ( ioctl(fd,LCD_IOCTL_CLEAR) < 0)
|
||||
{
|
||||
perror("clear failed");
|
||||
return;
|
||||
}
|
||||
|
||||
//graphic (binary) mode
|
||||
int i=LCD_MODE_BIN;
|
||||
if ( ioctl(fd,LCD_IOCTL_ASC_MODE,&i) < 0 )
|
||||
{
|
||||
perror("graphic mode failed");
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
paused = 0;
|
||||
}
|
||||
|
||||
void CLCDDisplay::convert_data ()
|
||||
{
|
||||
#ifndef HAVE_GENERIC_HARDWARE
|
||||
unsigned int x, y, z;
|
||||
char tmp;
|
||||
|
||||
for (x = 0; x < LCD_COLS; x++)
|
||||
{
|
||||
for (y = 0; y < LCD_ROWS; y++)
|
||||
{
|
||||
tmp = 0;
|
||||
|
||||
for (z = 0; z < 8; z++)
|
||||
if (raw[y * 8 + z][x] == 1)
|
||||
tmp |= (1 << z);
|
||||
|
||||
lcd[y][x] = tmp;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void CLCDDisplay::update()
|
||||
{
|
||||
#ifndef HAVE_GENERIC_HARDWARE
|
||||
convert_data();
|
||||
if(paused || !available)
|
||||
return;
|
||||
else
|
||||
if ( write(fd, lcd, LCD_BUFFER_SIZE) < 0) {
|
||||
perror("lcdd: CLCDDisplay::update(): write()");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void CLCDDisplay::draw_point(const int x, const int y, const int state)
|
||||
{
|
||||
if ((x < 0) || (x >= LCD_COLS) || (y < 0) || (y >= (LCD_ROWS * 8)))
|
||||
return;
|
||||
|
||||
if (state == LCD_PIXEL_INV)
|
||||
raw[y][x] ^= 1;
|
||||
else
|
||||
raw[y][x] = state;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* draw_line
|
||||
*
|
||||
* args:
|
||||
* x1 StartCol
|
||||
* y1 StartRow
|
||||
* x2 EndCol
|
||||
* y1 EndRow
|
||||
* state LCD_PIXEL_OFF/LCD_PIXEL_ON/LCD_PIXEL_INV
|
||||
*
|
||||
*/
|
||||
void CLCDDisplay::draw_line(const int x1, const int y1, const int x2, const int y2, const int state)
|
||||
{
|
||||
int dx = abs (x1 - x2);
|
||||
int dy = abs (y1 - y2);
|
||||
int x;
|
||||
int y;
|
||||
int End;
|
||||
int step;
|
||||
|
||||
if ( dx > dy )
|
||||
{
|
||||
int p = 2 * dy - dx;
|
||||
int twoDy = 2 * dy;
|
||||
int twoDyDx = 2 * (dy-dx);
|
||||
|
||||
if ( x1 > x2 )
|
||||
{
|
||||
x = x2;
|
||||
y = y2;
|
||||
End = x1;
|
||||
step = y1 < y2 ? -1 : 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
x = x1;
|
||||
y = y1;
|
||||
End = x2;
|
||||
step = y2 < y1 ? -1 : 1;
|
||||
}
|
||||
|
||||
draw_point(x, y, state);
|
||||
|
||||
while( x < End )
|
||||
{
|
||||
x++;
|
||||
if ( p < 0 )
|
||||
p += twoDy;
|
||||
else
|
||||
{
|
||||
y += step;
|
||||
p += twoDyDx;
|
||||
}
|
||||
draw_point(x, y, state);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
int p = 2 * dx - dy;
|
||||
int twoDx = 2 * dx;
|
||||
int twoDxDy = 2 * (dx-dy);
|
||||
|
||||
if ( y1 > y2 )
|
||||
{
|
||||
x = x2;
|
||||
y = y2;
|
||||
End = y1;
|
||||
step = x1 < x2 ? -1 : 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
x = x1;
|
||||
y = y1;
|
||||
End = y2;
|
||||
step = x2 < x1 ? -1 : 1;
|
||||
}
|
||||
|
||||
draw_point(x, y, state);
|
||||
|
||||
while( y < End )
|
||||
{
|
||||
y++;
|
||||
if ( p < 0 )
|
||||
p += twoDx;
|
||||
else
|
||||
{
|
||||
x += step;
|
||||
p += twoDxDy;
|
||||
}
|
||||
draw_point(x, y, state);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void CLCDDisplay::draw_fill_rect (int left,int top,int right,int bottom,int state) {
|
||||
int x,y;
|
||||
for(x = left + 1;x < right;x++) {
|
||||
for(y = top + 1;y < bottom;y++) {
|
||||
draw_point(x,y,state);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void CLCDDisplay::draw_rectangle (int left,int top, int right, int bottom, int linestate,int fillstate)
|
||||
{
|
||||
// coordinate checking in draw_pixel (-> you can draw lines only
|
||||
// partly on screen)
|
||||
|
||||
draw_line(left,top,right,top,linestate);
|
||||
draw_line(left,top,left,bottom,linestate);
|
||||
draw_line(right,top,right,bottom,linestate);
|
||||
draw_line(left,bottom,right,bottom,linestate);
|
||||
draw_fill_rect(left,top,right,bottom,fillstate);
|
||||
}
|
||||
|
||||
|
||||
void CLCDDisplay::draw_polygon(int num_vertices, int *vertices, int state)
|
||||
{
|
||||
|
||||
// coordinate checking in draw_pixel (-> you can draw polygons only
|
||||
// partly on screen)
|
||||
|
||||
int i;
|
||||
for(i=0;i<num_vertices-1;i++) {
|
||||
draw_line(vertices[(i<<1)+0],
|
||||
vertices[(i<<1)+1],
|
||||
vertices[(i<<1)+2],
|
||||
vertices[(i<<1)+3],
|
||||
state);
|
||||
}
|
||||
|
||||
draw_line(vertices[0],
|
||||
vertices[1],
|
||||
vertices[(num_vertices<<1)-2],
|
||||
vertices[(num_vertices<<1)-1],
|
||||
state);
|
||||
}
|
||||
|
||||
|
||||
struct rawHeader
|
||||
{
|
||||
uint8_t width_lo;
|
||||
uint8_t width_hi;
|
||||
uint8_t height_lo;
|
||||
uint8_t height_hi;
|
||||
uint8_t transp;
|
||||
} __attribute__ ((packed));
|
||||
|
||||
bool CLCDDisplay::paintIcon(std::string filename, int x, int y, bool invert)
|
||||
{
|
||||
struct rawHeader header;
|
||||
uint16_t stride;
|
||||
uint16_t height;
|
||||
unsigned char * pixpos;
|
||||
|
||||
int _fd;
|
||||
filename = iconBasePath + filename;
|
||||
|
||||
_fd = open(filename.c_str(), O_RDONLY );
|
||||
|
||||
if (_fd==-1)
|
||||
{
|
||||
printf("\nerror while loading icon: %s\n\n", filename.c_str() );
|
||||
return false;
|
||||
}
|
||||
|
||||
read(_fd, &header, sizeof(struct rawHeader));
|
||||
|
||||
stride = ((header.width_hi << 8) | header.width_lo) >> 1;
|
||||
height = (header.height_hi << 8) | header.height_lo;
|
||||
|
||||
unsigned char pixbuf[200];
|
||||
while (height-- > 0)
|
||||
{
|
||||
read(fd, &pixbuf, stride);
|
||||
pixpos = (unsigned char*) &pixbuf;
|
||||
for (int count2 = 0; count2 < stride; count2++)
|
||||
{
|
||||
unsigned char compressed = *pixpos;
|
||||
|
||||
draw_point(x + (count2 << 1) , y, ((((compressed & 0xf0) >> 4) != header.transp) ^ invert) ? PIXEL_ON : PIXEL_OFF);
|
||||
draw_point(x + (count2 << 1) + 1, y, (( (compressed & 0x0f) != header.transp) ^ invert) ? PIXEL_ON : PIXEL_OFF);
|
||||
|
||||
pixpos++;
|
||||
}
|
||||
y++;
|
||||
}
|
||||
|
||||
close(_fd);
|
||||
return true;
|
||||
}
|
||||
|
||||
void CLCDDisplay::dump_screen(raw_display_t *screen) {
|
||||
memmove(screen, raw, sizeof(raw_display_t));
|
||||
}
|
||||
|
||||
void CLCDDisplay::load_screen(const raw_display_t * const screen) {
|
||||
memmove(raw, screen, sizeof(raw_display_t));
|
||||
}
|
||||
|
||||
bool CLCDDisplay::load_png(const char * const filename)
|
||||
{
|
||||
png_structp png_ptr;
|
||||
png_infop info_ptr;
|
||||
unsigned int i;
|
||||
unsigned int pass;
|
||||
unsigned int number_passes;
|
||||
int bit_depth;
|
||||
int color_type;
|
||||
int interlace_type;
|
||||
png_uint_32 width;
|
||||
png_uint_32 height;
|
||||
png_byte * fbptr;
|
||||
FILE * fh;
|
||||
bool ret_value = false;
|
||||
|
||||
if ((fh = fopen(filename, "rb")))
|
||||
{
|
||||
if ((png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL)))
|
||||
{
|
||||
if (!(info_ptr = png_create_info_struct(png_ptr)))
|
||||
png_destroy_read_struct(&png_ptr, (png_infopp)NULL, (png_infopp)NULL);
|
||||
else
|
||||
{
|
||||
#if (PNG_LIBPNG_VER < 10500)
|
||||
if (!(setjmp(png_ptr->jmpbuf)))
|
||||
#else
|
||||
if (!setjmp(png_jmpbuf(png_ptr)))
|
||||
#endif
|
||||
{
|
||||
png_init_io(png_ptr,fh);
|
||||
|
||||
png_read_info(png_ptr, info_ptr);
|
||||
png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, &interlace_type, NULL, NULL);
|
||||
|
||||
if (
|
||||
(color_type == PNG_COLOR_TYPE_PALETTE) &&
|
||||
(bit_depth == 1 ) &&
|
||||
(width <= LCD_COLS ) &&
|
||||
(height == (LCD_ROWS * 8))
|
||||
)
|
||||
{
|
||||
png_set_packing(png_ptr); /* expand to 1 byte blocks */
|
||||
|
||||
number_passes = png_set_interlace_handling(png_ptr);
|
||||
png_read_update_info(png_ptr,info_ptr);
|
||||
|
||||
if (width == png_get_rowbytes(png_ptr, info_ptr))
|
||||
{
|
||||
ret_value = true;
|
||||
|
||||
for (pass = 0; pass < number_passes; pass++)
|
||||
{
|
||||
fbptr = (png_byte *)raw;
|
||||
for (i = 0; i < height; i++, fbptr += LCD_COLS)
|
||||
{
|
||||
png_read_row(png_ptr, fbptr, NULL);
|
||||
/* if the PNG is smaller, than the display width... */
|
||||
if (width < LCD_COLS) /* clear the area right of the PNG */
|
||||
memset(fbptr + width, 0, LCD_COLS - width);
|
||||
}
|
||||
}
|
||||
png_read_end(png_ptr, info_ptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp)NULL);
|
||||
}
|
||||
}
|
||||
fclose(fh);
|
||||
}
|
||||
return ret_value;
|
||||
}
|
@@ -1,84 +0,0 @@
|
||||
#ifndef __lcddisplay__
|
||||
#define __lcddisplay__
|
||||
/*
|
||||
LCD-Daemon - DBoxII-Project
|
||||
|
||||
Copyright (C) 2001 Steffen Hehn 'McClean'
|
||||
baseroutines by Shadow_
|
||||
Homepage: http://dbox.cyberphoria.org/
|
||||
|
||||
|
||||
|
||||
License: GPL
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_GENERIC_HARDWARE
|
||||
// dummy
|
||||
#define LCD_ROWS 8
|
||||
#define LCD_COLS 120
|
||||
#define LCD_PIXEL_OFF 0
|
||||
#define LCD_PIXEL_ON 1
|
||||
#define LCD_PIXEL_INV 2
|
||||
#endif
|
||||
|
||||
#include <string>
|
||||
|
||||
typedef unsigned char raw_display_t[LCD_ROWS*8][LCD_COLS];
|
||||
|
||||
class CLCDDisplay
|
||||
{
|
||||
private:
|
||||
raw_display_t raw;
|
||||
unsigned char lcd[LCD_ROWS][LCD_COLS];
|
||||
int fd, paused;
|
||||
std::string iconBasePath;
|
||||
bool available;
|
||||
|
||||
public:
|
||||
enum
|
||||
{
|
||||
PIXEL_ON = LCD_PIXEL_ON,
|
||||
PIXEL_OFF = LCD_PIXEL_OFF,
|
||||
PIXEL_INV = LCD_PIXEL_INV
|
||||
};
|
||||
|
||||
CLCDDisplay();
|
||||
~CLCDDisplay();
|
||||
|
||||
void pause();
|
||||
void resume();
|
||||
|
||||
void convert_data();
|
||||
void setIconBasePath(std::string bp){iconBasePath=bp;};
|
||||
bool isAvailable();
|
||||
|
||||
void update();
|
||||
|
||||
void draw_point(const int x, const int y, const int state);
|
||||
void draw_line(const int x1, const int y1, const int x2, const int y2, const int state);
|
||||
void draw_fill_rect (int left,int top,int right,int bottom,int state);
|
||||
void draw_rectangle (int left,int top, int right, int bottom, int linestate,int fillstate);
|
||||
void draw_polygon(int num_vertices, int *vertices, int state);
|
||||
|
||||
bool paintIcon(std::string filename, int x, int y, bool invert);
|
||||
void dump_screen(raw_display_t *screen);
|
||||
void load_screen(const raw_display_t * const screen);
|
||||
bool load_png(const char * const filename);
|
||||
};
|
||||
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user