imgmagick++ kinda works, but its still slow

This commit is contained in:
Tanishq Dubey 2024-05-12 21:21:17 -04:00
parent 293a814ad3
commit ebf910165f
4 changed files with 40 additions and 14 deletions

View File

@ -21,11 +21,11 @@ SOURCES += $(wildcard $(IMGUI_DIR)/*.cpp)
SOURCES += $(wildcard $(IMGUI_DIR)/backends/*.cpp)
OBJS = $(addsuffix .o, $(basename $(notdir $(SOURCES))))
UNAME_S := $(shell uname -s)
LINUX_GL_LIBS = -lGL
LINUX_GL_LIBS = -lGL
CXXFLAGS = -std=c++20 -I$(IMGUI_DIR) -I$(IMGUI_DIR)/backends
CXXFLAGS += -g -DIMGUI_DEFINE_MATH_OPERATORS -Ofast
LIBS =
CXXFLAGS += -g -DIMGUI_DEFINE_MATH_OPERATORS -Ofast -Xpreprocessor -fopenmp -DMAGICKCORE_HDRI_ENABLE=1 -DMAGICKCORE_QUANTUM_DEPTH=16 -DMAGICKCORE_CHANNEL_MASK_DEPTH=32 -I/opt/homebrew/Cellar/imagemagick/7.1.1-32/include/ImageMagick-7
LIBS = -L/opt/homebrew/Cellar/imagemagick/7.1.1-32/lib -lMagick++-7.Q16HDRI -lMagickWand-7.Q16HDRI -lMagickCore-7.Q16HDRI
##---------------------------------------------------------------------
## OPENGL ES

View File

@ -27,6 +27,11 @@
#include <cstdint>
#include <iostream>
#include <ImageMagick-7/Magick++.h>
#include <chrono>
using namespace std::chrono;
#ifdef __EMSCRIPTEN__
#include "../emscripten_browser_file.h"
#endif
@ -234,16 +239,34 @@ private:
return static_cast<int>(ret_val);
}
void adjustContrast(uint8_t *pixels, uint8_t *out, int width, int height,
double contrastValue) {
// Initialize Magick library
Magick::InitializeMagick(nullptr);
// Create a Magick::Image object from the uint8_t* data
Magick::Image image(width, height, "RGBA", Magick::CharPixel, pixels);
// Apply contrast adjustment
auto start = high_resolution_clock::now();
image.sigmoidalContrast(true, contrastValue); // Increase contrast
auto stop = high_resolution_clock::now();
auto duration = duration_cast<microseconds>(stop - start);
std::cout << duration.count() << std::endl;
start = high_resolution_clock::now();
Magick::Blob blob;
image.write(&blob);
memcpy(out, blob.data(), width * height * 4);
stop = high_resolution_clock::now();
duration = duration_cast<microseconds>(stop - start);
std::cout << duration.count() << std::endl;
}
void compute(uint8_t *input, uint8_t *output, int size, int channels) {
int nBval = brightnessVal + 256;
for (int i = 0; i < size; i += channels) {
uint8_t r = std::clamp(formula(input[i], brightnessVal), 0, 255);
uint8_t g = std::clamp(formula(input[i + 1], brightnessVal), 0, 255);
uint8_t b = std::clamp(formula(input[i + 2], brightnessVal), 0, 255);
output[i] = r;
output[i + 1] = g;
output[i + 2] = b;
}
adjustContrast(input, output, returnBundle.width, returnBundle.height,
nBval);
}
int brightnessVal = 0;
@ -467,8 +490,8 @@ public:
}
#else
if (bundle.fname == "") {
handle_upload_file_local(
"/Users/tanishqdubey/Downloads/Odd-eyed_cat_by_ihasb33r.jpg", this);
handle_upload_file_local("/Users/tanishqdubey/Pictures/DSC06956.JPG",
this);
}
#endif
if (bundle.fname != "") {

View File

@ -44,11 +44,12 @@
#endif
#include "lib/ImNodeFlow.h"
#include <ImageMagick-7/Magick++.h>
static bool init = true;
// Main code
int main(int, char **) {
int main(int, char **argv) {
// Setup SDL
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_GAMECONTROLLER) !=
0) {
@ -56,6 +57,8 @@ int main(int, char **) {
return -1;
}
Magick::InitializeMagick(*argv);
// Decide GL+GLSL versions
#if defined(IMGUI_IMPL_OPENGL_ES2)
// GL ES 2.0 + GLSL 100

BIN
ppdnode

Binary file not shown.