1 /* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3  * This file is part of openfx-supportext <https://github.com/devernay/openfx-supportext>,
4  * Copyright (C) 2013-2018 INRIA
5  *
6  * openfx-supportext is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * openfx-supportext is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with openfx-supportext.  If not, see <http://www.gnu.org/licenses/gpl-2.0.html>
18  * ***** END LICENSE BLOCK ***** */
19 
20 /*
21  * OFX mipmapping help functions
22  */
23 
24 #ifndef openfx_supportext_ofxsMipmap_h
25 #define openfx_supportext_ofxsMipmap_h
26 
27 #include <cmath>
28 #include <cassert>
29 #include <vector>
30 
31 #include "ofxsImageEffect.h"
32 
33 namespace OFX {
34 void ofxsScalePixelData(OFX::ImageEffect* instance,
35                         const OfxRectI & originalRenderWindow,
36                         const OfxRectI & renderWindow,
37                         unsigned int levels,
38                         const void* srcPixelData,
39                         OFX::PixelComponentEnum srcPixelComponents,
40                         OFX::BitDepthEnum srcPixelDepth,
41                         const OfxRectI & srcBounds,
42                         int srcRowBytes,
43                         void* dstPixelData,
44                         OFX::PixelComponentEnum dstPixelComponents,
45                         OFX::BitDepthEnum dstPixelDepth,
46                         const OfxRectI & dstBounds,
47                         int dstRowBytes);
48 
49 struct MipMap
50 {
51     std::size_t memSize;
52     OFX::ImageMemory* data;
53     OfxRectI bounds;
54 
MipMapMipMap55     MipMap()
56         : memSize(0)
57         , data(NULL)
58         , bounds()
59     {
60     }
61 
~MipMapMipMap62     ~MipMap()
63     {
64         delete data;
65         data = 0;
66     }
67 };
68 
69 //Contains all levels of details > 0, sort by decreasing LoD
70 typedef std::vector<MipMap> MipMapsVector;
71 
72 /**
73    @brief Given the original image, this function builds all mipmap levels
74    up to maxLevel and stores them in the mipmaps vector, in decreasing LoD.
75    The original image will not be stored in the mipmaps vector.
76    @param mipmaps[out] The mipmaps vector should contains at least maxLevel
77    entries
78  **/
79 void ofxsBuildMipMaps(OFX::ImageEffect* instance,
80                       const OfxRectI & renderWindow,
81                       const void* srcPixelData,
82                       OFX::PixelComponentEnum srcPixelComponents,
83                       OFX::BitDepthEnum srcPixelDepth,
84                       const OfxRectI & srcBounds,
85                       int srcRowBytes,
86                       unsigned int maxLevel,
87                       MipMapsVector & mipmaps);
88 } // OFX
89 
90 #endif // ifndef openfx_supportext_ofxsMipmap_h
91