1 /* Project 16 Source Code~
\r
2 * Copyright (C) 2012-2016 sparky4 & pngwen & andrius4669 & joncampbell123 & yakui-lover
\r
4 * This file is part of Project 16.
\r
6 * Project 16 is free software; you can redistribute it and/or modify
\r
7 * it under the terms of the GNU General Public License as published by
\r
8 * the Free Software Foundation; either version 3 of the License, or
\r
9 * (at your option) any later version.
\r
11 * Project 16 is distributed in the hope that it will be useful,
\r
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
14 * GNU General Public License for more details.
\r
16 * You should have received a copy of the GNU General Public License
\r
17 * along with this program. If not, see <http://www.gnu.org/licenses/>, or
\r
18 * write to the Free Software Foundation, Inc., 51 Franklin Street,
\r
19 * Fifth Floor, Boston, MA 02110-1301 USA.
\r
23 * Implimentation of the planar buffer files.
\r
29 #include "src/lib/planar.h"
\r
31 /* creates a planar buffer from the bitmap data.
\r
32 The planar buffer is dynamically allocated, and should
\r
33 be destroyed with the planar_buf_free function when no longer
\r
37 planar_buf_from_bitmap(bitmap_t *b) {
\r
39 int plane, bi, pi, x, y;
\r
42 /* allocate the buffer */
\r
43 p = planar_buf_alloc(b->width, b->height);
\r
45 /* copy the bitmap data into the planar format */
\r
48 for(y=0; y < b->height; y++) {
\r
49 /* start on the first plane */
\r
51 for(x=0; x < b->width; x++) {
\r
52 /* copy to each plane */
\r
53 p->plane[plane++][pi]=b->data[bi++];
\r
55 /* handle the completion of 4 planes. */
\r
62 /* correct for images not divisible by 4 */
\r
66 p->palette = modexNewPal();
\r
69 p->palette[q]=b->palette[q];
\r
76 /* allocates a planar buffer with specified dimensions */
\r
78 planar_buf_alloc(word width, word height) {
\r
82 /* allocate the structure and populate sizes */
\r
83 p=malloc(sizeof(planar_buf_t));
\r
86 p->pwidth = width / 4 + (width%4 ? 1 : 0);
\r
88 /* allocate the planes */
\r
89 for(i=0; i<4; i++) {
\r
90 p->plane[i] = malloc(p->height * p->pwidth);
\r
97 /* deallocates a planar buffer */
\r
99 planar_buf_free(planar_buf_t *p) {
\r
102 /* free the planes */
\r
103 for(i=0; i<4; i++) {
\r
107 /* free the structure */
\r