]> git.sesse.net Git - casparcg/blob - core/producer/text/utils/texture_atlas.h
4831158dfa9cd6c2bdf92023b0ddbad6ef51943f
[casparcg] / core / producer / text / utils / texture_atlas.h
1 /* ============================================================================
2  * Freetype GL - A C OpenGL Freetype engine
3  * Platform:    Any
4  * WWW:         http://code.google.com/p/freetype-gl/
5  * ----------------------------------------------------------------------------
6  * Copyright 2011,2012 Nicolas P. Rougier. All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions are met:
10  *
11  *  1. Redistributions of source code must retain the above copyright notice,
12  *     this list of conditions and the following disclaimer.
13  *
14  *  2. Redistributions in binary form must reproduce the above copyright
15  *     notice, this list of conditions and the following disclaimer in the
16  *     documentation and/or other materials provided with the distribution.
17  *
18  * THIS SOFTWARE IS PROVIDED BY NICOLAS P. ROUGIER ''AS IS'' AND ANY EXPRESS OR
19  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
20  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
21  * EVENT SHALL NICOLAS P. ROUGIER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
22  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  *
29  * The views and conclusions contained in the software and documentation are
30  * those of the authors and should not be interpreted as representing official
31  * policies, either expressed or implied, of Nicolas P. Rougier.
32  * ============================================================================
33  *
34  * This source is based on the article by Jukka Jylänki :
35  * "A Thousand Ways to Pack the Bin - A Practical Approach to
36  * Two-Dimensional Rectangle Bin Packing", February 27, 2010.
37  *
38  * More precisely, this is an implementation of the Skyline Bottom-Left
39  * algorithm based on C++ sources provided by Jukka Jylänki at:
40  * http://clb.demon.fi/files/RectangleBinPack/
41  *
42  *  ============================================================================
43  */
44 #pragma once
45
46
47 /**
48  * @file   texture-atlas.h
49  * @author Nicolas Rougier (Nicolas.Rougier@inria.fr)
50  *
51  * @defgroup texture-atlas Texture atlas
52  *
53  * A texture atlas is used to pack several small regions into a single texture.
54  *
55  * The actual implementation is based on the article by Jukka Jylänki : "A
56  * Thousand Ways to Pack the Bin - A Practical Approach to Two-Dimensional
57  * Rectangle Bin Packing", February 27, 2010.
58  * More precisely, this is an implementation of the Skyline Bottom-Left
59  * algorithm based on C++ sources provided by Jukka Jylänki at:
60  * http://clb.demon.fi/files/RectangleBinPack/
61  *
62  *
63  */
64
65 #include "common/memory.h"
66 #include "color.h"
67
68 namespace caspar { namespace core { namespace text {
69
70 struct rect
71 {
72         int x;
73         int y;
74         int width;
75         int height;
76 };
77
78 class texture_atlas
79 {
80 public:
81         texture_atlas(const size_t w, const size_t h, const size_t d);
82
83         rect get_region(int width, int height);
84         void set_region(const size_t x, const size_t y, const size_t width, const size_t height, const unsigned char *data, const size_t stride, const color<double>& col);
85         void clear();
86
87         size_t depth();
88         size_t width();
89         size_t height();
90
91         unsigned char* data();
92
93 private:
94         struct impl;
95         caspar::spl::shared_ptr<impl> impl_;
96 };
97
98 }}}