Using the JPEGDEC libary

I’m trying to be able to print jpg images on a thermal printer

Im using a ESP32-WROOM-32D

I have got the thermal printer working by adapting Larry Bank’s thermal printer code to work with a MXW01 printer and can print BMPs successfully. Additionally sending test code I can print using the current code im using so Im confident that part is working.

Testing different test images seems to yield the same result in terms of output being sent to the printer so I’m assuming im not correctly using the JPGDEC library but I can’t see what im doing wrong. THE JPGDEC code is the jpg. lines in the loop and the JPEGDraw function.

Please could someone advice whether im making an obvious mistake or what i should try next in order to debug further

The chekerboard test pattern is stored as a progmem as so it should be a 24Bpp image

// checkerboard_384x486_jpg - 384x486 JPEG, 4493 bytes

const unsigned int checkerboard_384x486_jpg_len = 4493;
const unsigned char checkerboard_384x486_jpg[] PROGMEM = {
  0xFF, 0xD8, 0xFF, 0xE0, 0x00, 0x10, 0x4A, 0x46, 0x49, 0x46, 0x00, 0x01,
  0x01, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0xFF, 0xDB, 0x00, 0x43,
  0x00, 0x02, 0x01, 0x01, 0x01, 0x01, 0x01, 0x02, 0x01, 0x01, 0x01, 0x02,
  0x02, 0x02, 0x02, 0x02, 0x04, 0x03, 0x02, 0x02, 0x02, 0x02, 0x05, 0x04,
  0x04, 0x03, 0x04, 0x06, 0x05, 0x06, 0x06, 0x06, 0x05, 0x06, 0x06, 0x06,
  0x07, 0x09, 0x08, 0x06, 0x07, 0x09, 0x07, 0x06, 0x06, 0x08, 0x0B, 0x08,
  0x09, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x06, 0x08, 0x0B, 0x0C, 0x0B, 0x0A,

this is my code

#include <Thermal_Printer.h>
#include <JPEGDEC.h>

#include "eagle_576.h"
#include "dog_384.h"

uint8_t ucDither[576 * 16]; // buffer for the dithered pixel output
JPEGDEC jpg;
static int iWidth;

int JPEGDraw(JPEGDRAW *pDraw)
{

  Serial.print(" W: "); Serial.print(pDraw->iWidth);
  Serial.print(" H: "); Serial.println(pDraw->iHeight);

  // Optional: inspect a few pixel bits
  for (int i = 0; i < 16 && i < (pDraw->iWidth * pDraw->iHeight / 8); i++) {
    Serial.print("0x");
    Serial.print(pDraw->pPixels[i], HEX);
    Serial.print(" ");
  }
  Serial.println();

  tpSetBackBuffer((uint8_t *)pDraw->pPixels, pDraw->iWidth, pDraw->iHeight);
  tpSendImageData();
  return 1;
}

void setup() {
  Serial.begin(115200);
  while (!Serial);
  Serial.println((char *)"Scanning for BLE printer");
  if (tpScan()) // Scan for any supported printer name
  {
    Serial.println((char *)"Found a printer!, connecting...");
    if (tpConnect())
    {
      Serial.println("Connected!");
      tpSetWriteMode(MODE_WITHOUT_RESPONSE);
    }
    else
    {
      Serial.println("Failed to connected :(");
      while (1) {};
    }
  } // if scan
  else
  {
    Serial.println((char *)"Didn't find a printer :( ");
    while (1) {};
  }
} /* setup () */

void loop() {
uint8_t *pImage;
int iImageSize;

  
  pImage = (uint8_t *)dog_384;
  iImageSize = (int)sizeof(dog_384);
  tpPreGraphics(384,486);
  if (jpg.openRAM(pImage, iImageSize, JPEGDraw)) {
     jpg.setPixelType(ONE_BIT_DITHERED);
     jpg.decodeDither(ucDither, 0);
  }
  tpPostGraphics();
  tpFeed(32); // advance the paper 32 scan lines
  tpDisconnect();
  Serial.println("Finished printing!");
  while (1) {};
} /* loop() */

I tried getting JPEGDEC working with my epaper display. Try using the dither buffer instead of the draw-pixels

tpSetBackBuffer(ucDither, pDraw->iWidth, pDraw->iHeight);

I see tpPrintBuffer in the printer library, but not tpSendImageData. Is that in an earlier version?

Interesting I'll try this later

The send image data is a custom function I wrote which is just tpprintbuffer with out pre or post graphics. And sends that data to a different bluetooth uuid because the printer I'm using is weird.

Yep this is the solution. Thank you!

How did you adapt the Larry Bank's Library?
I have the same printer, but I can't get it working.
I added "MXW01" to szPrinterIDs and it detects it but doesn't print anything. I tried defining it as PRINTER_CAT, PRINTER_MTP2, PRINTER_MTP3, PRINTER_FOMEMO.