How to view .h graphics files

SAI_band 2.zip (7.4 KB)

here you go

I don't understand your problem.
Google has a lot info about RGB565 format and it conversion to and from RGB888 (what you call 6chars HEX code).

// Convert 8/8/8 to  5/6/5 colour
uint16_t Color888(uint8_t r, uint8_t g, uint8_t b) {
  return ((uint16_t)(r & 0xF8) << 8) | ((uint16_t)(g & 0xFC) << 3) | (b >> 3);
}

Back conversion is also done in one line

Just so you can see what it's being used for, the bottom left instrument is a rolling picture that used the bmp file to diplay pitch; in 16bit form it's too memory hungry so doesn't display, but 8 bit images work

Les

What is the original X x Y resolution of the picture?

200x1012px

Les

So your first task should be resizing the image to the screen size, rather than reducing colour depth from 16 to 8 bit.
Resize will give you decreasing of the file size about four times

No, the bmp image is used as a moving scrolling image, I'm wondering if I can video it so you can see

Les

if you use GitHub - robertgallup/python-bmp2hex: Python utility to convert 1-, 4-, 8- and 16-bit bitmap files to hex. Used to embed graphics in Arduino/C code, primarily for display. on the bmp file you shared

you get

python3 bmp2hex.py image.bmp

PROGMEM const struct {
  unsigned int   width;
  unsigned int   height;
  unsigned int   bitDepth;
  uint8_t *pixel_data[404800];
} IMAGE = {
200, 1012, 16, {
0x7d, 0x67, 0x7d, 0x67, 0x7d, 0x67, 0x7d, 0x67, 0x7d, 0x67, 0x7d, 0x67, 0x7d, 0x67, 0x7d, 0x67,
0x7d, 0x67, 0x7d, 0x67, 0x7d, 0x67, 0x7d, 0x67, 0x7d, 0x67, 0x7d, 0x67, 0x7d, 0x67, 0x7d, 0x67,
....
0xa5, 0x14, 0xa5, 0x14, 0xa5, 0x14, 0xa5, 0x14, 0xa5, 0x14, 0xa5, 0x14, 0xa5, 0x14, 0xa5, 0x14,
0xa5, 0x14, 0xa5, 0x14, 0xa5, 0x14, 0xa5, 0x14, 0xa5, 0x14, 0xa5, 0x14, 0xa5, 0x14, 0xa5, 0x14
}
};

so indeed the file is recognised as a 200x1012 bitmap with bitDepth of 16 (2 bytes)

if that's the format expected by your code, then you could directly use the pixel_data array generated by the tool.

I got the same output, however putting that code into the sketch results in all the colours being corrupted

One thing I did notice was the header on my orginal is "const uint16_t SAI_band [] = {" rather than the more common form "static const unsigned char SAI_band_2[] PROGMEM = {" that I have seen with other sketches

Cheers

Les

what's the library you use for your screen? may be looking there you could find the expected bitmap representation?

If you have access to python you can try this prototype. It may have limitations on file format but it works well with png files and it worked with the bmp file you provided. It assumes that the file format of the header is rgb565 and converts to rgb888. If the header has a lot of comments there is a possibility it would could mess things up. There was also an unexpected issue with the file you provided, it's height was so tall that I could not access the save button very well but that is not a big deal.

Heres a vid and you can see with this image it takes some time for the conversion, it obviously works faster with smaller images

from tkinter import *
from tkinter import ttk
from tkinter import messagebox
from tkinter import Tk, Canvas, PhotoImage, mainloop
from PIL import Image

WIDTH=200
HEIGHT=1012
FILENAME="band.h"
SAVEFILE="band.png"

window = Tk()

canvas = Canvas(window, width=WIDTH, height=HEIGHT, bg="#000000")
canvas.grid(row=0,column=0)
img = PhotoImage(width=WIDTH, height=HEIGHT)
canvas.create_image((WIDTH/2, HEIGHT/2), image=img, state="normal")

def save_image():
 img.write(SAVEFILE, format='png')

def RGB565_to_RGB888(color_565):
 
    r = ((((int(color_565,16) >> 11) & 0x1F) * 527) + 23) >> 6
    g = ((((int(color_565,16) >> 5) & 0x3F) * 259) + 33) >> 6
    b = (((int(color_565,16) & 0x1F) * 527) + 23) >> 6
    RGB888 = r << 16 | g << 8 | b
    return RGB888
 
def display_image():
  temp_txt=""
  new_txt=""
  hex_text=""
  count=0
  
  with open(FILENAME) as myFile:
      hex_text = myFile.read()
      result = hex_text.split("{")  
      hex_text=result[1]
      result.clear()
      result=hex_text.split("}")
      hex_text=result[0]
      result.clear()
      result=hex_text.replace('0x','')
      hex_text=result.split(',')
   

      for i in range(len(hex_text)-1):
        
        if '//' in hex_text[i]:
          temp_txt=hex_text[i]
          new_txt=temp_txt.split("\n")
          hex_text[i]=new_txt[1]
       
        count+=1

      count=0

  if len(hex_text) != (HEIGHT * WIDTH):
    msg_box=messagebox.askquestion("Bad file size", "Do you want to continue?")
    if msg_box == 'no': 
      return
  else:
    pass

  for y in range(HEIGHT):
    for x in range(WIDTH):
      
          h_color=hex_text[count].strip()
          color_rgb888=RGB565_to_RGB888(h_color)
          color=hex(color_rgb888)
          count+=1
          data=color.replace("0x","")

          while len(data)<6:
            data="0" + data

          data="#" + data
         
          img.put(data,(x,y))
   
btn_Import=Button(window,text="Import File",width=10,command=lambda:display_image())
btn_Import.grid(row=1,column=0)
btn_saveCanvas=Button(window,text="Save Canvas",width=10,command=lambda:save_image())
btn_saveCanvas.grid(row=2,column=0)

mainloop()

B.T.W. I am creating the header in the simplest way

const unsigned short picture[202400] PROGMEM ={ .............. data ................};

Thanks for all the help, with that I nailed it! I wish I could post a video of how it all works so you could see it, I am so happy with the result

To all that looked in and those who help I extend my deepest gratitude!

Les

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.