Merge pull request #2237 from socram8888/waveshare-gd

[WIP] Use GDlib in Waveshare ePapers command
This commit is contained in:
Iceman
2024-01-07 21:51:46 +01:00
committed by GitHub
20 changed files with 458 additions and 541 deletions
+3 -3
View File
@@ -35,7 +35,7 @@ jobs:
run: brew tap RfidResearchGroup/proxmark3
- name: Install dependencies
run: brew install readline coreutils qt5 RfidResearchGroup/proxmark3/arm-none-eabi-gcc openssl
run: brew install readline coreutils qt5 RfidResearchGroup/proxmark3/arm-none-eabi-gcc openssl gd
continue-on-error: true
- name: Install Python dependencies
@@ -75,7 +75,7 @@ jobs:
run: brew tap RfidResearchGroup/proxmark3
- name: Install dependencies
run: brew install readline coreutils qt5 RfidResearchGroup/proxmark3/arm-none-eabi-gcc openssl
run: brew install readline coreutils qt5 RfidResearchGroup/proxmark3/arm-none-eabi-gcc openssl gd
continue-on-error: true
- name: Install Python dependencies
@@ -116,7 +116,7 @@ jobs:
run: brew tap RfidResearchGroup/proxmark3
- name: Install dependencies
run: brew install readline coreutils qt5 RfidResearchGroup/proxmark3/arm-none-eabi-gcc openssl
run: brew install readline coreutils qt5 RfidResearchGroup/proxmark3/arm-none-eabi-gcc openssl gd
continue-on-error: true
- name: Install Python dependencies
+3 -3
View File
@@ -26,7 +26,7 @@ jobs:
run: sudo apt-get update
- name: Install dependencies
run: sudo apt-get install -yqq make autoconf build-essential ca-certificates pkg-config libreadline-dev gcc-arm-none-eabi libnewlib-dev qtbase5-dev libbz2-dev liblz4-dev libbluetooth-dev libpython3-dev python3 python3-dev libpython3-all-dev liblua5.2-dev liblua5.2-0 lua5.2 sed libssl-dev
run: sudo apt-get install -yqq make autoconf build-essential ca-certificates pkg-config libreadline-dev gcc-arm-none-eabi libnewlib-dev qtbase5-dev libbz2-dev liblz4-dev libbluetooth-dev libpython3-dev python3 python3-dev libpython3-all-dev liblua5.2-dev liblua5.2-0 lua5.2 sed libssl-dev libgd-dev
- name: Install Python dependencies
run: |
@@ -56,7 +56,7 @@ jobs:
run: sudo apt-get update
- name: Install dependencies
run: sudo apt-get install -yqq make autoconf build-essential ca-certificates pkg-config libreadline-dev gcc-arm-none-eabi libnewlib-dev qtbase5-dev libbz2-dev liblz4-dev libbluetooth-dev libpython3-dev python3 python3-dev libpython3-all-dev liblua5.2-dev liblua5.2-0 lua5.2 sed libssl-dev
run: sudo apt-get install -yqq make autoconf build-essential ca-certificates pkg-config libreadline-dev gcc-arm-none-eabi libnewlib-dev qtbase5-dev libbz2-dev liblz4-dev libbluetooth-dev libpython3-dev python3 python3-dev libpython3-all-dev liblua5.2-dev liblua5.2-0 lua5.2 sed libssl-dev libgd-dev
- name: Install Python dependencies
run: |
@@ -87,7 +87,7 @@ jobs:
run: sudo apt-get update
- name: Install dependencies
run: sudo apt-get install -yqq make autoconf build-essential ca-certificates pkg-config libreadline-dev gcc-arm-none-eabi libnewlib-dev qtbase5-dev libbz2-dev liblz4-dev libbluetooth-dev libpython3-dev python3 python3-dev libpython3-all-dev liblua5.2-dev liblua5.2-0 lua5.2 sed libssl-dev
run: sudo apt-get install -yqq make autoconf build-essential ca-certificates pkg-config libreadline-dev gcc-arm-none-eabi libnewlib-dev qtbase5-dev libbz2-dev liblz4-dev libbluetooth-dev libpython3-dev python3 python3-dev libpython3-all-dev liblua5.2-dev liblua5.2-0 lua5.2 sed libssl-dev libgd-dev
- name: Install Python dependencies
run: |
+1
View File
@@ -119,6 +119,7 @@ jobs:
python3-dev
libpython3-all-dev
libssl-dev
libgd-dev
- name: Install Python dependencies
run: |
+1
View File
@@ -80,6 +80,7 @@ tools/jtag_openocd/openocd_configuration
tools/mfd_aes_brute/mfd_aes_brute
tools/mfd_aes_brute/mfd_multi_brute
tools/mfd_aes_brute/brute_key
!tools/lena.bmp
fpga/__build*
+1
View File
@@ -8,6 +8,7 @@ This project uses the changelog in accordance with [keepchangelog](http://keepac
- Added troubleshooting entry - ARM architecture error (@francis2054)
- Fixed `lf pyramid sim` - wrong parameter handling (@iceman1001)
- Fixed bootloader - Ignore jitters when pressing the button (@wh201906)
- Changed `hf waveshare` - image loading and processing is now done using [GDlib](https://github.com/libgd/libgd) (@socram8888)
## [Steamboat Willie.4.17768][2024-01-03]
- Changed `mem spiffs dump -t` - now supports downloading direct into trace buffer (@hazardousvoltage)
+52 -8
View File
@@ -97,11 +97,12 @@ if (CMAKE_TOOLCHAIN_FILE)
set(EMBED_READLINE ON)
set(EMBED_BZIP2 ON)
set(EMBED_LZ4 ON)
set(EMBED_GD ON)
endif (CMAKE_TOOLCHAIN_FILE)
if (EMBED_READLINE OR EMBED_BZIP2 OR EMBED_LZ4)
if (EMBED_READLINE OR EMBED_BZIP2 OR EMBED_LZ4 OR EMBED_GD)
include(ExternalProject)
endif (EMBED_READLINE OR EMBED_BZIP2 OR EMBED_LZ4)
endif (EMBED_READLINE OR EMBED_BZIP2 OR EMBED_LZ4 OR EMBED_GD)
if (NOT SKIPREADLINE EQUAL 1)
if (APPLE)
@@ -213,6 +214,27 @@ if (LZ4_INCLUDE_DIRS AND LZ4_LIBRARIES)
set(LZ4_FOUND ON)
endif (LZ4_INCLUDE_DIRS AND LZ4_LIBRARIES)
if (NOT SKIPGD EQUAL 1)
if (EMBED_GD)
cmake_policy(SET CMP0114 NEW)
set(GD_BUILD_DIR ${CMAKE_CURRENT_BINARY_DIR}/deps/gd)
# Specify SOURCE_DIR will cause some errors
ExternalProject_Add(gd
URL https://github.com/libgd/libgd/releases/download/gd-2.3.3/libgd-2.3.3.tar.gz
URL_HASH SHA256=dd3f1f0bb016edcc0b2d082e8229c822ad1d02223511997c80461481759b1ed2
PREFIX deps/gd
CMAKE_ARGS -DBUILD_SHARED_LIBS=OFF -DBUILD_STATIC_LIBS=ON -DENABLE_CPP=0 -DCMAKE_INSTALL_PREFIX=.
PATCH_COMMAND cat ${CMAKE_CURRENT_SOURCE_DIR}/deps/gd-static.patch | patch -p1
)
ExternalProject_Add_StepTargets(gd configure build install)
set(GD_INCLUDE_DIRS ${GD_BUILD_DIR}/src/gd-build/include)
set(GD_LIBRARIES ${GD_BUILD_DIR}/src/gd-build/lib/libgd.a)
set(GD_FOUND ON)
else (EMBED_GD)
pkg_search_module(GD QUIET gdlib)
endif (EMBED_GD)
endif (NOT SKIPGD EQUAL 1)
if (NOT SKIPWHEREAMISYSTEM EQUAL 1)
find_path(WHEREAMI_INCLUDE_DIRS whereami.h)
find_library(WHEREAMI_LIBRARIES whereami)
@@ -332,7 +354,6 @@ set (TARGET_SOURCES
${PM3_ROOT}/client/src/cmdhfthinfilm.c
${PM3_ROOT}/client/src/cmdhftopaz.c
${PM3_ROOT}/client/src/cmdhfvas.c
${PM3_ROOT}/client/src/cmdhfwaveshare.c
${PM3_ROOT}/client/src/cmdhfxerox.c
${PM3_ROOT}/client/src/cmdhw.c
${PM3_ROOT}/client/src/cmdlf.c
@@ -495,6 +516,17 @@ if (LZ4_FOUND)
set(ADDITIONAL_LNK ${LZ4_LIBRARIES} ${ADDITIONAL_LNK})
endif (LZ4_FOUND)
if (NOT SKIPGD EQUAL 1 AND GD_FOUND)
set(ADDITIONAL_DIRS ${GD_INCLUDE_DIRS} ${ADDITIONAL_DIRS})
set(ADDITIONAL_LNK ${GD_LIBRARIES} ${ADDITIONAL_LNK})
set(ADDITIONAL_LNKDIRS ${GD_LIBRARY_DIRS} ${ADDITIONAL_LNKDIRS})
set(TARGET_SOURCES
${PM3_ROOT}/client/src/imgutils.c
${PM3_ROOT}/client/src/cmdhfwaveshare.c
${TARGET_SOURCES})
add_definitions("-DHAVE_GD")
endif (NOT SKIPGD EQUAL 1 AND GD_FOUND)
if (WHEREAMI_FOUND)
set(ADDITIONAL_DIRS ${WHEREAMI_INCLUDE_DIRS} ${ADDITIONAL_DIRS})
set(ADDITIONAL_LNK ${WHEREAMI_LIBRARIES} ${ADDITIONAL_LNK})
@@ -547,6 +579,18 @@ else (LZ4_FOUND)
message(SEND_ERROR "LZ4 library: LZ4 not found")
endif (LZ4_FOUND)
if (SKIPGD EQUAL 1)
message(STATUS "GD library: skipped")
elseif (GD_FOUND)
if (EMBED_GD)
message(STATUS "GD library: embedded")
else (EMBED_GD)
message(STATUS "GD library: system library found")
endif (EMBED_GD)
else (SKIPGD EQUAL 1)
message(STATUS "GD library: GD not found, disabled")
endif (SKIPGD EQUAL 1)
if (SKIPJANSSONSYSTEM EQUAL 1)
message(STATUS "Jansson library: local library forced")
else (SKIPJANSSONSYSTEM EQUAL 1)
@@ -721,14 +765,14 @@ endif (NOT SKIPPTHREAD EQUAL 1)
if (NOT SKIPPYTHON EQUAL 1)
# OSX have a hard time compiling python3 dependency with older cmake.
if (PYTHON3EMBED_FOUND OR PYTHON3_FOUND)
if (NOT CMAKE_VERSION VERSION_LESS 3.13)
target_link_directories(proxmark3 PRIVATE ${ADDITIONAL_LNKDIRS})
elseif (APPLE)
message( SEND_ERROR "Your CMAKE version is too old for Apple platform, please update to a version >=3.13" )
endif (NOT CMAKE_VERSION VERSION_LESS 3.13)
if (CMAKE_VERSION VERSION_LESS 3.13)
message( SEND_ERROR "Your CMAKE version is too old for Apple platform, please update to a version >=3.13" )
endif (CMAKE_VERSION VERSION_LESS 3.13)
endif (PYTHON3EMBED_FOUND OR PYTHON3_FOUND)
endif (NOT SKIPPYTHON EQUAL 1)
target_link_directories(proxmark3 PRIVATE ${ADDITIONAL_LNKDIRS})
install(TARGETS proxmark3 DESTINATION "bin")
install(DIRECTORY cmdscripts lualibs luascripts pyscripts resources dictionaries DESTINATION "share/proxmark3")
+31 -1
View File
@@ -332,6 +332,17 @@ endif
LDLIBS += $(QTLDLIBS)
CXXINCLUDES += $(QTINCLUDES)
## GD (optional)
ifneq ($(SKIPGD),1)
GDINCLUDES = $(shell $(PKG_CONFIG_ENV) pkg-config --cflags gdlib 2>/dev/null)
GDLDLIBS = $(shell $(PKG_CONFIG_ENV) pkg-config --libs gdlib 2>/dev/null)
ifneq ($(GDLDLIBS),)
LDLIBS += $(GDLDLIBS)
PM3INCLUDES += $(GDINCLUDES)
GD_FOUND = 1
endif
endif
## Readline
ifneq ($(SKIPREADLINE),1)
ifeq ($(USE_BREW),1)
@@ -410,6 +421,10 @@ ifeq ($(PYTHON_FOUND),1)
PM3CFLAGS += -DHAVE_PYTHON
endif
ifeq ($(GD_FOUND),1)
PM3CFLAGS += -DHAVE_GD
endif
ifeq ($(SWIG_LUA_FOUND),1)
PM3CFLAGS += -DHAVE_LUA_SWIG
endif
@@ -510,6 +525,16 @@ else
endif
endif
ifeq ($(SKIPGD),1)
$(info GD library: skipped)
else
ifeq ($(GD_FOUND),1)
$(info GD library: GD v$(shell $(PKG_CONFIG_ENV) pkg-config --modversion gdlib) found, enabled)
else
$(info GD library: GD not found, disabled)
endif
endif
ifeq ($(SKIPREADLINE),1)
$(info Readline library: skipped)
else
@@ -605,7 +630,6 @@ SRCS = mifare/aiddesfire.c \
cmdhftopaz.c \
cmdhftexkom.c \
cmdhfvas.c \
cmdhfwaveshare.c \
cmdhfxerox.c \
cmdhw.c \
cmdlf.c \
@@ -738,6 +762,12 @@ SRCS += bucketsort.c \
lfdemod.c \
util_posix.c
ifeq ($(GD_FOUND),1)
# electronic shelf labels
SRCS += imgutils.c \
cmdhfwaveshare.c
endif
# swig
SWIGSRCS =
+11
View File
@@ -0,0 +1,11 @@
--- a/src/gd.h 2024-01-07 16:51:43.749223000 +0100
+++ b/src/gd.h 2024-01-07 16:52:34.162291600 +0100
@@ -45,7 +45,7 @@
the gd sources in a project. */
/* http://gcc.gnu.org/wiki/Visibility */
-#if defined(_WIN32) || defined(CYGWIN) || defined(_WIN32_WCE)
+#if 0 // Disable DLL annotations when building statically. Needed for embedding under MinGW.
# ifdef BGDWIN32
# ifdef NONDLL
# define BGD_EXPORT_DATA_PROT
+52 -8
View File
@@ -98,11 +98,12 @@ if (CMAKE_TOOLCHAIN_FILE)
set(EMBED_READLINE ON)
set(EMBED_BZIP2 ON)
set(EMBED_LZ4 ON)
set(EMBED_GD ON)
endif (CMAKE_TOOLCHAIN_FILE)
if (EMBED_READLINE OR EMBED_BZIP2 OR EMBED_LZ4)
if (EMBED_READLINE OR EMBED_BZIP2 OR EMBED_LZ4 OR EMBED_GD)
include(ExternalProject)
endif (EMBED_READLINE OR EMBED_BZIP2 OR EMBED_LZ4)
endif (EMBED_READLINE OR EMBED_BZIP2 OR EMBED_LZ4 OR EMBED_GD)
if (NOT SKIPREADLINE EQUAL 1)
if (APPLE)
@@ -214,6 +215,27 @@ if (LZ4_INCLUDE_DIRS AND LZ4_LIBRARIES)
set(LZ4_FOUND ON)
endif (LZ4_INCLUDE_DIRS AND LZ4_LIBRARIES)
if (NOT SKIPGD EQUAL 1)
if (EMBED_GD)
cmake_policy(SET CMP0114 NEW)
set(GD_BUILD_DIR ${CMAKE_CURRENT_BINARY_DIR}/deps/gd)
# Specify SOURCE_DIR will cause some errors
ExternalProject_Add(gd
URL https://github.com/libgd/libgd/releases/download/gd-2.3.3/libgd-2.3.3.tar.gz
URL_HASH SHA256=dd3f1f0bb016edcc0b2d082e8229c822ad1d02223511997c80461481759b1ed2
PREFIX deps/gd
CMAKE_ARGS -DBUILD_SHARED_LIBS=OFF -DBUILD_STATIC_LIBS=ON -DENABLE_CPP=0 -DCMAKE_INSTALL_PREFIX=.
PATCH_COMMAND cat ${CMAKE_CURRENT_SOURCE_DIR}/deps/gd-static.patch | patch -p1
)
ExternalProject_Add_StepTargets(gd configure build install)
set(GD_INCLUDE_DIRS ${GD_BUILD_DIR}/src/gd-build/include)
set(GD_LIBRARIES ${GD_BUILD_DIR}/src/gd-build/lib/libgd.a)
set(GD_FOUND ON)
else (EMBED_GD)
pkg_search_module(GD QUIET gdlib)
endif (EMBED_GD)
endif (NOT SKIPGD EQUAL 1)
if (NOT SKIPWHEREAMISYSTEM EQUAL 1)
find_path(WHEREAMI_INCLUDE_DIRS whereami.h)
find_library(WHEREAMI_LIBRARIES whereami)
@@ -333,7 +355,6 @@ set (TARGET_SOURCES
${PM3_ROOT}/client/src/cmdhfthinfilm.c
${PM3_ROOT}/client/src/cmdhftopaz.c
${PM3_ROOT}/client/src/cmdhfvas.c
${PM3_ROOT}/client/src/cmdhfwaveshare.c
${PM3_ROOT}/client/src/cmdhfxerox.c
${PM3_ROOT}/client/src/cmdhw.c
${PM3_ROOT}/client/src/cmdlf.c
@@ -496,6 +517,17 @@ if (LZ4_FOUND)
set(ADDITIONAL_LNK ${LZ4_LIBRARIES} ${ADDITIONAL_LNK})
endif (LZ4_FOUND)
if (NOT SKIPGD EQUAL 1 AND GD_FOUND)
set(ADDITIONAL_DIRS ${GD_INCLUDE_DIRS} ${ADDITIONAL_DIRS})
set(ADDITIONAL_LNK ${GD_LIBRARIES} ${ADDITIONAL_LNK})
set(ADDITIONAL_LNKDIRS ${GD_LIBRARY_DIRS} ${ADDITIONAL_LNKDIRS})
set(TARGET_SOURCES
${PM3_ROOT}/client/src/imgutils.c
${PM3_ROOT}/client/src/cmdhfwaveshare.c
${TARGET_SOURCES})
add_definitions("-DHAVE_GD")
endif (NOT SKIPGD EQUAL 1 AND GD_FOUND)
if (WHEREAMI_FOUND)
set(ADDITIONAL_DIRS ${WHEREAMI_INCLUDE_DIRS} ${ADDITIONAL_DIRS})
set(ADDITIONAL_LNK ${WHEREAMI_LIBRARIES} ${ADDITIONAL_LNK})
@@ -548,6 +580,18 @@ else (LZ4_FOUND)
message(SEND_ERROR "LZ4 library: LZ4 not found")
endif (LZ4_FOUND)
if (SKIPGD EQUAL 1)
message(STATUS "GD library: skipped")
elseif (GD_FOUND)
if (EMBED_GD)
message(STATUS "GD library: embedded")
else (EMBED_GD)
message(STATUS "GD library: system library found")
endif (EMBED_GD)
else (SKIPGD EQUAL 1)
message(STATUS "GD library: GD not found, disabled")
endif (SKIPGD EQUAL 1)
if (SKIPJANSSONSYSTEM EQUAL 1)
message(STATUS "Jansson library: local library forced")
else (SKIPJANSSONSYSTEM EQUAL 1)
@@ -722,10 +766,10 @@ endif (NOT SKIPPTHREAD EQUAL 1)
if (NOT SKIPPYTHON EQUAL 1)
# OSX have a hard time compiling python3 dependency with older cmake.
if (PYTHON3EMBED_FOUND OR PYTHON3_FOUND)
if (NOT CMAKE_VERSION VERSION_LESS 3.13)
target_link_directories(pm3rrg_rdv4 PRIVATE ${ADDITIONAL_LNKDIRS})
elseif (APPLE)
message( SEND_ERROR "Your CMAKE version is too old for Apple platform, please update to a version >=3.13" )
endif (NOT CMAKE_VERSION VERSION_LESS 3.13)
if (CMAKE_VERSION VERSION_LESS 3.13)
message( SEND_ERROR "Your CMAKE version is too old for Apple platform, please update to a version >=3.13" )
endif (CMAKE_VERSION VERSION_LESS 3.13)
endif (PYTHON3EMBED_FOUND OR PYTHON3_FOUND)
endif (NOT SKIPPYTHON EQUAL 1)
target_link_directories(pm3rrg_rdv4 PRIVATE ${ADDITIONAL_LNKDIRS})
+2
View File
@@ -566,7 +566,9 @@ static command_t CommandTable[] = {
{"thinfilm", CmdHFThinfilm, AlwaysAvailable, "{ Thinfilm RFIDs... }"},
{"topaz", CmdHFTopaz, AlwaysAvailable, "{ TOPAZ (NFC Type 1) RFIDs... }"},
{"vas", CmdHFVAS, AlwaysAvailable, "{ Apple Value Added Service }"},
#ifdef HAVE_GD
{"waveshare", CmdHFWaveshare, AlwaysAvailable, "{ Waveshare NFC ePaper... }"},
#endif
{"xerox", CmdHFXerox, AlwaysAvailable, "{ Fuji/Xerox cartridge RFIDs... }"},
{"-----------", CmdHelp, AlwaysAvailable, "--------------------- " _CYAN_("General") " ---------------------"},
{"help", CmdHelp, AlwaysAvailable, "This help"},
File diff suppressed because it is too large Load Diff
+159
View File
@@ -0,0 +1,159 @@
#include <assert.h>
#include "imgutils.h"
struct ycbcr_t {
int y;
int cb;
int cr;
};
static void rgb_to_ycbcr(int rgb, struct ycbcr_t * ycbcr) {
int r = gdTrueColorGetRed(rgb);
int g = gdTrueColorGetGreen(rgb);
int b = gdTrueColorGetBlue(rgb);
/*
* Below is a fixed-point version of the following code:
* ycbcr->y = r * 0.29900 + g * 0.58700 + b * 0.11400;
* ycbcr->cb = r * -0.16874 + g * -0.33126 + b * 0.50000 + 128;
* ycbcr->cr = r * 0.50000 + g * -0.41869 + b * -0.08131 + 128;
*/
ycbcr->y = (r * 19595 + g * 38470 + b * 7471) / 65536;
ycbcr->cb = (r * -11059 + g * -21709 + b * 32768) / 65536 + 128;
ycbcr->cr = (r * 32768 + g * -27439 + b * -5329) / 65536 + 128;
}
static inline void cap_comp(int * x) {
if (*x < 0) {
*x = 0;
} else if (*x > 255) {
*x = 255;
}
}
/*
* The following function implements a Floyd-Steinberg in YCbCr color space.
*
* Using this colorspace, the Euclidean distance between colors is closer to human perception than
* in sRGB, which results in a more accurate color rendering.
*
* A comparison can be found at https://twitter.com/Socram4x8/status/1733157380097995205/photo/1.
*/
gdImagePtr img_palettize(gdImagePtr rgb, int * palette, int palette_size) {
assert(rgb != NULL);
assert(palette != NULL);
assert(palette_size >= 2 && palette_size < 256);
// Create paletized image
gdImagePtr res = gdImageCreate(gdImageSX(rgb), gdImageSY(rgb));
if (!res) {
return NULL;
}
// Allocate space for palette in YCbCr
struct ycbcr_t * pal_ycbcr = calloc(palette_size, sizeof(struct ycbcr_t));
if (!pal_ycbcr) {
gdImageDestroy(res);
return NULL;
}
/*
* Initialize the column's error array.
*
* Note that we are storing two extra values so we don't have to do boundary checking at
* the left and right edges of the image.
*
* To reduce shifts and increase accuracy, each entry is stored with 16x times the error,
* and gets divided by that amount when it is read.
*/
struct ycbcr_t * forward = calloc(gdImageSX(rgb) + 2, sizeof(struct ycbcr_t));
if (!forward) {
free(pal_ycbcr);
gdImageDestroy(res);
return NULL;
}
// Convert palette to YCbCr and allocate in image
for (int i = 0; i < palette_size; i++) {
int c = palette[i];
rgb_to_ycbcr(c, pal_ycbcr + i);
gdImageColorAllocate(res, gdTrueColorGetRed(c), gdTrueColorGetGreen(c), gdTrueColorGetBlue(c));
}
for (int y = 0; y < gdImageSY(rgb); y++) {
// Load current row error and reset its storage
struct ycbcr_t row_err = forward[1];
forward[1].y = forward[1].cb = forward[1].cr = 0;
for (int x = 0; x < gdImageSX(rgb); x++) {
struct ycbcr_t pix;
rgb_to_ycbcr(gdImageGetTrueColorPixel(rgb, x, y), &pix);
// Add error for current pixel
pix.y += row_err.y / 16;
pix.cb += row_err.cb / 16;
pix.cr += row_err.cr / 16;
// Cap in case it went to imaginary color territory
cap_comp(&pix.y);
cap_comp(&pix.cb);
cap_comp(&pix.cr);
/*
* Iterate through all candidate colors and find the nearest one using the
* squared Euclidean distance.
*/
int best_idx = 0;
struct ycbcr_t best_err = { 0 };
int best_score = 0x7FFFFFFF;
for (int can_idx = 0; can_idx < palette_size; can_idx++) {
struct ycbcr_t can_err = {
.y = pix.y - pal_ycbcr[can_idx].y,
.cb = pix.cb - pal_ycbcr[can_idx].cb,
.cr = pix.cr - pal_ycbcr[can_idx].cr,
};
int can_score = (
can_err.y * can_err.y +
can_err.cb * can_err.cb +
can_err.cr * can_err.cr
);
if (can_score < best_score) {
best_idx = can_idx;
best_score = can_score;
best_err = can_err;
}
}
// Set current pixel
gdImageSetPixel(res, x, y, best_idx);
// Propagate error within the current row, to the pixel to the right
row_err.y = best_err.y * 7 + forward[x + 2].y;
row_err.cb = best_err.cb * 7 + forward[x + 2].cb;
row_err.cr = best_err.cr * 7 + forward[x + 2].cr;
// Add error to bottom left
forward[x + 0].y += best_err.y * 3;
forward[x + 0].cb += best_err.cb * 3;
forward[x + 0].cr += best_err.cr * 3;
// Add error to bottom center
forward[x + 1].y += best_err.y * 5;
forward[x + 1].cb += best_err.cb * 5;
forward[x + 1].cr += best_err.cr * 5;
// Set error to bottom right
forward[x + 2].y = best_err.y * 1;
forward[x + 2].cb = best_err.cb * 1;
forward[x + 2].cr = best_err.cr * 1;
}
}
free(forward);
free(pal_ycbcr);
return res;
}
+25
View File
@@ -0,0 +1,25 @@
//-----------------------------------------------------------------------------
// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// See LICENSE.txt for the text of the license.
//-----------------------------------------------------------------------------
// Image utilities
//-----------------------------------------------------------------------------
#ifndef IMGUTILS_H__
#define IMGUTILS_H__
#include <gd.h>
gdImagePtr img_palettize(gdImagePtr rgb, int * palette, int palette_size);
#endif
@@ -72,6 +72,9 @@ you can skip the installation of `qtbase5-dev`.
👉 If you don't need support for Python3 scripts in the Proxmark3 client,
you can skip the installation of `libpython3-dev`.
👉 If you don't need support for NFC ePaper devices,
you can skip the installation of `libgd-dev`.
### Failed to load module...
⚠️ If you get some (non blocking) error at runtime such as _Gtk-Message: Failed to load module "canberra-gtk-module"_
you may have to install `libcanberra-gtk-module`.
@@ -82,7 +85,7 @@ you may have to install `libcanberra-gtk-module`.
```sh
sudo pacman -Syu git base-devel readline bzip2 lz4 arm-none-eabi-gcc \
arm-none-eabi-newlib qt5-base bluez python --needed
arm-none-eabi-newlib qt5-base bluez python gd --needed
```
### If you don't need...
@@ -95,6 +98,9 @@ you can skip the installation of `qt5-base`.
👉 If you don't need support for Python3 scripts in the Proxmark3 client,
you can skip the installation of `python`.
👉 If you don't need support for NFC ePaper devices,
you can skip the installation of `gd`.
## On Fedora
^[Top](#top)
@@ -102,7 +108,7 @@ you can skip the installation of `python`.
```sh
sudo dnf install git make gcc gcc-c++ arm-none-eabi-gcc-cs arm-none-eabi-newlib \
readline-devel bzip2-devel lz4-devel qt5-qtbase-devel bluez-libs-devel \
python3-devel libatomic openssl-devel
python3-devel libatomic openssl-devel gd-devel
```
### If you don't need...
@@ -115,6 +121,9 @@ you can skip the installation of `qt5-qtbase-devel`.
👉 If you don't need support for Python3 scripts in the Proxmark3 client,
you can skip the installation of `python3-devel`.
👉 If you don't need support for NFC ePaper devices,
you can skip the installation of `gd-devel`.
## On openSUSE
^[Top](#top)
@@ -122,7 +131,8 @@ you can skip the installation of `python3-devel`.
```sh
sudo zypper install git patterns-devel-base-devel_basis gcc-c++ \
readline-devel libbz2-devel liblz4-devel cross-arm-none-gcc9 \
cross-arm-none-newlib-devel python3-devel libqt5-qtbase-devel libopenssl-devel
cross-arm-none-newlib-devel python3-devel libqt5-qtbase-devel \
libopenssl-devel gd-devel
```
Note that Bluez is not available on openSUSE so the native Bluetooth support won't be available in the client.
@@ -134,6 +144,9 @@ you can skip the installation of `libqt5-qtbase-devel`.
👉 If you don't need support for Python3 scripts in the Proxmark3 client,
you can skip the installation of `python3-devel`.
👉 If you don't need support for NFC ePaper devices,
you can skip the installation of `gd-devel`.
# Clone the repository
^[Top](#top)
@@ -169,11 +169,12 @@ Install dependencies:
```sh
sudo apt-get install --no-install-recommends git ca-certificates build-essential pkg-config \
libreadline-dev gcc-arm-none-eabi libnewlib-dev \
libbz2-dev liblz4-dev libpython3-dev qtbase5-dev libssl-dev
libbz2-dev liblz4-dev libpython3-dev qtbase5-dev libssl-dev libgd-dev
```
_note_
If you don't need the graphical components of the Proxmark3 client, you can skip the installation of `qtbase5-dev`.
If you don't need support for Python3 scripts in the Proxmark3 client, you can skip the installation of `libpython3-dev`.
If you don't need support for NFC ePaper devices, you can skip the installation of `libgd-dev`.
## Clone the Iceman repository
^[Top](#top)
@@ -108,12 +108,14 @@ then, install proxmark dependencies:
sudo apt-get install --no-install-recommends \
git ca-certificates build-essential pkg-config \
libreadline-dev gcc-arm-none-eabi libnewlib-dev \
libbz2-dev liblz4-dev libpython3-dev qtbase5-dev libssl-dev
libbz2-dev liblz4-dev libpython3-dev qtbase5-dev \
libssl-dev libgd-dev
```
_note_
If you don't need the graphical components of the Proxmark3 client, you can skip the installation of `qtbase5-dev`.
If you don't need support for Python3 scripts in the Proxmark3 client, you can skip the installation of `libpython3-dev`.
If you don't need support for NFC ePaper devices, you can skip the installation of `libgd-dev`.
## X Server Installation
^[Top](#top)
@@ -161,7 +161,7 @@ These instructions will show how to setup the environment on OSX to the point wh
2. Install dependencies:
```
brew install readline qt5 pkgconfig coreutils
brew install readline qt5 gd pkgconfig coreutils
brew install RfidResearchGroup/proxmark3/arm-none-eabi-gcc
```
3. (optional) Install makefile dependencies:
@@ -61,7 +61,7 @@ These instructions will show how to setup the environment on OSX to the point wh
2. Install dependencies:
```bash
sudo port install readline jansson lua52 python311 bzip2 lz4 openssl11 arm-none-eabi-gcc arm-none-eabi-binutils coreutils qt5 qt5-qtbase pkgconfig
sudo port install readline jansson lua52 python311 bzip2 lz4 openssl11 arm-none-eabi-gcc arm-none-eabi-binutils coreutils qt5 qt5-qtbase gd2 pkgconfig
```
3. Clamp Python version for pkg-config
BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 117 KiB

+1
View File
@@ -535,6 +535,7 @@ while true; do
if ! CheckExecute "emv test" "$CLIENTBIN -c 'emv test'" "Test\(s\) \[ ok"; then break; fi
if ! CheckExecute "hf cipurse test" "$CLIENTBIN -c 'hf cipurse test'" "Tests \[ ok"; then break; fi
if ! CheckExecute "hf mfdes test" "$CLIENTBIN -c 'hf mfdes test'" "Tests \[ ok"; then break; fi
if ! CheckExecute "hf waveshare load" "$CLIENTBIN -c 'hf waveshare load -m 6 -f tools/lena.bmp -s dither.bmp' && echo '34ff55fe7257876acf30dae00eb0e439 dither.bmp' | md5sum -c" "dither.bmp: OK"; then break; fi
fi
echo -e "\n------------------------------------------------------------"
echo -e "Tests [ ${C_GREEN}OK${C_NC} ] ${C_OK}\n"