added support to view JPEG2000 images commonly used with epassports. The lib use a BSD-2 license compatible with our GPL3+

This commit is contained in:
iceman1001 committed 2026-08-21 20:10:30 +02:00
1 parent 68af7e2582
commit 0f3092ceb8
64 files changed
+47449 -5

No files matched your search

+15 -2
View File
@@ -1531,8 +1531,21 @@ static int emrtd_print_image(const char *title, uint8_t *data, size_t datalen) {
bool found = false;
size_t offset = 0;
for (offset = 0; offset < datalen - 6; offset++) {
if ((data[offset] == 0xFF && memcmp(jpeg_header, data + offset, 4) == 0) ||
(data[offset] == 0x00 && memcmp(jpeg2k_header, data + offset, 6) == 0)) {
if (data[offset] == 0xFF) {
// JPEG SOI + any APPn marker, JFIF (FFE0) is the common one but
// Exif (FFE1) / raw DQT (FFDB) show up as well
if (memcmp(jpeg_header, data + offset, 3) == 0) {
found = true;
break;
}
// JPEG2000 raw codestream, no JP2 container
if (memcmp(jpeg2k_cs_header, data + offset, 4) == 0) {
found = true;
break;
}
} else if (data[offset] == 0x00 && memcmp(jpeg2k_header, data + offset, 6) == 0) {
// JPEG2000 in a JP2 container
found = true;
break;
}
+26 -3
View File
@@ -21,7 +21,8 @@
#include <string.h>
#include "proxguiqt.h"
#include "proxmark3.h"
#include "ui.h" // for prints
#include "ui.h" // for prints
#include "imgjp2.h" // JPEG2000
static ProxGuiQT *gui = NULL;
static WorkerThread *main_loop_thread = NULL;
@@ -77,11 +78,33 @@ static void show_no_gui_notice(void) {
// hook up picture viewer
extern "C" void ShowPictureWindow(const char *title, uint8_t *data, int len) {
if (data == NULL || len <= 0) {
return;
}
QImage img;
// No support for jpeg2000 in Qt Image since a while...
// https://doc.qt.io/qt-5/qtimageformats-index.html
QImage img = QImage::fromData(data, len);
// and the distros ship no replacement plugin, so decode it ourselves with
// the vendored openjpeg. Most eMRTD EF_DG2 portraits are jpeg2000.
if (jp2_is_jpeg2000(data, (size_t)len)) {
int w = 0, h = 0;
uint8_t *rgb = jp2_decode_rgb(data, (size_t)len, &w, &h);
if (rgb) {
// QImage doesn't take ownership of the buffer, copy() detaches it
img = QImage(rgb, w, h, w * 3, QImage::Format_RGB888).copy();
free(rgb);
}
} else {
img = QImage::fromData(data, len);
}
if (img.isNull()) {
PrintAndLogEx(WARNING, "Failed to decode image ( %s ), Qt lacks support for this format (jpeg2000?)", (title) ? title : "n/a");
PrintAndLogEx(WARNING, "Failed to decode image ( %s )", (title) ? title : "n/a");
return;
}