]> git.cworth.org Git - vogl/blob - src/voglcore/vogl_threaded_resampler.h
Initial vogl checkin
[vogl] / src / voglcore / vogl_threaded_resampler.h
1 /**************************************************************************
2  *
3  * Copyright 2013-2014 RAD Game Tools and Valve Software
4  * Copyright 2010-2014 Rich Geldreich and Tenacious Software LLC
5  * All Rights Reserved.
6  *
7  * Permission is hereby granted, free of charge, to any person obtaining a copy
8  * of this software and associated documentation files (the "Software"), to deal
9  * in the Software without restriction, including without limitation the rights
10  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11  * copies of the Software, and to permit persons to whom the Software is
12  * furnished to do so, subject to the following conditions:
13  *
14  * The above copyright notice and this permission notice shall be included in
15  * all copies or substantial portions of the Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23  * THE SOFTWARE.
24  *
25  **************************************************************************/
26
27 // File: vogl_threaded_resampler.h
28 #pragma once
29
30 #include "vogl_core.h"
31 #include "vogl_resampler.h"
32 #include "vogl_vec.h"
33
34 namespace vogl
35 {
36     class task_pool;
37     class threaded_resampler
38     {
39         VOGL_NO_COPY_OR_ASSIGNMENT_OP(threaded_resampler);
40
41     public:
42         threaded_resampler(task_pool &tp);
43         ~threaded_resampler();
44
45         enum pixel_format
46         {
47             cPF_Y_F32,
48             cPF_RGBX_F32,
49             cPF_RGBA_F32,
50             cPF_Total
51         };
52
53         struct params
54         {
55             params()
56             {
57                 clear();
58             }
59
60             void clear()
61             {
62                 utils::zero_object(*this);
63
64                 m_boundary_op = Resampler::BOUNDARY_CLAMP;
65                 m_sample_low = 0.0f;
66                 m_sample_high = 255.0f;
67                 m_Pfilter_name = VOGL_RESAMPLER_DEFAULT_FILTER;
68                 m_filter_x_scale = 1.0f;
69                 m_filter_y_scale = 1.0f;
70                 m_x_ofs = 0.0f;
71                 m_y_ofs = 0.0f;
72             }
73
74             pixel_format m_fmt;
75
76             const void *m_pSrc_pixels;
77             uint m_src_width;
78             uint m_src_height;
79             uint m_src_pitch;
80
81             void *m_pDst_pixels;
82             uint m_dst_width;
83             uint m_dst_height;
84             uint m_dst_pitch;
85
86             Resampler::Boundary_Op m_boundary_op;
87
88             float m_sample_low;
89             float m_sample_high;
90
91             const char *m_Pfilter_name;
92             float m_filter_x_scale;
93             float m_filter_y_scale;
94
95             float m_x_ofs;
96             float m_y_ofs;
97         };
98
99         bool resample(const params &p);
100
101     private:
102         task_pool *m_pTask_pool;
103
104         const params *m_pParams;
105
106         Resampler::Contrib_List *m_pX_contribs;
107         Resampler::Contrib_List *m_pY_contribs;
108         uint m_bytes_per_pixel;
109
110         vogl::vector<vec4F> m_tmp_img;
111
112         void free_contrib_lists();
113
114         void resample_x_task(uint64_t data, void *pData_ptr);
115         void resample_y_task(uint64_t data, void *pData_ptr);
116     };
117
118 } // namespace vogl