PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

109 lines
3.0KB

  1. /**
  2. * glcdBitmap.
  3. *
  4. * Creates a bitmap definition file that can be included in an Arduino sketch
  5. * to display a bitmap image on a graphics LCD using the Arduino GLCD library.
  6. *
  7. * Created 6 Nov 2008 Copyright Michael Margolis 2008
  8. */
  9. String sourceImage = "ArduinoIcon.bmp"; // change this to the name of your bitmap file
  10. PImage a;
  11. int[] aPixels;
  12. void setup()
  13. {
  14. noFill();
  15. stroke(255);
  16. frameRate(30);
  17. // load the image
  18. a = loadImage(sourceImage);
  19. if( a != null){
  20. size(a.width, a.height);
  21. aPixels = new int[width*height];
  22. for(int i=0; i<width*height; i++) {
  23. aPixels[i] = a.pixels[i];
  24. }
  25. // display the image
  26. loadPixels();
  27. for (int i=0; i<width*height; i++)
  28. pixels[i] = aPixels[i];
  29. updatePixels();
  30. writeFile(sourceImage);
  31. println("created header file for " + sourceImage);
  32. }
  33. }
  34. void writeFile(String inFileName){
  35. String[] f = split(inFileName, '.');
  36. String baseName = f[0];
  37. String outFileName = baseName + ".h";
  38. PrintWriter output;
  39. output = createWriter(outFileName);
  40. output.println("/* " + outFileName + " bitmap file for GLCD library */");
  41. output.println("/* Bitmap created from " + inFileName + " */");
  42. String[] monthName = {"","Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};
  43. output.println("/* Date: " + day() + " " + monthName[month()] + " " + year() + " */" );
  44. output.println();
  45. output.println("#include <inttypes.h>");
  46. output.println("#include <avr/pgmspace.h>");
  47. output.println();
  48. output.println("#ifndef " + baseName + "_H");
  49. output.println("#define " + baseName + "_H");
  50. output.println();
  51. output.print("static uint8_t ");
  52. output.print(baseName);
  53. output.println("[] PROGMEM = {");
  54. output.print(" ");
  55. output.print(a.width); // note width and height are bytes so 256 will be 0
  56. output.println(", // width");
  57. output.print(" ");
  58. output.print(a.height);
  59. output.println(", // height");
  60. for(int page=0; page < (a.height + 7)/8; page++) {
  61. output.println("\n /* page " + page + " (lines " + page*8 + "-" + (page*8+7) + ") */");
  62. output.print(" ");
  63. for(int x=0; x < a.width; x++){
  64. output.print( "0x" + Integer.toHexString(getValue(x,page))) ;
  65. if( (x == (a.width-1)) && (page == (((a.height +7)/8)-1)) )
  66. println("\n"); // this is the last element so new line instead of comma
  67. else
  68. output.print(","); // comma on all but last entry
  69. if( x % 16 == 15)
  70. output.print("\n ");
  71. }
  72. }
  73. output.print("\n};\n");
  74. output.println("#endif");
  75. output.flush(); // Write the remaining data
  76. output.close(); // Finish the file
  77. }
  78. int getValue( int x, int page){
  79. int val = 0;
  80. for( byte b=0; b < 8; b++){
  81. int y = page * 8 + b;
  82. int pos = y * a.width + x;
  83. if( aPixels[pos] != 0xffffffff ){
  84. val |= (1 << b); // here if color is not black
  85. }
  86. }
  87. return val;
  88. }
  89. void draw()
  90. {
  91. }