Nicolas Winkler 5 years ago
parent
commit
65602dc0f9
5 changed files with 56 additions and 10 deletions
  1. 14 7
      Gradient.cpp
  2. 16 2
      MandelVideoGenerator.cpp
  3. 4 0
      MandelWidget.cpp
  4. 12 1
      VideoStream.cpp
  5. 10 0
      libmandel/include/CpuGenerators.h

+ 14 - 7
Gradient.cpp

@@ -4,10 +4,10 @@ Gradient::Gradient()
 {
     //addColor(RGBColor{255, 0, 0}, -100);
     addColor(RGBColor{0, 0, 0}, 0);
-    addColor(RGBColor{ 37, 116, 153 }, 40);
-    addColor(RGBColor{ 69, 185, 225 }, 104);
-    addColor(RGBColor{ 171, 89, 117 }, 190);
-    addColor(RGBColor{ 102, 127, 46 }, 295);
+    addColor(RGBColor{ 250, 70, 24 }, 40);
+    addColor(RGBColor{ 200, 230, 30 }, 104);
+    addColor(RGBColor{ 70, 223, 30 }, 190);
+    addColor(RGBColor{ 14, 20, 150 }, 295);
     addColor(RGBColor{ 36, 155, 169 }, 418);
     addColor(RGBColor{ 233, 33, 79 }, 558);
     addColor(RGBColor{ 254, 169, 63 }, 714);
@@ -141,10 +141,17 @@ RGBColor Gradient::get(float x) const
 
 RGBColor Gradient::lerpColors(RGBColor a, RGBColor b, float val)
 {
+    auto mklin = [] (double x) {
+        return x;//::pow(x, 2.4);
+    };
+    auto unlin = [] (double x) {
+        return x;// ::pow(x, 1.0 / 2.4);
+    };
+
     return RGBColor{
-        uint8_t(b.r * val + a.r * (1 - val)),
-        uint8_t(b.g * val + a.g * (1 - val)),
-        uint8_t(b.b * val + a.b * (1 - val))
+        uint8_t(unlin(mklin(b.r) * val + mklin(a.r) * (1 - val))),
+        uint8_t(unlin(mklin(b.g) * val + mklin(a.g) * (1 - val))),
+        uint8_t(unlin(mklin(b.b) * val + mklin(a.b) * (1 - val)))
     };
 }
 

+ 16 - 2
MandelVideoGenerator.cpp

@@ -36,6 +36,7 @@ void MandelVideoGenerator::generate(void)
         if (bigW > 2 * w) {
             Bitmap<float> raw{ evi.width * 2, evi.height * 2 };
             gen.generate(mi, raw.pixels.get());
+            auto before = std::chrono::high_resolution_clock::now();
             big = raw.map<RGBColor>([&mi, this] (float i) {
                 return i >= mi.maxIter ? RGBColor{ 0,0,0 } : evi.gradient.get(i);
             });
@@ -81,10 +82,10 @@ inline RGBColor biliniear(const Bitmap<RGBColor>& img, double x, double y)
     double r = 0, g = 0, b = 0;
 
     auto mklin = [] (double x) {
-        return ::pow(x, 2.4);
+        return x;
     };
     auto unlin = [] (double x) {
-        return ::pow(x, 1.0 / 2.4);
+        return x;
     };
 
     r += (1 - xLerp) * (1 - yLerp) * mklin(samples[0][0].r);
@@ -106,6 +107,14 @@ inline RGBColor biliniear(const Bitmap<RGBColor>& img, double x, double y)
 }
 
 
+inline RGBColor nearest(const Bitmap<RGBColor>& img, double x, double y)
+{
+    int xfloor = int(::floor(x));
+    int yfloor = int(::floor(y));
+    return img.get(xfloor, yfloor);
+}
+
+
 Bitmap<RGBColor> MandelVideoGenerator::overlay(const Bitmap<RGBColor>& outer,
                          const Bitmap<RGBColor>& inner, double scale)
 {
@@ -116,6 +125,8 @@ Bitmap<RGBColor> MandelVideoGenerator::overlay(const Bitmap<RGBColor>& outer,
     double newX = outer.width * (1 - scale) / 2;
     double newY = outer.height * (1 - scale) / 2;
 
+    auto before = std::chrono::high_resolution_clock::now();
+#pragma omp parallel for
     for (int i = 0; i < ret.height; i++) {
         for (int j = 0; j < ret.width; j++) {
             double newJ = newX + j * newW / outer.width;
@@ -124,6 +135,9 @@ Bitmap<RGBColor> MandelVideoGenerator::overlay(const Bitmap<RGBColor>& outer,
             ret.get(j, i) = a;
         }
     }
+    auto after = std::chrono::high_resolution_clock::now();
+    printf("gradient applied in: %lld microseconds\n", std::chrono::duration_cast<std::chrono::microseconds>(after - before).count());
+    fflush(stdout);
     /*for (int i = 0; i < ret.height * ret.width; i++) {
         ret.pixels[i] = outer.pixels[i];
     }*/

+ 4 - 0
MandelWidget.cpp

@@ -246,6 +246,10 @@ void MandelWidget::initializeGL(void)
     qglClearColor(Qt::black);
 
     glDisable(GL_DEPTH_TEST);
+
+    // looks not even better
+    glDisable(GL_FRAMEBUFFER_SRGB);
+
     //glShadeModel(GL_SMOOTH);
 
     /*CpuGenerator<double> cpg;

+ 12 - 1
VideoStream.cpp

@@ -39,7 +39,7 @@ VideoStream::VideoStream(int width, int height, const std::string& filename) :
     codecContext->time_base = AVRational{ 1, 60 };
     codecContext->framerate = AVRational{ 60, 1 };
 
-    codecContext->gop_size = 10; /* emit one intra frame every ten frames */
+    codecContext->gop_size = 5; /* emit one intra frame every five frames */
     codecContext->max_b_frames = 1;
     codecContext->pix_fmt = AV_PIX_FMT_YUV420P;
 
@@ -166,6 +166,17 @@ void VideoStream::addFrame(const Bitmap<RGBColor>& frame)
         }
     }*/
 
+    /*auto gammaCorrect = [] (const RGBColor& rgb) {
+        const float gamma = 2.2f;
+        return RGBColor {
+            uint8_t(::powf(rgb.r / 255.0f, 1.0f / gamma) * 255),
+            uint8_t(::powf(rgb.g / 255.0f, 1.0f / gamma) * 255),
+            uint8_t(::powf(rgb.b / 255.0f, 1.0f / gamma) * 255),
+        };
+    };
+
+    Bitmap<RGBColor> gammaCorrected = frame.map<RGBColor>(gammaCorrect);*/
+
     const uint8_t* pixelPointer[] = { reinterpret_cast<const uint8_t*>(frame.pixels.get()), 0 };
     const int linesizeIn[] = { int(frame.width * sizeof(RGBColor)) };
 

+ 10 - 0
libmandel/include/CpuGenerators.h

@@ -5,6 +5,16 @@
 
 namespace mnd
 {
+    enum CpuExtension
+    {
+        X86_SSE2,
+        X86_AVX,
+        ARM_NEON,
+    };
+
+    template<typename T, CpuExtension ex, bool parallel>
+    class CpuGenerator;
+
     class CpuGeneratorFloat;
     class CpuGeneratorDouble;
     class CpuGenerator128;