Beatmup
sepia.cpp
Go to the documentation of this file.
1 /*
2  Beatmup image and signal processing library
3  Copyright (C) 2020, lnstadrum
4 
5  This program is free software: you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation, either version 3 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18 
19 #include "sepia.h"
20 #include "../bitmap/bitmap_access.h"
21 #include "../bitmap/processing.h"
22 #include <algorithm>
23 
24 using namespace Beatmup;
25 
26 namespace Kernels {
27  /**
28  Application of sepia filter on CPU
29  */
30  template <class in_t, class out_t> class ApplySepia {
31  public:
32  static inline void process(AbstractBitmap& input, AbstractBitmap& output, int x, int y, msize nPix) {
33  in_t in(input, x, y);
34  out_t out(output, x, y);
35  static const pixint3
36  R{ 100, 196, 48 },
37  G{ 89, 175, 43 },
38  B{ 69, 138, 33 };
39 
40  for (msize n = 0; n < nPix; n++) {
41  pixint4 P = (pixint4)in();
42  out.assign(
43  (P.r * R.r + P.g * R.g + P.b * R.b) / 255,
44  (P.r * G.r + P.g * G.g + P.b * G.b) / 255,
45  (P.r * B.r + P.g * B.g + P.b * B.b) / 255,
46  P.a
47  );
48  in++;
49  out++;
50  }
51  }
52  };
53 }
54 
55 
56 void Filters::Sepia::apply(int x, int y, msize nPix, TaskThread& thread) {
57  BitmapProcessing::pipeline<Kernels::ApplySepia>(*inputBitmap, *outputBitmap, x, y, nPix);
58 }
59 
60 
61 std::string Filters::Sepia::getGlslSourceCode() const {
62  return
63  "gl_FragColor = vec4(dot(vec3(100.0/255.0, 196.0/255.0, 48.0/255.0), " + GLSL_RGBA_INPUT + ".rgb)," +
64  "dot(vec3( 89.0/255.0, 175.0/255.0, 43.0/255.0), " + GLSL_RGBA_INPUT + ".rgb)," +
65  "dot(vec3( 69.0/255.0, 138.0/255.0, 33.0/255.0), " + GLSL_RGBA_INPUT + ".rgb)," +
66  GLSL_RGBA_INPUT + ".a);";
67 }
A very basic class for any image.
virtual void apply(int x, int y, msize nPix, TaskThread &thread)
Applies filtering to given pixel data.
Definition: sepia.cpp:56
virtual std::string getGlslSourceCode() const
Provides GLSL source code of the filter.
Definition: sepia.cpp:61
Thread executing tasks.
Definition: parallelism.h:154
Application of sepia filter on CPU.
Definition: sepia.cpp:30
static void process(AbstractBitmap &input, AbstractBitmap &output, int x, int y, msize nPix)
Definition: sepia.cpp:32
uint32_t msize
memory size
Definition: basic_types.h:30
const int B
Definition: bitmap_access.h:31
const int R
Definition: bitmap_access.h:31
const int G
Definition: bitmap_access.h:31
Operations kernels.
Definition: basic_types.h:85
Trichromatic integer arithmetic.
4-channel integer arithmetic
jobject jlong jint jint y
jobject jlong jint x
JNIEnv jlong jint out
int n