Beatmup
bitmap_access.h
Go to the documentation of this file.
1 /*
2  Beatmup image and signal processing library
3  Copyright (C) 2019, 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 #pragma once
20 #include "abstract_bitmap.h"
21 #include "../exception.h"
22 #include "pixel_arithmetic.h"
23 
24 namespace Beatmup {
25 
26  /**
27  \internal
28  Color channel order specification for 4-channel images.
29  */
30  static const struct {
31  const int A, R, G, B;
32  } CHANNELS_4 = {
33  #ifdef BEATMUP_CHANNEL_ORDER_ARGB
34  0, 1, 2, 3
35  #elif BEATMUP_CHANNEL_ORDER_BGRA
36  3, 2, 1, 0
37  #else // rgba
38  3, 0, 1, 2
39  #endif
40  };
41 
42  /**
43  \internal
44  Color channel order specification for 3-channel images.
45  */
46  static const struct {
47  const int R, G, B;
48  } CHANNELS_3 = {
49  #ifdef BEATMUP_CHANNEL_ORDER_ARGB
50  0, 1, 2
51  #elif BEATMUP_CHANNEL_ORDER_BGRA
52  2, 1, 0
53  #else // rgba
54  0, 1, 2
55  #endif
56  };
57 
59  protected:
61  };
62 
63  /**
64  A generic to access bitmap data
65  */
66  template<typename pixel, const int num_channels> class CustomBitmapScanner {
67  protected:
68  pixel* data; //!< bitmap data
69  pixel* ptr; //!< pointer to the current pixel
70  int width, height; //!< bitmap sizes in pixels
71 
72  /**
73  Retrieves pixel address at a given position;
74  */
75  inline pixel* jump(int x, int y) const {
76  return data + num_channels*(width*y + x);
77  }
78  public:
79  typedef pixel pixvaltype;
80 
81  const int NUMBER_OF_CHANNELS = num_channels;
82 
83  bool operator < (const CustomBitmapScanner& another) const {
84  return ptr < another.ptr;
85  }
86 
87  pixel* operator*() const {
88  return ptr;
89  }
90 
91  /**
92  Move the current position ONE PIXEL forward
93  */
94  inline void operator++(int) {
95  // int argument here is to declare the postfix increment (a C++ convention)
96  ptr += num_channels;
97  }
98 
99  /**
100  Move the current position N pixels forward
101  */
102  inline void operator+=(const int n) {
103  ptr += num_channels * n;
104  }
105 
106  /**
107  Changes current position
108  */
109  inline void goTo(int x, int y) {
110 #ifdef BEATMUP_DEBUG
111  DebugAssertion::check(x >= 0 && y >= 0 && x < width && y < height, "Coordinates outside of image: %d %d (width=%d, height=%d)", x, y, width, height);
112 #endif
113  ptr = data + num_channels*(width*y + x);
114  }
115 
116  /**
117  Returns bitmap width in pixels
118  */
119  inline int getWidth() const {
120  return width;
121  }
122 
123  /**
124  Returns bitmap height in pixels
125  */
126  inline int getHeight() const {
127  return height;
128  }
129 
130  CustomBitmapScanner(const AbstractBitmap& bitmap, int x = 0, int y = 0) {
131 #ifdef BEATMUP_DEBUG
132  DebugAssertion::check(
133  bitmap.getBitsPerPixel() == 8* num_channels * sizeof(pixel),
134  "Invalid bitmap scanner"
135  );
136 #endif
137  width = bitmap.getWidth();
138  height = bitmap.getHeight();
139  data = (pixel*)bitmap.getData(0, 0);
140  goTo(x, y);
141  }
142  };
143 
144  /**
145  Single byte bitmap reader
146  */
147  class SingleByteBitmapReader : public CustomBitmapScanner<pixbyte, 1> {
148  public:
149  typedef pixint1 pixtype;
150 
151  const int MAX_VALUE = 255;
152 
153  /**
154  Returns value at current position
155  */
156  inline pixint1 operator()() const {
157  return pixint1{ *ptr };
158  }
159 
160  /**
161  Returns value at pixel (x,y) position
162  */
163  inline pixint1 operator()(int x, int y) const {
164  return pixint1{ data[y * width + x] };
165  }
166 
167  /**
168  Retrieves a value at position shifted by i pixels in scanline order with respect to the current position
169  */
170  inline const pixint1 operator[](int i) const {
171  return pixint1{ ptr[i] };
172  }
173 
175  };
176 
177 
178  /**
179  Triple byte bitmap reader
180  */
181  class TripleByteBitmapReader : public CustomBitmapScanner<pixbyte, 3> {
182  public:
183  typedef pixint3 pixtype;
184 
185  const int MAX_VALUE = 255;
186 
187  inline pixint3 operator()() const {
188  return pixint3{ ptr[CHANNELS_3.R], ptr[CHANNELS_3.G], ptr[CHANNELS_3.B] };
189  }
190 
191  inline pixint3 operator()(int x, int y) const {
192  int i = 3 * (y * width + x);
193  return pixint3{ data[i + CHANNELS_3.R], data[i + CHANNELS_3.G], data[i + CHANNELS_3.B] };
194  }
195 
196  /**
197  Retrieves a value at position shifted by i pixels in scanline order with respect to the current position
198  */
199  inline const pixint3 operator[](int i) const {
200  const pixbyte* p = ptr + 3 * i;
201  return pixint3{ p[CHANNELS_3.R], p[CHANNELS_3.G], p[CHANNELS_3.B] };
202  }
203 
205  };
206 
207 
208  /**
209  Quad byte bitmap reader
210  */
211  class QuadByteBitmapReader : public CustomBitmapScanner<pixbyte, 4> {
212  public:
213  typedef pixint4 pixtype;
214 
215  const int MAX_VALUE = 255;
216 
217  inline pixint4 operator()() const {
219  }
220 
221  inline pixint4 operator()(int x, int y) const {
222  int i = 4 * (y * width + x);
223  return pixint4(data[i + CHANNELS_4.R], data[i + CHANNELS_4.G], data[i + CHANNELS_4.B], data[i + CHANNELS_4.A]);
224  }
225 
226  /**
227  Retrieves a value at position shifted by i pixels in scanline order with respect to the current position
228  */
229  inline const pixint4 operator[](int i) const {
230  const pixbyte* p = ptr + 4 * i;
231  return pixint4(p[CHANNELS_4.R], p[CHANNELS_4.G], p[CHANNELS_4.B], p[CHANNELS_4.A]);
232  }
233 
235  };
236 
237 
238  /**
239  Single float bitmap reader
240  */
241  class SingleFloatBitmapReader : public CustomBitmapScanner<pixfloat, 1> {
242  public:
244 
245  const float MAX_VALUE = 1.0f;
246 
247  inline pixfloat1 operator()() const {
248  return pixfloat1{ *ptr };
249  }
250 
251  inline pixfloat1 operator()(int x, int y) const {
252  return pixfloat1{ data[y * width + x] };
253  }
254 
255  /**
256  Retrieves a value at position shifted by i pixels in scanline order with respect to the current position
257  */
258  inline const pixfloat1 operator[](int i) const {
259  return pixfloat1{ ptr[i] };
260  }
261 
263  };
264 
265 
266  /**
267  Triple float bitmap reader
268  */
269  class TripleFloatBitmapReader : public CustomBitmapScanner<pixfloat, 3> {
270  public:
272 
273  const float MAX_VALUE = 1.0f;
274 
275  inline pixfloat3 operator()() const {
276  return pixfloat3{ ptr[CHANNELS_3.R], ptr[CHANNELS_3.G], ptr[CHANNELS_3.B] };
277  }
278 
279  inline pixfloat3 operator()(int x, int y) const {
280  int i = 3 * (y * width + x);
281  return pixfloat3{ data[i + CHANNELS_3.R], data[i + CHANNELS_3.G], data[i + CHANNELS_3.B] };
282  }
283 
284  /**
285  Retrieves a value at position shifted by i pixels in scanline order with respect to the current position
286  */
287  inline const pixfloat3 operator[](int i) const {
288  const pixfloat* p = ptr + 3 * i;
289  return pixfloat3{ p[CHANNELS_3.R], p[CHANNELS_3.G], p[CHANNELS_3.B] };
290  }
291 
292 
294  };
295 
296 
297  /**
298  Quad float bitmap reader
299  */
300  class QuadFloatBitmapReader : public CustomBitmapScanner<pixfloat, 4> {
301  public:
303 
304  const float MAX_VALUE = 1.0f;
305 
306  inline pixfloat4 operator()() const {
308  }
309 
310  inline pixfloat4 operator()(int x, int y) const {
311  int i = 4 * (y * width + x);
312  return pixfloat4(data[i + CHANNELS_4.R], data[i + CHANNELS_4.G], data[i + CHANNELS_4.B], data[i + CHANNELS_4.A]);
313  }
314 
315  inline pixfloat4 at(int x, int y) const {
316  int i = 4 * (y * width + x);
317  return pixfloat4(ptr[i + CHANNELS_4.R], ptr[i + CHANNELS_4.G], ptr[i + CHANNELS_4.B], ptr[i + CHANNELS_4.A]);
318  }
319 
320  /**
321  Retrieves a value at position shifted by i pixels in scanline order with respect to the current position
322  */
323  inline const pixfloat4 operator[](int i) const {
324  const pixfloat* p = ptr + 4 * i;
325  return pixfloat4(p[CHANNELS_4.R], p[CHANNELS_4.G], p[CHANNELS_4.B], p[CHANNELS_4.A]);
326  }
327 
328 
330  };
331 
332 
333  /**
334  Single byte bitmap writer
335  */
337  public:
338  inline void assign(int x) {
339  *ptr = clipPixint(x);
340  }
341 
342  inline void assign(int r, int g, int b) {
343  *ptr = clipPixint((r + g + b) / 3);
344  }
345 
346  inline void assign(int r, int g, int b, int a) {
347  *ptr = clipPixint((r + g + b) / 3);
348  }
349 
350  inline void assign(float x) {
351  *ptr = pixfloat2pixbyte(x);
352  }
353 
354  inline void assign(float r, float g, float b) {
355  *ptr = pixfloat2pixbyte((r + g + b) / 3);
356  }
357 
358  inline void assign(float r, float g, float b, float a) {
359  *ptr = pixfloat2pixbyte((r + g + b) / 3);
360  }
361 
362  inline void operator<<(const pixint1& P) {
363  assign(P.x);
364  }
365 
366  inline void operator<<(const pixint3& P) {
367  assign(P.r, P.g, P.b);
368  }
369 
370  inline void operator<<(const pixint4& P) {
371  *ptr = clipPixint(((P.r + P.g + P.b) * P.a + *ptr * (255 - P.a) * 3) / 765);
372  }
373 
374  inline void operator<<(const pixfloat1& P) {
375  assign(P.x);
376  }
377 
378  inline void operator<<(const pixfloat3& P) {
379  assign(P.r, P.g, P.b);
380  }
381 
382  inline void operator<<(const pixfloat4& P) {
383  *ptr = pixfloat2pixbyte((P.r + P.g + P.b) * P.a / 3 + *ptr * (1 - P.a));
384  }
385 
386  inline void operator=(const pixint1& P) {
387  assign(P.x);
388  }
389 
390  inline void operator=(const pixint3& P) {
391  assign(P.r, P.g, P.b);
392  }
393 
394  inline void operator=(const pixint4& P) {
395  assign(P.r, P.g, P.b, P.a);
396  }
397 
398  inline void operator=(const pixfloat1& P) {
399  assign(P.x);
400  }
401 
402  inline void operator=(const pixfloat3& P) {
403  assign(P.r, P.g, P.b);
404  }
405 
406  inline void operator=(const pixfloat4& P) {
407  assign(P.r, P.g, P.b, P.a);
408  }
409 
411  };
412 
413 
414  /**
415  Triple byte bitmap writer
416  */
418  public:
419  inline void assign(int x) {
421  }
422 
423  inline void assign(int r, int g, int b) {
424  ptr[CHANNELS_3.R] = clipPixint(r);
425  ptr[CHANNELS_3.G] = clipPixint(g);
426  ptr[CHANNELS_3.B] = clipPixint(b);
427  }
428 
429  inline void assign(int r, int g, int b, int a) {
430  ptr[CHANNELS_3.R] = clipPixint(r);
431  ptr[CHANNELS_3.G] = clipPixint(g);
432  ptr[CHANNELS_3.B] = clipPixint(b);
433  }
434 
435  inline void assign(float x) {
437  }
438 
439  inline void assign(float r, float g, float b) {
443  }
444 
445  inline void assign(float r, float g, float b, float a) {
449  }
450 
451  inline void operator<<(const pixint1& P) {
452  assign(P.x);
453  }
454 
455  inline void operator<<(const pixint3& P) {
456  assign(P.r, P.g, P.b);
457  }
458 
459  inline void operator<<(const pixint4& P) {
460  ptr[CHANNELS_3.R] = clipPixint((P.r * P.a + ptr[CHANNELS_3.R] * (255 - P.a)) / 255);
461  ptr[CHANNELS_3.G] = clipPixint((P.g * P.a + ptr[CHANNELS_3.G] * (255 - P.a)) / 255);
462  ptr[CHANNELS_3.B] = clipPixint((P.b * P.a + ptr[CHANNELS_3.B] * (255 - P.a)) / 255);
463  }
464 
465  inline void operator<<(const pixfloat1& P) {
466  assign(P.x);
467  }
468 
469  inline void operator<<(const pixfloat3& P) {
470  assign(P.r, P.g, P.b);
471  }
472 
473  inline void operator<<(const pixfloat4& P) {
474  float _a = (1 - P.a) / 255;
475  ptr[CHANNELS_3.R] = pixfloat2pixbyte(P.r * P.a + ptr[CHANNELS_3.R] * _a);
476  ptr[CHANNELS_3.G] = pixfloat2pixbyte(P.g * P.a + ptr[CHANNELS_3.G] * _a);
477  ptr[CHANNELS_3.B] = pixfloat2pixbyte(P.b * P.a + ptr[CHANNELS_3.B] * _a);
478  }
479 
480  inline void operator=(const pixint1& P) {
481  assign(P.x);
482  }
483 
484  inline void operator=(const pixint3& P) {
485  assign(P.r, P.g, P.b);
486  }
487 
488  inline void operator=(const pixint4& P) {
489  assign(P.r, P.g, P.b, P.a);
490  }
491 
492  inline void operator=(const pixfloat1& P) {
493  assign(P.x);
494  }
495 
496  inline void operator=(const pixfloat3& P) {
497  assign(P.r, P.g, P.b);
498  }
499 
500  inline void operator=(const pixfloat4& P) {
501  assign(P.r, P.g, P.b, P.a);
502  }
503 
505  };
506 
507 
508  /**
509  Quad byte bitmap writer
510  */
512  public:
513  inline void assign(int x) {
515  ptr[CHANNELS_4.A] = 255;
516  }
517 
518  inline void assign(int r, int g, int b) {
519  ptr[CHANNELS_4.R] = clipPixint(r);
520  ptr[CHANNELS_4.G] = clipPixint(g);
521  ptr[CHANNELS_4.B] = clipPixint(b);
522  ptr[CHANNELS_4.A] = 255;
523  }
524 
525  inline void assign(int r, int g, int b, int a) {
526  ptr[CHANNELS_4.R] = clipPixint(r);
527  ptr[CHANNELS_4.G] = clipPixint(g);
528  ptr[CHANNELS_4.B] = clipPixint(b);
529  ptr[CHANNELS_4.A] = clipPixint(a);
530  }
531 
532  inline void assign(float x) {
534  ptr[CHANNELS_4.A] = 255;
535  }
536 
537  inline void assign(float r, float g, float b) {
541  ptr[CHANNELS_4.A] = 255;
542  }
543 
544  inline void assign(float r, float g, float b, float a) {
549  }
550 
551  inline void operator<<(const pixint1& P) {
552  assign(P.x);
553  }
554 
555  inline void operator<<(const pixint3& P) {
556  assign(P.r, P.g, P.b);
557  }
558 
559  inline void operator<<(const pixint4& P) {
560  int _a = 255 - P.a;
561  ptr[CHANNELS_4.R] = clipPixint(P.r + ptr[CHANNELS_4.R] * _a / 255);
562  ptr[CHANNELS_4.G] = clipPixint(P.g + ptr[CHANNELS_4.G] * _a / 255);
563  ptr[CHANNELS_4.B] = clipPixint(P.b + ptr[CHANNELS_4.B] * _a / 255);
564  ptr[CHANNELS_4.A] = clipPixint(255 - _a*(255 - ptr[CHANNELS_4.A]) / 255);
565  }
566 
567  inline void operator<<(const pixfloat1& P) {
568  assign(P.x);
569  }
570 
571  inline void operator<<(const pixfloat3& P) {
572  assign(P.r, P.g, P.b);
573  }
574 
575  inline void operator<<(const pixfloat4& P) {
576  float _a = (1 - P.a) / 255;
577  ptr[CHANNELS_4.R] = pixfloat2pixbyte(P.r + ptr[CHANNELS_4.R] * _a);
578  ptr[CHANNELS_4.G] = pixfloat2pixbyte(P.g + ptr[CHANNELS_4.G] * _a);
579  ptr[CHANNELS_4.B] = pixfloat2pixbyte(P.b + ptr[CHANNELS_4.B] * _a);
580  ptr[CHANNELS_4.A] = pixfloat2pixbyte(1 - _a * (255 - ptr[CHANNELS_4.B]) / 255);
581  }
582 
583  inline void operator=(const pixint1& P) {
584  assign(P.x);
585  }
586 
587  inline void operator=(const pixint3& P) {
588  assign(P.r, P.g, P.b);
589  }
590 
591  inline void operator=(const pixint4& P) {
592  assign(P.r, P.g, P.b, P.a);
593  }
594 
595  inline void operator=(const pixfloat1& P) {
596  assign(P.x);
597  }
598 
599  inline void operator=(const pixfloat3& P) {
600  assign(P.r, P.g, P.b);
601  }
602 
603  inline void operator=(const pixfloat4& P) {
604  assign(P.r, P.g, P.b, P.a);
605  }
606 
608  };
609 
610 
611  /**
612  Single float bitmap writer
613  */
615  public:
616  inline void assign(int x) {
617  *ptr = int2pixfloat(x);
618  }
619 
620  inline void assign(int r, int g, int b) {
621  *ptr = int2pixfloat((r + g + b) / 3);
622  }
623 
624  inline void assign(int r, int g, int b, int a) {
625  *ptr = int2pixfloat((r + g + b) / 3);
626  }
627 
628  inline void assign(float x) {
629  *ptr = clipPixfloat(x);
630  }
631 
632  inline void assign(float r, float g, float b) {
633  *ptr = clipPixfloat((r + g + b) / 3);
634  }
635 
636  inline void assign(float r, float g, float b, float a) {
637  *ptr = clipPixfloat((r + g + b) / 3);
638  }
639 
640  inline void operator<<(const pixint1& P) {
641  assign(P.x);
642  }
643 
644  inline void operator<<(const pixint3& P) {
645  assign(P.r, P.g, P.b);
646  }
647 
648  inline void operator<<(const pixint4& P) {
649  *ptr = clipPixfloat(((P.r + P.g + P.b) * P.a + *ptr * (255 - P.a) * 3) / 765.0f);
650  }
651 
652  inline void operator<<(const pixfloat1& P) {
653  assign(P.x);
654  }
655 
656  inline void operator<<(const pixfloat3& P) {
657  assign(P.r, P.g, P.b);
658  }
659 
660  inline void operator<<(const pixfloat4& P) {
661  *ptr = clipPixfloat((P.r + P.g + P.b) * P.a + *ptr * (1 - P.a));
662  }
663 
664  inline void operator=(const pixint1& P) {
665  assign(P.x);
666  }
667 
668  inline void operator=(const pixint3& P) {
669  assign(P.r, P.g, P.b);
670  }
671 
672  inline void operator=(const pixint4& P) {
673  assign(P.r, P.g, P.b, P.a);
674  }
675 
676  inline void operator=(const pixfloat1& P) {
677  assign(P.x);
678  }
679 
680  inline void operator=(const pixfloat3& P) {
681  assign(P.r, P.g, P.b);
682  }
683 
684  inline void operator=(const pixfloat4& P) {
685  assign(P.r, P.g, P.b, P.a);
686  }
687 
689  };
690 
691 
692  /**
693  Triple float bitmap writer
694  */
696  public:
697  inline void assign(int x) {
699  }
700 
701  inline void assign(int r, int g, int b) {
705  }
706 
707  inline void assign(int r, int g, int b, int a) {
711  }
712 
713  inline void assign(float x) {
715  }
716 
717  inline void assign(float r, float g, float b) {
721  }
722 
723  inline void assign(float r, float g, float b, float a) {
727  }
728  inline void operator<<(const pixint1& P) {
729  assign(P.x);
730  }
731 
732  inline void operator<<(const pixint3& P) {
733  assign(P.r, P.g, P.b);
734  }
735 
736  inline void operator<<(const pixint4& P) {
737  ptr[CHANNELS_3.R] = clipPixfloat((P.r * P.a + ptr[CHANNELS_3.R] * (255 - P.a)) / 65025.0f);
738  ptr[CHANNELS_3.G] = clipPixfloat((P.g * P.a + ptr[CHANNELS_3.G] * (255 - P.a)) / 65025.0f);
739  ptr[CHANNELS_3.B] = clipPixfloat((P.b * P.a + ptr[CHANNELS_3.B] * (255 - P.a)) / 65025.0f);
740  }
741 
742  inline void operator<<(const pixfloat1& P) {
743  assign(P.x);
744  }
745 
746  inline void operator<<(const pixfloat3& P) {
747  assign(P.r, P.g, P.b);
748  }
749 
750  inline void operator<<(const pixfloat4& P) {
751  float _a = 1 - P.a;
752  ptr[CHANNELS_3.R] = clipPixfloat(P.r * P.a + ptr[CHANNELS_3.R] * _a);
753  ptr[CHANNELS_3.G] = clipPixfloat(P.g * P.a + ptr[CHANNELS_3.G] * _a);
754  ptr[CHANNELS_3.B] = clipPixfloat(P.b * P.a + ptr[CHANNELS_3.B] * _a);
755  }
756 
757  inline void operator=(const pixint1& P) {
758  assign(P.x);
759  }
760 
761  inline void operator=(const pixint3& P) {
762  assign(P.r, P.g, P.b);
763  }
764 
765  inline void operator=(const pixint4& P) {
766  assign(P.r, P.g, P.b, P.a);
767  }
768 
769  inline void operator=(const pixfloat1& P) {
770  assign(P.x);
771  }
772 
773  inline void operator=(const pixfloat3& P) {
774  assign(P.r, P.g, P.b);
775  }
776 
777  inline void operator=(const pixfloat4& P) {
778  assign(P.r, P.g, P.b, P.a);
779  }
780 
782  };
783 
784 
785  /**
786  Quad float bitmap writer
787  */
789  public:
790  inline void assign(int x) {
792  ptr[CHANNELS_4.A] = 1.0f;
793  }
794 
795  inline void assign(int r, int g, int b) {
799  ptr[CHANNELS_4.A] = 1.0f;
800  }
801 
802  inline void assign(int r, int g, int b, int a) {
807  }
808 
809  inline void assign(float x) {
811  ptr[CHANNELS_4.A] = 1.0f;
812  }
813 
814  inline void assign(float r, float g, float b) {
818  ptr[CHANNELS_4.A] = 1.0f;
819  }
820 
821  inline void assign(float r, float g, float b, float a) {
826  }
827 
828  inline void operator<<(const pixint1& P) {
829  assign(P.x);
830  }
831 
832  inline void operator<<(const pixint3& P) {
833  assign(P.r, P.g, P.b);
834  }
835 
836  inline void operator<<(const pixint4& P) {
837  int _a = 255 - P.a;
838  ptr[CHANNELS_4.R] = clipPixfloat((P.r + ptr[CHANNELS_4.R] * _a) / 255.0f);
839  ptr[CHANNELS_4.G] = clipPixfloat((P.g + ptr[CHANNELS_4.G] * _a) / 255.0f);
840  ptr[CHANNELS_4.B] = clipPixfloat((P.b + ptr[CHANNELS_4.B] * _a) / 255.0f);
841  ptr[CHANNELS_4.A] = clipPixfloat(1 - _a * ptr[CHANNELS_4.A] / 255.0f);
842  }
843 
844  inline void operator<<(const pixfloat1& P) {
845  assign(P.x);
846  }
847 
848  inline void operator<<(const pixfloat3& P) {
849  assign(P.r, P.g, P.b);
850  }
851 
852  inline void operator<<(const pixfloat4& P) {
853  float _a = 1 - P.a;
854  ptr[CHANNELS_4.R] = clipPixfloat(P.r + ptr[CHANNELS_4.R] * _a);
855  ptr[CHANNELS_4.G] = clipPixfloat(P.g + ptr[CHANNELS_4.G] * _a);
856  ptr[CHANNELS_4.B] = clipPixfloat(P.b + ptr[CHANNELS_4.B] * _a);
857  ptr[CHANNELS_4.A] = clipPixfloat(1 - _a * (1 - ptr[CHANNELS_4.A]));
858  }
859 
860  inline void operator=(const pixint1& P) {
861  assign(P.x);
862  }
863 
864  inline void operator=(const pixint3& P) {
865  assign(P.r, P.g, P.b);
866  }
867 
868  inline void operator=(const pixint4& P) {
869  assign(P.r, P.g, P.b, P.a);
870  }
871 
872  inline void operator=(const pixfloat1& P) {
873  assign(P.x);
874  }
875 
876  inline void operator=(const pixfloat3& P) {
877  assign(P.r, P.g, P.b);
878  }
879 
880  inline void operator=(const pixfloat4& P) {
881  assign(P.r, P.g, P.b, P.a);
882  }
883 
885  };
886 
887  /**
888  An exception to throw if a pixel format is not supported
889  */
891  public:
892  UnsupportedPixelFormat(PixelFormat pf) : Exception("This pixel format is not supported: %s", AbstractBitmap::PIXEL_FORMAT_NAMES[pf]) {};
893  static void check(AbstractBitmap& bitmap, PixelFormat pf);
894  static void assertMask(AbstractBitmap& bitmap);
895  static void assertFloat(AbstractBitmap& bitmap);
896  static void assertInt(AbstractBitmap& bitmap);
897  };
898 }
A very basic class for any image.
const unsigned char getBitsPerPixel() const
Returns number of bits per pixel stored in each bitmap.
BitmapContentModifier(AbstractBitmap &bitmap)
Definition: bitmap_access.h:60
A generic to access bitmap data.
Definition: bitmap_access.h:66
bool operator<(const CustomBitmapScanner &another) const
Definition: bitmap_access.h:83
pixel * ptr
pointer to the current pixel
Definition: bitmap_access.h:69
void operator+=(const int n)
Move the current position N pixels forward.
CustomBitmapScanner(const AbstractBitmap &bitmap, int x=0, int y=0)
pixel * jump(int x, int y) const
Retrieves pixel address at a given position;.
Definition: bitmap_access.h:75
void operator++(int)
Move the current position ONE PIXEL forward.
Definition: bitmap_access.h:94
int getHeight() const
Returns bitmap height in pixels.
void goTo(int x, int y)
Changes current position.
pixel * data
bitmap data
Definition: bitmap_access.h:68
int getWidth() const
Returns bitmap width in pixels.
int height
bitmap sizes in pixels
Definition: bitmap_access.h:70
Base class for all exceptions.
Definition: exception.h:37
const pixbyte * getData(int x, int y) const
Returns a pointer to given pixel.
const int getHeight() const
Height of the texture in pixels.
const int getWidth() const
Width of the texture in pixels.
Quad byte bitmap reader.
QuadByteBitmapReader(const AbstractBitmap &bitmap, int x=0, int y=0)
const pixint4 operator[](int i) const
Retrieves a value at position shifted by i pixels in scanline order with respect to the current posit...
pixint4 operator()(int x, int y) const
Quad byte bitmap writer.
QuadByteBitmapWriter(AbstractBitmap &bitmap, int x=0, int y=0)
void operator<<(const pixfloat1 &P)
void operator<<(const pixint1 &P)
void operator=(const pixint3 &P)
void operator<<(const pixfloat4 &P)
void assign(float r, float g, float b, float a)
void operator=(const pixfloat3 &P)
void operator=(const pixfloat4 &P)
void operator=(const pixint1 &P)
void assign(int r, int g, int b, int a)
void operator<<(const pixint3 &P)
void operator=(const pixfloat1 &P)
void assign(float r, float g, float b)
void operator<<(const pixfloat3 &P)
void operator=(const pixint4 &P)
void operator<<(const pixint4 &P)
void assign(int r, int g, int b)
Quad float bitmap reader.
const pixfloat4 operator[](int i) const
Retrieves a value at position shifted by i pixels in scanline order with respect to the current posit...
pixfloat4 operator()(int x, int y) const
QuadFloatBitmapReader(const AbstractBitmap &bitmap, int x=0, int y=0)
pixfloat4 at(int x, int y) const
Quad float bitmap writer.
void assign(float r, float g, float b)
void assign(int r, int g, int b)
void operator<<(const pixint4 &P)
void operator<<(const pixint1 &P)
QuadFloatBitmapWriter(AbstractBitmap &bitmap, int x=0, int y=0)
void operator=(const pixfloat1 &P)
void operator=(const pixfloat4 &P)
void operator=(const pixint3 &P)
void assign(float r, float g, float b, float a)
void assign(int r, int g, int b, int a)
void operator=(const pixfloat3 &P)
void operator<<(const pixfloat1 &P)
void operator<<(const pixfloat4 &P)
void operator<<(const pixfloat3 &P)
void operator=(const pixint4 &P)
void operator<<(const pixint3 &P)
void operator=(const pixint1 &P)
Single byte bitmap reader.
pixint1 operator()() const
Returns value at current position.
const pixint1 operator[](int i) const
Retrieves a value at position shifted by i pixels in scanline order with respect to the current posit...
pixint1 operator()(int x, int y) const
Returns value at pixel (x,y) position.
SingleByteBitmapReader(const AbstractBitmap &bitmap, int x=0, int y=0)
Single byte bitmap writer.
void assign(int r, int g, int b)
void operator=(const pixint1 &P)
void assign(int r, int g, int b, int a)
void operator=(const pixint3 &P)
void operator<<(const pixfloat3 &P)
void operator=(const pixint4 &P)
void operator<<(const pixint1 &P)
void operator<<(const pixint3 &P)
void assign(float r, float g, float b, float a)
SingleByteBitmapWriter(AbstractBitmap &bitmap, int x=0, int y=0)
void operator<<(const pixint4 &P)
void operator<<(const pixfloat1 &P)
void operator=(const pixfloat1 &P)
void assign(float r, float g, float b)
void operator=(const pixfloat3 &P)
void operator<<(const pixfloat4 &P)
void operator=(const pixfloat4 &P)
Single float bitmap reader.
pixfloat1 operator()(int x, int y) const
SingleFloatBitmapReader(const AbstractBitmap &bitmap, int x=0, int y=0)
const pixfloat1 operator[](int i) const
Retrieves a value at position shifted by i pixels in scanline order with respect to the current posit...
Single float bitmap writer.
void operator=(const pixfloat1 &P)
void operator<<(const pixfloat3 &P)
void operator=(const pixfloat3 &P)
void assign(float r, float g, float b, float a)
void operator=(const pixfloat4 &P)
void assign(int r, int g, int b, int a)
void assign(int r, int g, int b)
void operator<<(const pixint3 &P)
void operator<<(const pixfloat1 &P)
void operator=(const pixint4 &P)
SingleFloatBitmapWriter(AbstractBitmap &bitmap, int x=0, int y=0)
void operator=(const pixint1 &P)
void assign(float r, float g, float b)
void operator=(const pixint3 &P)
void operator<<(const pixint1 &P)
void operator<<(const pixfloat4 &P)
void operator<<(const pixint4 &P)
Triple byte bitmap reader.
const pixint3 operator[](int i) const
Retrieves a value at position shifted by i pixels in scanline order with respect to the current posit...
TripleByteBitmapReader(const AbstractBitmap &bitmap, int x=0, int y=0)
pixint3 operator()(int x, int y) const
Triple byte bitmap writer.
void assign(int r, int g, int b, int a)
void operator=(const pixint1 &P)
void operator<<(const pixfloat3 &P)
void operator=(const pixint3 &P)
void operator<<(const pixint1 &P)
void operator<<(const pixfloat1 &P)
TripleByteBitmapWriter(AbstractBitmap &bitmap, int x=0, int y=0)
void operator=(const pixint4 &P)
void assign(int r, int g, int b)
void operator=(const pixfloat4 &P)
void operator<<(const pixint3 &P)
void operator=(const pixfloat3 &P)
void operator<<(const pixfloat4 &P)
void assign(float r, float g, float b, float a)
void operator<<(const pixint4 &P)
void operator=(const pixfloat1 &P)
void assign(float r, float g, float b)
Triple float bitmap reader.
TripleFloatBitmapReader(const AbstractBitmap &bitmap, int x=0, int y=0)
const pixfloat3 operator[](int i) const
Retrieves a value at position shifted by i pixels in scanline order with respect to the current posit...
pixfloat3 operator()(int x, int y) const
Triple float bitmap writer.
void operator=(const pixint1 &P)
void operator=(const pixfloat3 &P)
void operator<<(const pixint3 &P)
void operator=(const pixfloat1 &P)
void operator<<(const pixfloat1 &P)
void assign(int r, int g, int b)
void operator<<(const pixint4 &P)
void assign(float r, float g, float b, float a)
void operator=(const pixint3 &P)
void operator=(const pixfloat4 &P)
TripleFloatBitmapWriter(AbstractBitmap &bitmap, int x=0, int y=0)
void operator<<(const pixfloat3 &P)
void assign(int r, int g, int b, int a)
void operator<<(const pixint1 &P)
void assign(float r, float g, float b)
void operator<<(const pixfloat4 &P)
void operator=(const pixint4 &P)
An exception to throw if a pixel format is not supported.
UnsupportedPixelFormat(PixelFormat pf)
static void check(AbstractBitmap &bitmap, PixelFormat pf)
static void assertFloat(AbstractBitmap &bitmap)
static void assertInt(AbstractBitmap &bitmap)
static void assertMask(AbstractBitmap &bitmap)
uint8_t pixbyte
Definition: basic_types.h:34
const int B
Definition: bitmap_access.h:31
const int A
Definition: bitmap_access.h:31
pixbyte clipPixint(int x)
Clips an integer pixel value to 0..255 range.
float pixfloat
Definition: basic_types.h:35
pixfloat clipPixfloat(pixfloat x)
Clips a floating point pixel value to 0..1 range.
pixbyte pixfloat2pixbyte(pixfloat x)
Converts a floating point pixel value to a 0..255 integer.
pixfloat int2pixfloat(int x)
Converts an integer value to 0..1 floating point pixel value.
static const struct Beatmup::@1 CHANNELS_4
const int R
Definition: bitmap_access.h:31
const int G
Definition: bitmap_access.h:31
static const struct Beatmup::@2 CHANNELS_3
Monochromatic floating point arithmetic.
Trichromatic floating point arithmetic.
4-channel floating point arithmetic
Monochromatic integer arithmetic.
Trichromatic integer arithmetic.
4-channel integer arithmetic
jobject jlong jint jint jint jint g
jobject jlong jint jint jint jint jint b
jobject jlong jint jint y
jobject jlong jint jint jint r
jobject jlong jint jint jint jint jint jint a
jobject jlong jint x
Beatmup::InternalBitmap * bitmap
Beatmup::IntPoint p((int) x,(int) y)
int n