@@ -230,7 +230,7 @@ export default function Pixel2CPP() {
230230
231231 // Generate byte string based on output format
232232 if ( outputFormat === "PLAIN_BYTES" ) {
233- return generatePlainBytes ( bytes , safeName , w , h , dataType ) ;
233+ return generatePlainBytes ( bytes , safeName , w , h , dataType , dataFormat , drawMode ) ;
234234 } else if ( outputFormat === "ARDUINO_CODE" ) {
235235 return generateArduinoCode ( bytes , safeName , w , h , dataType , dataFormat , drawMode ) ;
236236 } else if ( outputFormat === "ARDUINO_SINGLE_BITMAP" ) {
@@ -493,18 +493,211 @@ void drawGrayImage(int16_t x0, int16_t y0) {
493493 } ;
494494
495495 // Output format generators
496- const generatePlainBytes = ( bytes , safeName , w , h , dataType ) => {
496+ const generatePlainBytes = ( bytes , safeName , w , h , dataType , dataFormat , drawMode ) => {
497497 const formatByte = ( b ) => dataType === "uint16_t"
498498 ? "0x" + b . toString ( 16 ) . toUpperCase ( ) . padStart ( 4 , "0" )
499499 : "0x" + b . toString ( 16 ) . toUpperCase ( ) . padStart ( 2 , "0" ) ;
500500
501501 const byteStr = bytes . map ( formatByte ) . join ( ", " ) ;
502502
503- return `// Generated by Pixel2CPP - Plain bytes format
504- // ${ w } x${ h } pixels, ${ bytes . length } bytes total
505- // Data type: ${ dataType }
503+ // Generate working Arduino code based on draw mode
504+ if ( drawMode . includes ( "1BIT" ) || drawMode . includes ( "ALPHA" ) ) {
505+ return `// Generated by Pixel2CPP (${ drawMode } )
506+ #include <Adafruit_GFX.h>
507+ #include <Adafruit_SSD1306.h>
508+
509+ const uint16_t ${ safeName } _w = ${ w } ;
510+ const uint16_t ${ safeName } _h = ${ h } ;
511+ const ${ dataType } ${ safeName } _data[] PROGMEM = {
512+ ${ byteStr }
513+ };
514+
515+ Adafruit_SSD1306 display(128, 64, &Wire, -1);
516+
517+ void setup() {
518+ Serial.begin(9600);
519+
520+ // Initialize display
521+ display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
522+ display.clearDisplay();
523+ display.drawBitmap(0, 0, ${ safeName } _data, ${ safeName } _w, ${ safeName } _h, 1);
524+ display.display();
525+ }
526+
527+ void loop() {
528+ // Your main code here
529+ }` ;
530+ } else if ( drawMode . includes ( "RGB565" ) ) {
531+ return `// Generated by Pixel2CPP (RGB565)
532+ #include <Adafruit_GFX.h>
533+ #include <Adafruit_ST7735.h>
534+
535+ const uint16_t ${ safeName } _w = ${ w } ;
536+ const uint16_t ${ safeName } _h = ${ h } ;
537+ const ${ dataType } ${ safeName } _data[] PROGMEM = {
538+ ${ byteStr }
539+ };
540+
541+ #define TFT_CS 10
542+ #define TFT_RST 9
543+ #define TFT_DC 8
544+
545+ Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST);
546+
547+ void setup() {
548+ Serial.begin(9600);
549+
550+ // Initialize display
551+ tft.initR(INITR_BLACKTAB);
552+ tft.setRotation(0);
553+ tft.fillScreen(ST77XX_BLACK);
554+
555+ // Display the image
556+ drawImage(0, 0);
557+ }
558+
559+ void drawImage(int16_t x0, int16_t y0) {
560+ tft.startWrite();
561+ tft.setAddrWindow(x0, y0, ${ safeName } _w, ${ safeName } _h);
562+ for (uint16_t i = 0; i < ${ safeName } _w * ${ safeName } _h; i++) {
563+ uint16_t color = pgm_read_word(&${ safeName } _data[i]);
564+ tft.writePixel(color);
565+ }
566+ tft.endWrite();
567+ }
568+
569+ void loop() {
570+ // Your main code here
571+ }` ;
572+ } else if ( drawMode . includes ( "RGB888_24" ) ) {
573+ return `// Generated by Pixel2CPP (RGB24)
574+ #include <Adafruit_GFX.h>
575+ #include <Adafruit_ILI9341.h>
576+
577+ const uint16_t ${ safeName } _w = ${ w } ;
578+ const uint16_t ${ safeName } _h = ${ h } ;
579+ const ${ dataType } ${ safeName } _data[] PROGMEM = {
580+ ${ byteStr }
581+ };
582+
583+ #define TFT_CS 10
584+ #define TFT_RST 9
585+ #define TFT_DC 8
586+
587+ Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_RST);
588+
589+ void setup() {
590+ Serial.begin(9600);
591+
592+ // Initialize display
593+ tft.begin();
594+ tft.setRotation(0);
595+ tft.fillScreen(ILI9341_BLACK);
596+
597+ // Display the image
598+ drawImage(0, 0);
599+ }
600+
601+ void drawImage(int16_t x0, int16_t y0) {
602+ for (uint16_t y = 0; y < ${ safeName } _h; y++) {
603+ for (uint16_t x = 0; x < ${ safeName } _w; x++) {
604+ uint16_t index = (y * ${ safeName } _w + x) * 3;
605+ uint8_t r = pgm_read_byte(&${ safeName } _data[index]);
606+ uint8_t g = pgm_read_byte(&${ safeName } _data[index + 1]);
607+ uint8_t b = pgm_read_byte(&${ safeName } _data[index + 2]);
608+
609+ // Convert to RGB565 for display
610+ uint16_t color = ((r & 0xF8) << 8) | ((g & 0xFC) << 3) | (b >> 3);
611+ tft.drawPixel(x0 + x, y0 + y, color);
612+ }
613+ }
614+ }
615+
616+ void loop() {
617+ // Your main code here
618+ }` ;
619+ } else if ( drawMode . includes ( "RGB888_32" ) ) {
620+ return `// Generated by Pixel2CPP (RGBA32)
621+ #include <Adafruit_GFX.h>
622+ #include <Adafruit_ILI9341.h>
623+
624+ const uint16_t ${ safeName } _w = ${ w } ;
625+ const uint16_t ${ safeName } _h = ${ h } ;
626+ const ${ dataType } ${ safeName } _data[] PROGMEM = {
627+ ${ byteStr }
628+ };
629+
630+ #define TFT_CS 10
631+ #define TFT_RST 9
632+ #define TFT_DC 8
633+
634+ Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_RST);
635+
636+ void setup() {
637+ Serial.begin(9600);
638+
639+ // Initialize display
640+ tft.begin();
641+ tft.setRotation(0);
642+ tft.fillScreen(ILI9341_BLACK);
643+
644+ // Display the image
645+ drawImage(0, 0);
646+ }
647+
648+ void drawImage(int16_t x0, int16_t y0) {
649+ for (uint16_t y = 0; y < ${ safeName } _h; y++) {
650+ for (uint16_t x = 0; x < ${ safeName } _w; x++) {
651+ uint16_t index = (y * ${ safeName } _w + x) * 4;
652+ uint8_t r = pgm_read_byte(&${ safeName } _data[index]);
653+ uint8_t g = pgm_read_byte(&${ safeName } _data[index + 1]);
654+ uint8_t b = pgm_read_byte(&${ safeName } _data[index + 2]);
655+ uint8_t a = pgm_read_byte(&${ safeName } _data[index + 3]);
656+
657+ // Only draw if alpha > threshold
658+ if (a > 127) {
659+ // Convert to RGB565 for display
660+ uint16_t color = ((r & 0xF8) << 8) | ((g & 0xFC) << 3) | (b >> 3);
661+ tft.drawPixel(x0 + x, y0 + y, color);
662+ }
663+ }
664+ }
665+ }
666+
667+ void loop() {
668+ // Your main code here
669+ }` ;
670+ } else {
671+ // Fallback for other modes - generic display code with the data
672+ return `// Generated by Pixel2CPP (${ drawMode } )
673+ #include <Adafruit_GFX.h>
674+ // Add your display library here (e.g., #include <Adafruit_SSD1306.h>)
675+
676+ const uint16_t ${ safeName } _w = ${ w } ;
677+ const uint16_t ${ safeName } _h = ${ h } ;
678+ const ${ dataType } ${ safeName } _data[] PROGMEM = {
679+ ${ byteStr }
680+ };
681+
682+ // Add your display initialization here
683+ // Example: Adafruit_SSD1306 display(128, 64, &Wire, -1);
506684
507- ${ byteStr } `;
685+ void setup() {
686+ Serial.begin(9600);
687+
688+ // Initialize your display here
689+ // Example: display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
690+
691+ // Add your image display code here
692+ // Example: display.clearDisplay();
693+ // display.drawBitmap(0, 0, ${ safeName } _data, ${ safeName } _w, ${ safeName } _h, 1);
694+ // display.display();
695+ }
696+
697+ void loop() {
698+ // Your main code here
699+ }` ;
700+ }
508701 } ;
509702
510703 const generateArduinoCode = ( bytes , safeName , w , h , dataType , dataFormat , drawMode ) => {
0 commit comments