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.

86 lines
3.4KB

  1. /*
  2. * First Attempt at generating the TLC output code from an image.
  3. * Run this with "java AnimationCreator"
  4. * It will read any image file in the current directory and create an animation for the TLC library.
  5. *
  6. * Right now this only works with 1 TLC with 16 LEDS connected to it, where
  7. * output0 is the bottom and output15 is the top.
  8. *
  9. * For best results make your files 16 pixels high and as wide as you want. Each vertical pixel
  10. * corresponds to an LED output.
  11. *
  12. * Alex Leone <acleone ~AT~ gmail.com>, 2008-11-12
  13. */
  14. import java.util.*;
  15. import java.awt.*;
  16. import java.awt.image.*;
  17. import java.io.*;
  18. import javax.imageio.*;
  19. public class AnimationCreator {
  20. public static void main(String[] args) throws IOException {
  21. if (args.length == 0) {
  22. autoProcess();
  23. }
  24. }
  25. public static void autoProcess() throws IOException {
  26. File currentDirectory = new File (".");
  27. File[] files = currentDirectory.listFiles();
  28. int animationCount = 1;
  29. for (File file : files) {
  30. if (!file.isFile())
  31. continue;
  32. String fileName = file.getName();
  33. String suffix = fileName.substring(fileName.indexOf('.') + 1);
  34. if(!canReadFormat(suffix))
  35. continue;
  36. String baseName = fileName.substring(0, fileName.indexOf('.'));
  37. String varName = "ani_" + baseName.toLowerCase();
  38. String outputName = varName + ".h";
  39. System.out.println("Writing " + outputName);
  40. BufferedImage image = ImageIO.read(file);
  41. PrintStream output = new PrintStream(new File(outputName));
  42. output.println("#define " + varName.toUpperCase() + "_FRAMES " + image.getWidth());
  43. output.println("uint8_t " + varName + "[NUM_TLCS * 24 * " + varName.toUpperCase() + "_FRAMES] PROGMEM = {");
  44. int[] rowRGB = new int[16];
  45. for (int w = 0; w < image.getWidth(); w++) {
  46. for (int h = 0; h < 16; h++) {
  47. rowRGB[h] = image.getRGB(w, 15 - h);
  48. }
  49. parseRow(rowRGB, output);
  50. }
  51. output.println("};");
  52. System.out.println("Wrote " + image.getWidth() + " frames to " + outputName);
  53. animationCount++;
  54. }
  55. }
  56. // Returns true if the specified format name can be read
  57. public static boolean canReadFormat(String formatName) {
  58. Iterator<ImageReader> iter = ImageIO.getImageReadersByFormatName(formatName);
  59. return iter.hasNext();
  60. }
  61. public static double rgbToGrayscaleIntensity(int rgb) {
  62. Color c = new Color(rgb);
  63. return 0.2989 * c.getRed() + 0.5870 * c.getGreen() + 0.1140 * c.getBlue();
  64. }
  65. public static void parseRow(int[] rowRGB, PrintStream output) {
  66. output.print("\t");
  67. for (int i = rowRGB.length - 1; i >= 0; i -= 2) {
  68. int a = (255 - (int)Math.round(rgbToGrayscaleIntensity(rowRGB[i])));
  69. int b = (255 - (int)Math.round(rgbToGrayscaleIntensity(rowRGB[i - 1])));
  70. output.print(((a >> 4) & 0xFF) + "," + (((a << 4) | (b >> 8)) & 0xFF) + "," + (b & 0xFF) + ",");
  71. //System.out.print(
  72. // "GS_DUO(" + (255 - Math.round(rgbToGrayscaleIntensity(rowRGB[i]))) + "," +
  73. // (255 - Math.round(rgbToGrayscaleIntensity(rowRGB[i - 1]))) + "),");
  74. }
  75. output.println();
  76. }
  77. }