imgmagick++ kinda works, but its still slow
This commit is contained in:
@ -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 != "") {
|
||||
|
Reference in New Issue
Block a user