imgmagick++ kinda works, but its still slow
This commit is contained in:
parent
293a814ad3
commit
ebf910165f
6
Makefile
6
Makefile
@ -21,11 +21,11 @@ SOURCES += $(wildcard $(IMGUI_DIR)/*.cpp)
|
|||||||
SOURCES += $(wildcard $(IMGUI_DIR)/backends/*.cpp)
|
SOURCES += $(wildcard $(IMGUI_DIR)/backends/*.cpp)
|
||||||
OBJS = $(addsuffix .o, $(basename $(notdir $(SOURCES))))
|
OBJS = $(addsuffix .o, $(basename $(notdir $(SOURCES))))
|
||||||
UNAME_S := $(shell uname -s)
|
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 = -std=c++20 -I$(IMGUI_DIR) -I$(IMGUI_DIR)/backends
|
||||||
CXXFLAGS += -g -DIMGUI_DEFINE_MATH_OPERATORS -Ofast
|
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 =
|
LIBS = -L/opt/homebrew/Cellar/imagemagick/7.1.1-32/lib -lMagick++-7.Q16HDRI -lMagickWand-7.Q16HDRI -lMagickCore-7.Q16HDRI
|
||||||
|
|
||||||
##---------------------------------------------------------------------
|
##---------------------------------------------------------------------
|
||||||
## OPENGL ES
|
## OPENGL ES
|
||||||
|
@ -27,6 +27,11 @@
|
|||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
#include <ImageMagick-7/Magick++.h>
|
||||||
|
|
||||||
|
#include <chrono>
|
||||||
|
using namespace std::chrono;
|
||||||
|
|
||||||
#ifdef __EMSCRIPTEN__
|
#ifdef __EMSCRIPTEN__
|
||||||
#include "../emscripten_browser_file.h"
|
#include "../emscripten_browser_file.h"
|
||||||
#endif
|
#endif
|
||||||
@ -234,16 +239,34 @@ private:
|
|||||||
return static_cast<int>(ret_val);
|
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) {
|
void compute(uint8_t *input, uint8_t *output, int size, int channels) {
|
||||||
int nBval = brightnessVal + 256;
|
int nBval = brightnessVal + 256;
|
||||||
for (int i = 0; i < size; i += channels) {
|
adjustContrast(input, output, returnBundle.width, returnBundle.height,
|
||||||
uint8_t r = std::clamp(formula(input[i], brightnessVal), 0, 255);
|
nBval);
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int brightnessVal = 0;
|
int brightnessVal = 0;
|
||||||
@ -467,8 +490,8 @@ public:
|
|||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
if (bundle.fname == "") {
|
if (bundle.fname == "") {
|
||||||
handle_upload_file_local(
|
handle_upload_file_local("/Users/tanishqdubey/Pictures/DSC06956.JPG",
|
||||||
"/Users/tanishqdubey/Downloads/Odd-eyed_cat_by_ihasb33r.jpg", this);
|
this);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if (bundle.fname != "") {
|
if (bundle.fname != "") {
|
||||||
|
5
main.cpp
5
main.cpp
@ -44,11 +44,12 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "lib/ImNodeFlow.h"
|
#include "lib/ImNodeFlow.h"
|
||||||
|
#include <ImageMagick-7/Magick++.h>
|
||||||
|
|
||||||
static bool init = true;
|
static bool init = true;
|
||||||
|
|
||||||
// Main code
|
// Main code
|
||||||
int main(int, char **) {
|
int main(int, char **argv) {
|
||||||
// Setup SDL
|
// Setup SDL
|
||||||
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_GAMECONTROLLER) !=
|
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_GAMECONTROLLER) !=
|
||||||
0) {
|
0) {
|
||||||
@ -56,6 +57,8 @@ int main(int, char **) {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Magick::InitializeMagick(*argv);
|
||||||
|
|
||||||
// Decide GL+GLSL versions
|
// Decide GL+GLSL versions
|
||||||
#if defined(IMGUI_IMPL_OPENGL_ES2)
|
#if defined(IMGUI_IMPL_OPENGL_ES2)
|
||||||
// GL ES 2.0 + GLSL 100
|
// GL ES 2.0 + GLSL 100
|
||||||
|
Loading…
x
Reference in New Issue
Block a user