Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of TFTLCD by
Revision 13:5ceeba86bbe4, committed 2012-12-11
- Comitter:
- ttodorov
- Date:
- Tue Dec 11 20:02:48 2012 +0000
- Parent:
- 12:d0978272a340
- Child:
- 14:8efbe7361dae
- Commit message:
- - completed the rework of bitmap drawing functions
Changed in this revision
| lcd_base.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/lcd_base.cpp Tue Dec 11 18:11:14 2012 +0000
+++ b/lcd_base.cpp Tue Dec 11 20:02:48 2012 +0000
@@ -333,19 +333,32 @@
if ( scale == 1 )
{
SetXY( x, y, x + img->Width - 1, y + img->Height - 1 );
-
- if ( _colorDepth == RGB16 )
+
+ if ( img->Format == RGB16 )
{
- if ( img->Format == RGB16 )
- {
- const unsigned short *pixel = (const unsigned short*) img->PixelData;
+ const unsigned short *pixel = ( const unsigned short* ) img->PixelData;
+ if ( _colorDepth == RGB16 )
for ( tc = 0; tc < ( img->Width * img->Height ); tc++ )
WriteData( *pixel++ );
- }
- else // img RGB18
+ else if ( _colorDepth == RGB18 )
{
- unsigned char r, g, b;
- const unsigned int *pixel = (const unsigned int*) img->PixelData;
+ unsigned short r, g, b;
+ for ( tc = 0; tc < ( img->Width * img->Height ); tc++ )
+ {
+ r = ( *pixel & 0xF800 ) >> 8;
+ g = ( *pixel & 0x07E0 ) >> 3;
+ b = ( *pixel & 0x001F ) << 3;
+ pixel++;
+ SetPixelColor( RGB( r, g, b ) );
+ }
+ }
+ }
+ else if ( img->Format == RGB18 )
+ {
+ const unsigned int *pixel = ( const unsigned int* ) img->PixelData;
+ if ( _colorDepth == RGB16 )
+ {
+ unsigned short r, g, b;
for ( tc = 0; tc < ( img->Width * img->Height ); tc++ )
{
r = ( *pixel >> 16 ) & 0xF8;
@@ -354,72 +367,69 @@
WriteData( ( r << 8 ) | ( g >> 5 ) | ( g << 3 ) | b );
}
}
- }
- else // color depth RGB18
- {
- unsigned short r, g, b, leftover = 0;
- bool hasNext = false;
- if ( img->Format == RGB16 )
- {
- const unsigned short *pixel = (const unsigned short*) img->PixelData;
+ else if ( _colorDepth == RGB18 )
for ( tc = 0; tc < ( img->Width * img->Height ); tc++ )
- {
- r = ( *pixel & 0xF800 ) >> 8;
- g = ( *pixel & 0x07E0 ) >> 3;
- b = ( *pixel & 0x001F ) << 3;
- pixel++;
- if ( hasNext )
- {
- WriteData( ( leftover << 8 ) | r );
- WriteData( ( g << 8 ) | b );
- hasNext = false;
- }
- else
- {
- WriteData( ( r << 8 ) | g );
- leftover = b;
- hasNext = true;
- }
- }
- }
- else // img RGB18
- {
- const unsigned int *pixel = (const unsigned int*) img->PixelData;
- for ( tc = 0; tc < ( img->Width * img->Height ); tc++ )
- {
SetPixelColor( *pixel++ );
- }
- }
}
}
else
{
- /*
- if ( _orientation == PORTRAIT )
+ if ( img->Format == RGB16 )
{
- for ( ty = 0; ty < sy; ty++ )
+ const unsigned short *pixel = ( const unsigned short* ) img->PixelData;
+ unsigned short r, g, b;
+
+ for ( ty = 0; ty < img->Height; ty++ )
{
- SetXY( x, y + ( ty * scale ), x + ( ( sx * scale ) - 1 ), y + ( ty * scale ) + scale );
- for ( tsy = 0; tsy < scale; tsy++ )
- for ( tx = 0; tx < sx; tx++ )
- for ( tsx = 0; tsx < scale; tsx++ )
- WriteData( imgPixelData[ ( ty * sx ) + tx ] );
- }
- }
- else
- {
- for ( ty = 0; ty < sy; ty++ )
- {
+ SetXY( x, y + ( ty * scale ), x + ( ( img->Width * scale ) - 1 ), y + ( ty * scale ) + scale );
for ( tsy = 0; tsy < scale; tsy++ )
{
- SetXY( x, y + ( ty * scale ) + tsy, x + ( ( sx * scale ) - 1 ), y + ( ty * scale ) + tsy );
- for ( tx = sx; tx >= 0; tx-- )
+ for ( tx = 0; tx < img->Width; tx++ )
+ {
for ( tsx = 0; tsx < scale; tsx++ )
- WriteData( imgPixelData[ ( ty * sx ) + tx ] );
+ {
+ if ( _colorDepth == RGB16 )
+ WriteData( pixel[ ( ty * img->Width ) + tx ] );
+ else if ( _colorDepth == RGB18 )
+ {
+ r = ( pixel[ ( ty * img->Width ) + tx ] & 0xF800 ) >> 8;
+ g = ( pixel[ ( ty * img->Width ) + tx ] & 0x07E0 ) >> 3;
+ b = ( pixel[ ( ty * img->Width ) + tx ] & 0x001F ) << 3;
+ SetPixelColor( RGB( r, g, b ) );
+ }
+ }
+ }
}
}
}
- */
+ else if ( img->Format == RGB18 )
+ {
+ const unsigned int *pixel = ( const unsigned int* ) img->PixelData;
+ unsigned short r, g, b;
+
+ for ( ty = 0; ty < img->Height; ty++ )
+ {
+ SetXY( x, y + ( ty * scale ), x + ( ( img->Width * scale ) - 1 ), y + ( ty * scale ) + scale );
+ for ( tsy = 0; tsy < scale; tsy++ )
+ {
+ for ( tx = 0; tx < img->Width; tx++ )
+ {
+ for ( tsx = 0; tsx < scale; tsx++ )
+ {
+ if ( _colorDepth == RGB16 )
+ {
+ r = ( pixel[ ( ty * img->Width ) + tx ] >> 16 ) & 0xF8;
+ g = ( pixel[ ( ty * img->Width ) + tx ] >> 8 ) & 0xFC;
+ b = ( pixel[ ( ty * img->Width ) + tx ] & 0xF8 ) >> 3;
+ WriteData( ( r << 8 ) | ( g >> 5 ) | ( g << 3 ) | b );
+ }
+ else if ( _colorDepth == RGB18 )
+ SetPixelColor( pixel[ ( ty * img->Width ) + tx ] );
+ }
+ }
+ }
+ }
+ }
}
Deactivate();
}
@@ -435,15 +445,53 @@
else
{
Activate();
- for ( ty = 0; ty < img->Height; ty++ )
- for ( tx = 0; tx < img->Width; tx++ )
- {
- newx = x + rox + ( ( ( tx - rox ) * cos( radian ) ) - ( ( ty - roy ) * sin( radian ) ) );
- newy = y + roy + ( ( ( ty - roy ) * cos( radian ) ) + ( ( tx - rox ) * sin( radian ) ) );
-
- SetXY( newx, newy, newx, newy );
- //WriteData( imgPixelData[ ( ty * sx ) + tx ] );
- }
+
+ if ( img->Format == RGB16 )
+ {
+ const unsigned short *pixel = ( const unsigned short* ) img->PixelData;
+ unsigned short r, g, b;
+
+ for ( ty = 0; ty < img->Height; ty++ )
+ for ( tx = 0; tx < img->Width; tx++ )
+ {
+ newx = x + rox + ( ( ( tx - rox ) * cos( radian ) ) - ( ( ty - roy ) * sin( radian ) ) );
+ newy = y + roy + ( ( ( ty - roy ) * cos( radian ) ) + ( ( tx - rox ) * sin( radian ) ) );
+
+ SetXY( newx, newy, newx, newy );
+ if ( _colorDepth == RGB16 )
+ WriteData( pixel[ ( ty * img->Width ) + tx ] );
+ else if ( _colorDepth == RGB18 )
+ {
+ r = ( pixel[ ( ty * img->Width ) + tx ] & 0xF800 ) >> 8;
+ g = ( pixel[ ( ty * img->Width ) + tx ] & 0x07E0 ) >> 3;
+ b = ( pixel[ ( ty * img->Width ) + tx ] & 0x001F ) << 3;
+ SetPixelColor( RGB( r, g, b ) );
+ }
+ }
+ }
+ else if ( img->Format == RGB18 )
+ {
+ const unsigned int *pixel = ( const unsigned int* ) img->PixelData;
+ unsigned short r, g, b;
+
+ for ( ty = 0; ty < img->Height; ty++ )
+ for ( tx = 0; tx < img->Width; tx++ )
+ {
+ newx = x + rox + ( ( ( tx - rox ) * cos( radian ) ) - ( ( ty - roy ) * sin( radian ) ) );
+ newy = y + roy + ( ( ( ty - roy ) * cos( radian ) ) + ( ( tx - rox ) * sin( radian ) ) );
+
+ SetXY( newx, newy, newx, newy );
+ if ( _colorDepth == RGB16 )
+ {
+ r = ( pixel[ ( ty * img->Width ) + tx ] >> 16 ) & 0xF8;
+ g = ( pixel[ ( ty * img->Width ) + tx ] >> 8 ) & 0xFC;
+ b = ( pixel[ ( ty * img->Width ) + tx ] & 0xF8 ) >> 3;
+ WriteData( ( r << 8 ) | ( g >> 5 ) | ( g << 3 ) | b );
+ }
+ else if ( _colorDepth == RGB18 )
+ SetPixelColor( pixel[ ( ty * img->Width ) + tx ] );
+ }
+ }
Deactivate();
}
}
