text rendering

User avatar
Tectu
Posts: 1225
Joined: Thu May 10, 2012 9:50 am

Re: text rendering

Post by Tectu »

I don't see what there is to tell in more detail? I can confirm that the current text rendering solution is very slow.
Badger made a few posts up everything clear and also gave ideas how to solve the problem?!

To make this clear at this point: Badger and I don't try to make your work looking bad or something. We are happy for your contribution, and I even asked you for implementing something.
This are just improvements. I had to do the same on the rest of the library too. I had 3k additions and 2.5k removes just because the architecture of the library got optimized ;-)
Such projects do require re-writing and overthinking parts of the codes serval times, that's not a bad thing.


~ Tectu
User avatar
Badger
Posts: 346
Joined: Mon Apr 18, 2011 6:07 pm

Re: text rendering

Post by Badger »

Previously the font drawing routine would go through each pixel in the font, move the cursor to that coordinate and then write the pixel to the lcd. This is slow because it involves sending lots of coordinates.

All I did to get the speed up was to create a uint16_t buffer, fill it with the new pixel data row by row and then use the writeStream functions to write it to the LCD, rather than doing it pixel by pixel.

Code: Select all

   for(x = 0; x < fontWidth; x++) {
      chi = *(uint16_t*)ptr;
      for(y = 0; y < fontHeight; y++) {
         buf[y*fontWidth+x] = (chi & 0x01) ? fgcolor : bgcolor;
         chi >>= 1;
      }
      ptr += 2;
   }

   lcdWriteArea(cx, cy, cx+fontWidth, cy+fontHeight, buf, fontWidth*fontHeight);


It's an obvious optimisation to make.

The same approach could also be used to support transparency, but we'd have to first read the window covered by the character to the buffer, and then alter the pixels covered by the font. I think it should still end up being quicker than drawing it pixel by pixel.
User avatar
Badger
Posts: 346
Joined: Mon Apr 18, 2011 6:07 pm

Re: text rendering

Post by Badger »

responding to some of Abhisek's comments so we can discuss them here:

Also, the four orientations we support can make writeStream difficult, you have to set Y increment first and then X. We will have to work out LLD implementation of all possible combinations.

true, but this is something that should be implemented in the lld. doing a 'bulk transfer' is key to getting decent performance. If a particular driver can't handle windowing then the lld can implement the write stream functions to draw the data pixel by pixel. in the ssd1289 you can specify the order the buffer is read in (column by column, row by row etc) so that shouldn't be a problem. Hopefully your panel has similar abilities?

Image

Anyway, the more I think about it handling both monospaced and variable width fonts wont be a problem, so everyone can be happy :D

I think, we should let transparent rendering as it is, solid text rendering be optimised.

We can do that for now until we have done some tests to see which is quicker. It will probably vary depending on the driver and interface
User avatar
Tectu
Posts: 1225
Joined: Thu May 10, 2012 9:50 am

Re: text rendering

Post by Tectu »

You can use lcdGetOrientation() wherever you need it to find out, which is the current orientation. It returns an int value from 0 to 3.
There's an enum for more readable handling:

Code: Select all

enum orientation {portrait, landscape, portraitInv, landscapeInv};




~ Tectu
Abhishek
Posts: 266
Joined: Wed May 23, 2012 3:15 pm

Re: text rendering

Post by Abhishek »

Yes the S6D1121 has both ID and AM bits and I can work with them!

However after checking the datasheet of S6D1121 I cannot find anything that will enable my panel to do the 'inverted' portrait and landscape modes as the SSD1289 can do.

Here's a link to the S6D1121 datasheet, maybe something could come up: http://iteadstudio.com/store/images/pro ... 6D1121.pdf

Also, I have two suggestions for the text rendering rewrite, request comments:
1. Could I make the lcdDrawChar function return the font width of the character it just drew on the screen? It could simplify console implementations, I guess.
2. Should we move the text rendering functions to a separate file?

Abhishek
User avatar
Tectu
Posts: 1225
Joined: Thu May 10, 2012 9:50 am

Re: text rendering

Post by Tectu »

Your driver does not need to some inverted output mode. It's just flipped over head. So every inverted mode is just 180° rotated of the "normal" mode.
It's also archived by the AM and ID bits.

And I think we should keep the text rendering stuff inside the glcd files, since this is basic functionallity. Just put "extended" features like graph, gui and console in seperate files.


~ Tectu
Abhishek
Posts: 266
Joined: Wed May 23, 2012 3:15 pm

Re: text rendering

Post by Abhishek »

I'm afraid Tectu that's not the case.

Your orientation mode setting in all cases does the following calls with a slight change in values:

Code: Select all

lld_lcdWriteReg(0x0001, 0x293F);
lld_lcdWriteReg(0x0011, 0x6078);


To the best of my knowledege, 0x0001 sets the driving direction (239 to 0 or 0 to 239) : The RL Bit, to be exact. The inverted portrait mode sets this particular bit.

The ID and AM bits are contained in the 0x0011 register.
User avatar
Tectu
Posts: 1225
Joined: Thu May 10, 2012 9:50 am

Re: text rendering

Post by Tectu »

You are right. I am still not sure if this is the propper way or not. In my understanding, it should be done just over AM and ID bits, because you can draw, and change the orientation without redrawing (the lcd controller does keep the informations and redraws in the right direction).

Doing some more research about that is on my todo list.


~ Tectu
User avatar
Badger
Posts: 346
Joined: Mon Apr 18, 2011 6:07 pm

Re: text rendering

Post by Badger »

I've just noticed that SSD1289 has a vertical scroll function. This will make the console so much easier to implement quickly! I think that S6D1121 does as well, but it might depend on the interface used.
User avatar
Tectu
Posts: 1225
Joined: Thu May 10, 2012 9:50 am

Re: text rendering

Post by Tectu »

Could we also implement \t and probably \v ?


~ Tectu
Locked