Add blit color conversion, use GP_Coord and GP_Size in blits
[gfxprim.git] / libs / core / GP_Blit.c
blob76c7a2c516ceb41ca5daf4d27db96674fbd1908d
1 /*****************************************************************************
2 * This file is part of gfxprim library. *
3 * *
4 * Gfxprim is free software; you can redistribute it and/or *
5 * modify it under the terms of the GNU Lesser General Public *
6 * License as published by the Free Software Foundation; either *
7 * version 2.1 of the License, or (at your option) any later version. *
8 * *
9 * Gfxprim is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
12 * Lesser General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU Lesser General Public *
15 * License along with gfxprim; if not, write to the Free Software *
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
17 * Boston, MA 02110-1301 USA *
18 * *
19 * Copyright (C) 2011 Tomas Gavenciak <gavento@ucw.cz> *
20 * *
21 *****************************************************************************/
23 #include "GP_Pixel.h"
24 #include "GP_GetPutPixel.h"
25 #include "GP_Context.h"
26 #include "GP_Blit.h"
29 void GP_Blit(const GP_Context *c1, int x1, int y1, int w, int h,
30 GP_Context *c2, int x2, int y2)
32 // Ultimate TODO: effective processing
33 GP_Blit_Naive(c1, x1, y1, w, h, c2, x2, y2);
37 // TODO(gavento, czech) Plan:
38 // GP_Blit_Naive - Zadne rotovani a tak, jen Get/PutPixel a konverze A->RGBA8888->B
39 // GP_Blit_Simple - S rotovanim, makrovy Get/PutPixel, mozna optimalizace na radky, chytrejsi konverze (ale porad univ.)
40 // GP_Blit_Simple_xBPP - S rotovanim, makrovy Get/PutPixel
41 // GP_Blit_xBPP - Optimalizovane, muze volat GP_Blit_Simple_xBPP pro divne pripady
42 // GP_Blit - Vola GP_Blit_xBPP (stejny typ) nebo GP_Blit_Simple (jine typy), pripadne optimalizovat
45 void GP_Blit_Naive(const GP_Context *c1, int x1, int y1, int w, int h,
46 GP_Context *c2, int x2, int y2)
48 GP_TRANSFORM_BLIT(c1, x1, y1, w, h, c2, x2, y2);
49 // TODO: Cipping?
50 GP_Blit_Naive_Raw(c1, x1, y1, w, h, c2, x2, y2);
54 void GP_Blit_Naive(const GP_Context *c1, GP_Coord x1, GP_Coord y1, GP_Size w, GP_Size h,
55 GP_Context *c2, GP_Coord x2, GP_Coord y2)
57 GP_CHECK(x1 >= 0);
58 GP_CHECK(y1 >= 0);
59 GP_CHECK(w >= 0);
60 GP_CHECK(h >= 0);
61 GP_CHECK(x1 + w <= GP_ContextW(c1));
62 GP_CHECK(y1 + h <= GP_ContextH(c1));
63 GP_CHECK(x2 >= 0);
64 GP_CHECK(y2 >= 0);
65 GP_CHECK(x2 + w <= GP_ContextW(c2));
66 GP_CHECK(y2 + h <= GP_ContextH(c2));
68 for (int i = 0; i < w; i++)
69 for (int j = 0; j < h; j++) {
70 GP_Pixel p = GP_GetPixel(c1, x1 + i, y1 + j);
71 if (c1->pixel_type != c2->pixel_type)
72 p = GP_GP_ConvertContextPixel(p, c1, c2);
73 GP_PutPixel(c2, x2 + i, y2 + j, p);