Luna Picture (*.lp)

Luna uses a proprietary picture format which the IDE supports directly. Its simple structure is ideal for microcontroller applications. You may also integrate any other picture format and decode it yourself. The BMP format also supports RLe-Compression und up to 24 Bit color depth. „png“ is also suitable although decoding is more complicated. Contrary to the popular microcontroller „BGF“-Format, „LP“ will not lead to decoding errors when some specific byte sequences are encountered. „LP“ also has an „end“ marker.

Format Description

The Luna-Picture-Format is made up of a header, the RLe packed data end an end marker.

Offset Description Name
0x00 Width in Pixel Width
0x01 Height in Pixel Height
0x02 Bit Depth(1) Depth
0x03 Reserved (0) reserved
0x04..n RLe-Compressed Picture Data Data
0x77:0x00 End marking (2-Byte-Token) endMark

tHE pICTURE dATA: first Pixel is at top left (x=0,y=0)

  • 1Bit: Every Byte stores 8 Pixel x,y+0..7 (bit)
  • 8Bit: Every Byte stores 1 pixel x,y (byte)

The RLe-Coding
Read a byte and check if it is 0x77, the (Magic-Byte). This preceeds a 3 byte token: 0x77:count:value, Example: „0x77 0xFF 0x13“ represents 255 times the value 0x13. Tha tis all there is to it, the simplicity is ideal for processing on micro controller. Example of a decoding routine

' Initialization
avr.device = atmega168
avr.clock = 20000000         ' Quartz frequency
avr.stack = 32               ' Bytes Program stack (Default: 16)
uart.baud = 19200            ' Baudrate
uart.Recv.enable             ' Send active
uart.Send.enable             ' Receive aktive
' Main Program
SendPicture(Picture.Addr) ' Decode picture and send to serial port
do
loop
 
Procedure SendPicture(imgAddr as word)
    dim i,a,cc as byte
    dim c,w,h,size as word
    ' RLe compressed luna lcd picture 
    ' format description
    ' -- header (4 byte) ------------------
    ' byte   width in pixels
    ' byte   height in pixels
    ' byte   depth (1,8)
    ' byte   reserved (0)
    ' -- data (x bytes) --------------------
    ' First pixel at top left x=0,y=0
    '  1 bit: pixels scanned from x to x+width-1 and 8 rows per width
    '         each byte contains 8 pixel x,y+0..7 (bit)
    '  8 bit: pixels scanned from x to x+width-1 and 1 row per width
    '         each byte contains 1 pixel x,y      (byte)
    ' RLe: magic = 0x77:count:value (3-byte token)
    ' example: 0x77 0xFF 0x13  is 255 x the value 0x13
    ' -- end mark --------------------------
    ' 0x77 0x00 (zero count, no value byte)
    ' routine for monochrome pictures
    w = flash.ByteValue(imgAdr)
    incr imgAdr
    h = flash.ByteValue(imgAdr)
    add imgAdr,3
    size = h / 8
    size = size * w
    decr size
    clr c
    do
      a = flash.ByteValue(imgAdr)
      incr imgAdr
      if a = &h77 then
        cc = flash.ByteValue(imgAdr)
        if cc then
          incr imgAdr
          a = flash.ByteValue(imgAdr)
          incr imgAdr
          for i = 1 to cc
            Uart.Write a
            incr c
          next
        else
          exit
        end if
      else
        Uart.Write a
        incr c
      end if
    loop until c > size or c > 1023
  endproc
endProc
#includeData Bild,"pictures\mypicture.lp"