filters: Move gaussian blur into separate file.
[gfxprim.git] / tests / SDL / showimage.c
bloba63ba78e0e11f8baafe3918bd0624561e19edcb0
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) 2009-2011 Cyril Hrubis <metan@ucw.cz> *
20 * *
21 *****************************************************************************/
23 #include <stdlib.h>
24 #include <stdio.h>
25 #include <errno.h>
26 #include <SDL/SDL.h>
28 #include "GP.h"
29 #include "GP_SDL.h"
31 SDL_Surface *display = NULL;
32 GP_Context context, *bitmap;
34 int brightness = 0;
36 void event_loop(void)
38 SDL_Event event;
39 GP_Context *res;
41 while (SDL_WaitEvent(&event) > 0) {
43 switch (event.type) {
45 case SDL_KEYDOWN:
46 switch (event.key.keysym.sym) {
47 case SDLK_ESCAPE:
48 return;
49 case SDLK_UP:
50 brightness+=2;
51 case SDLK_DOWN: {
52 brightness-=1;
54 GP_FILTER_PARAMS(bitmap->pixel_type, param);
55 GP_FilterParamSetIntAll(param, brightness);
56 res = GP_FilterBrightness(bitmap, NULL, param, NULL);
58 printf("brightness = %i %ux%u\n", brightness, res->w, res->h);
60 GP_Blit(res, 0, 0, res->w, res->h, &context, 0, 0);
61 SDL_Flip(display);
62 GP_ContextFree(res);
63 } break;
64 default:
65 break;
67 break;
68 case SDL_QUIT:
69 return;
70 default:
71 break;
76 int main(int argc, char *argv[])
78 /* Bits per pixel to be set for the display surface. */
79 int display_bpp = 0;
81 int i;
82 for (i = 1; i < argc; i++) {
83 if (strcmp(argv[i], "-16") == 0) {
84 display_bpp = 16;
86 else if (strcmp(argv[i], "-24") == 0) {
87 display_bpp = 24;
89 else if (strcmp(argv[i], "-32") == 0) {
90 display_bpp = 32;
94 GP_SetDebugLevel(10);
96 if ((bitmap = GP_LoadImage(argv[1], NULL)) == NULL) {
97 fprintf(stderr, "Failed to load bitmap: %s\n", strerror(errno));
98 return 1;
101 /* Initialize SDL */
102 if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) != 0) {
103 fprintf(stderr, "Could not initialize SDL: %s\n", SDL_GetError());
104 return 1;
107 /* Create a window with a software back surface */
108 display = SDL_SetVideoMode(bitmap->w, bitmap->h, display_bpp, SDL_SWSURFACE);
109 if (display == NULL) {
110 fprintf(stderr, "Could not open display: %s\n", SDL_GetError());
111 goto fail;
114 GP_SDL_ContextFromSurface(&context, display);
116 GP_Blit(bitmap, 0, 0, bitmap->w, bitmap->h, &context, 0, 0);
117 SDL_Flip(display);
119 event_loop();
121 SDL_Quit();
122 return 0;
123 fail:
124 SDL_Quit();
125 return 1;