1 /* Project 16 Source Code~
2 * Copyright (C) 2012-2015 sparky4 & pngwen & andrius4669
4 * This file is part of Project 16.
6 * Project 16 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 3 of the License, or
9 * (at your option) any later version.
11 * Project 16 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.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>, or
18 * write to the Free Software Foundation, Inc., 51 Franklin Street,
19 * Fifth Floor, Boston, MA 02110-1301 USA.
23 * Implimentation of the planar buffer files.
\r
26 #include "src/lib/planar.h"
\r
28 /* creates a planar buffer from the bitmap data.
\r
29 The planar buffer is dynamically allocated, and should
\r
30 be destroyed with the planar_buf_free function when no longer
\r
34 planar_buf_from_bitmap(bitmap_t *b) {
\r
36 int plane, bi, pi, x, y;
\r
38 /* allocate the buffer */
\r
39 p = planar_buf_alloc(b->width, b->height);
\r
41 /* copy the bitmap data into the planar format */
\r
44 for(y=0; y < b->height; y++) {
\r
45 /* start on the first plane */
\r
47 for(x=0; x < b->width; x++) {
\r
48 /* copy to each plane */
\r
49 p->plane[plane++][pi]=b->data[bi++];
\r
51 /* handle the completion of 4 planes. */
\r
58 /* correct for images not divisible by 4 */
\r
66 /* allocates a planar buffer with specified dimensions */
\r
68 planar_buf_alloc(word width, word height) {
\r
72 /* allocate the structure and populate sizes */
\r
73 p=malloc(sizeof(planar_buf_t));
\r
76 p->pwidth = width / 4 + (width%4 ? 1 : 0);
\r
78 /* allocate the planes */
\r
79 for(i=0; i<4; i++) {
\r
80 p->plane[i] = malloc(p->height * p->pwidth);
\r
87 /* deallocates a planar buffer */
\r
89 planar_buf_free(planar_buf_t *p) {
\r
92 /* free the planes */
\r
93 for(i=0; i<4; i++) {
\r
97 /* free the structure */
\r