1 /* 2 * Copyright (C) 2020 Linux Studio Plugins Project <https://lsp-plug.in/> 3 * (C) 2020 Vladimir Sadovnikov <sadko4u@gmail.com> 4 * 5 * This file is part of lsp-plugins 6 * Created on: 12 нояб. 2018 г. 7 * 8 * lsp-plugins is free software: you can redistribute it and/or modify 9 * it under the terms of the GNU Lesser General Public License as published by 10 * the Free Software Foundation, either version 3 of the License, or 11 * any later version. 12 * 13 * lsp-plugins is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU Lesser General Public License for more details. 17 * 18 * You should have received a copy of the GNU Lesser General Public License 19 * along with lsp-plugins. If not, see <https://www.gnu.org/licenses/>. 20 */ 21 22 #ifndef UI_TK_WIDGETS_GRAPH_LSPFRAMEBUFFER_H_ 23 #define UI_TK_WIDGETS_GRAPH_LSPFRAMEBUFFER_H_ 24 25 namespace lsp 26 { 27 namespace tk 28 { 29 class LSPFrameBuffer: public LSPGraphItem 30 { 31 public: 32 static const w_class_t metadata; 33 34 typedef struct rgba_t 35 { 36 float r, g, b, a; 37 } rgba_t; 38 39 protected: 40 typedef void (LSPFrameBuffer::*calc_color_t)(float *rgba, const float *value, size_t n); 41 42 protected: 43 size_t nChanges; // Number of changes 44 size_t nRows; // Number of rows in frame buffer 45 size_t nCols; // Number of columns in frame buffer 46 uint32_t nCurrRow; // Synchronized rowId 47 float *vData; // Frame buffer data 48 float *vTempRGBA; // Temporary RGBA buffer data 49 uint8_t *pData; // Allocation pointer 50 float fTransparency; // Frame buffer transparency 51 size_t nAngle; // Frame buffer rotation angle 0..3 52 float fHPos; // Horizontal position on graph widget (-1 .. 1) 53 float fVPos; // Vertical position on graph widget (-1 .. 1) 54 float fWidth; // Width in pixels (-1 .. 1) 55 float fHeight; // Height in pixels (-1 .. 1) 56 bool bClear; // Clear flag: do complete redraw 57 size_t nPalette; // Palette used for drawing 58 calc_color_t pCalcColor; // Function for estimating color 59 LSPColor sColor; // Base color 60 61 rgba_t sColRGBA, sBgRGBA; 62 63 protected: 64 void drop_data(); 65 void calc_rainbow_color(float *rgba, const float *value, size_t n); 66 void calc_fog_color(float *rgba, const float *v, size_t n); 67 void calc_color(float *rgba, const float *value, size_t n); 68 void calc_lightness(float *rgba, const float *value, size_t n); 69 void calc_lightness2(float *rgba, const float *value, size_t n); 70 void allocate_buffer(); 71 void check_color_changed(); 72 float *get_buffer(); 73 float *get_rgba_buffer(); 74 75 public: 76 explicit LSPFrameBuffer(LSPDisplay *dpy); 77 virtual ~LSPFrameBuffer(); 78 79 virtual status_t init(); 80 virtual void destroy(); 81 82 public: get_rows()83 size_t get_rows() const { return nRows; } get_cols()84 size_t get_cols() const { return nCols; } get_angle()85 size_t get_angle() const { return nAngle; } get_palette()86 size_t get_palette() const { return nPalette; } get_hpos()87 float get_hpos() const { return fHPos; } get_vpos()88 float get_vpos() const { return fVPos; } get_width()89 float get_width() const { return fWidth; } get_height()90 float get_height() const { return fHeight; } get_transparency()91 float get_transparency() const { return fTransparency; } get_opacity()92 float get_opacity() const { return 1.0f - fTransparency; } color()93 inline LSPColor *color() { return &sColor; } 94 95 public: 96 status_t append_data(uint32_t row_id, const float *data); 97 void set_rows(size_t rows); 98 void set_cols(size_t cols); 99 void set_size(size_t rows, size_t cols); 100 void set_angle(size_t angle); 101 void set_hpos(float value); 102 void set_vpos(float value); 103 void set_width(float value); 104 void set_height(float value); 105 void set_transparency(float value); 106 void set_palette(size_t value); set_opacity(float value)107 inline void set_opacity(float value) { set_transparency(1.0f - value); }; 108 109 public: 110 virtual void render(ISurface *s, bool force); 111 }; 112 113 } /* namespace tk */ 114 } /* namespace lsp */ 115 116 #endif /* UI_TK_WIDGETS_GRAPH_LSPFRAMEBUFFER_H_ */ 117