|
Packit Service |
2781ba |
/* This file is an image processing operation for GEGL
|
|
Packit Service |
2781ba |
*
|
|
Packit Service |
2781ba |
* GEGL is free software; you can redistribute it and/or
|
|
Packit Service |
2781ba |
* modify it under the terms of the GNU Lesser General Public
|
|
Packit Service |
2781ba |
* License as published by the Free Software Foundation; either
|
|
Packit Service |
2781ba |
* version 3 of the License, or (at your option) any later version.
|
|
Packit Service |
2781ba |
*
|
|
Packit Service |
2781ba |
* GEGL is distributed in the hope that it will be useful,
|
|
Packit Service |
2781ba |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
2781ba |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit Service |
2781ba |
* Lesser General Public License for more details.
|
|
Packit Service |
2781ba |
*
|
|
Packit Service |
2781ba |
* You should have received a copy of the GNU Lesser General Public
|
|
Packit Service |
2781ba |
* License along with GEGL; if not, see <http://www.gnu.org/licenses/>.
|
|
Packit Service |
2781ba |
*
|
|
Packit Service |
2781ba |
* Copyright 2006 Øyvind Kolås <pippin@gimp.org>
|
|
Packit Service |
2781ba |
*/
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
#include "config.h"
|
|
Packit Service |
2781ba |
#include <glib/gi18n-lib.h>
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
#ifdef GEGL_CHANT_PROPERTIES
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
gegl_chant_string (window_title, _(""), "window_title",
|
|
Packit Service |
2781ba |
_("Title to be given to output window"))
|
|
Packit Service |
2781ba |
gegl_chant_string (icon_title, _(""), "icon_title",
|
|
Packit Service |
2781ba |
_("Icon to be used for output window"))
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
gegl_chant_pointer (screen, "", "private")
|
|
Packit Service |
2781ba |
gegl_chant_int(w, "", 0, 1000, 0, "private")
|
|
Packit Service |
2781ba |
gegl_chant_int(h, "", 0, 1000, 0, "private")
|
|
Packit Service |
2781ba |
gegl_chant_int(width, "", 0, 1000, 0, "private")
|
|
Packit Service |
2781ba |
gegl_chant_int(height, "", 0, 1000, 0, "private")
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
#else
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
#define GEGL_CHANT_TYPE_SINK
|
|
Packit Service |
2781ba |
#define GEGL_CHANT_C_FILE "sdl-display.c"
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
#include "gegl-chant.h"
|
|
Packit Service |
2781ba |
#include <SDL.h>
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
static void
|
|
Packit Service |
2781ba |
init_sdl (void)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
static int inited = 0;
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
if (!inited)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
inited = 1;
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
if (SDL_Init (SDL_INIT_VIDEO) < 0)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
fprintf (stderr, "Unable to init SDL: %s\n", SDL_GetError ());
|
|
Packit Service |
2781ba |
return;
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
atexit (SDL_Quit);
|
|
Packit Service |
2781ba |
SDL_EnableUNICODE (1);
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
/*static int instances = 0;*/
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
static gboolean idle (gpointer data)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
SDL_Event event;
|
|
Packit Service |
2781ba |
while (SDL_PollEvent (&event))
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
switch (event.type)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
case SDL_QUIT:
|
|
Packit Service |
2781ba |
exit (0);
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
return TRUE;
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
static guint handle = 0;
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
static gboolean
|
|
Packit Service |
2781ba |
process (GeglOperation *operation,
|
|
Packit Service |
2781ba |
GeglBuffer *input,
|
|
Packit Service |
2781ba |
const GeglRectangle *result,
|
|
Packit Service |
2781ba |
gint level)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
GeglChantO *o = GEGL_CHANT_PROPERTIES (operation);
|
|
Packit Service |
2781ba |
GeglBuffer *source;
|
|
Packit Service |
2781ba |
SDL_Surface **sdl_outwin = NULL; /*op_sym (op, "sdl_outwin");*/
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
init_sdl ();
|
|
Packit Service |
2781ba |
if (!handle)
|
|
Packit Service |
2781ba |
handle = g_timeout_add (500, idle, NULL);
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
if (!o->screen ||
|
|
Packit Service |
2781ba |
o->width != result->width ||
|
|
Packit Service |
2781ba |
o->height != result->height)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
if (sdl_outwin)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
if (o->screen)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
SDL_FreeSurface (o->screen);
|
|
Packit Service |
2781ba |
o->screen = NULL;
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
o->screen = SDL_CreateRGBSurface (SDL_SWSURFACE,
|
|
Packit Service |
2781ba |
result->width, result->height, 32, 0xff0000,
|
|
Packit Service |
2781ba |
0x00ff00, 0x0000ff, 0x000000);
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
*sdl_outwin = o->screen;
|
|
Packit Service |
2781ba |
if (!o->screen)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
fprintf (stderr, "CreateRGBSurface failed: %s\n",
|
|
Packit Service |
2781ba |
SDL_GetError ());
|
|
Packit Service |
2781ba |
return -1;
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
else
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
o->screen = SDL_SetVideoMode (result->width, result->height, 32, SDL_SWSURFACE);
|
|
Packit Service |
2781ba |
if (!o->screen)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
fprintf (stderr, "Unable to set SDL mode: %s\n",
|
|
Packit Service |
2781ba |
SDL_GetError ());
|
|
Packit Service |
2781ba |
return -1;
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
o->width = result->width ;
|
|
Packit Service |
2781ba |
o->height = result->height;
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
/*
|
|
Packit Service |
2781ba |
* There seems to be a valid faster path to the SDL desired display format
|
|
Packit Service |
2781ba |
* in B'G'R'A, perhaps babl should have been able to figure this out ito?
|
|
Packit Service |
2781ba |
*
|
|
Packit Service |
2781ba |
*/
|
|
Packit Service |
2781ba |
source = gegl_buffer_create_sub_buffer (input, result);
|
|
Packit Service |
2781ba |
gegl_buffer_get (source,
|
|
Packit Service |
2781ba |
NULL,
|
|
Packit Service |
2781ba |
1.0,
|
|
Packit Service |
2781ba |
babl_format_new (babl_model ("RGBA"),
|
|
Packit Service |
2781ba |
babl_type ("u8"),
|
|
Packit Service |
2781ba |
babl_component ("B"),
|
|
Packit Service |
2781ba |
babl_component ("G"),
|
|
Packit Service |
2781ba |
babl_component ("R"),
|
|
Packit Service |
2781ba |
babl_component ("A"),
|
|
Packit Service |
2781ba |
NULL),
|
|
Packit Service |
2781ba |
((SDL_Surface*)o->screen)->pixels, GEGL_AUTO_ROWSTRIDE,
|
|
Packit Service |
2781ba |
GEGL_ABYSS_NONE);
|
|
Packit Service |
2781ba |
g_object_unref (source);
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
if (!sdl_outwin)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
SDL_UpdateRect (o->screen, 0, 0, 0, 0);
|
|
Packit Service |
2781ba |
SDL_WM_SetCaption (o->window_title, o->icon_title);
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
o->width = result->width ;
|
|
Packit Service |
2781ba |
o->height = result->height;
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
return TRUE;
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
static void
|
|
Packit Service |
2781ba |
gegl_chant_class_init (GeglChantClass *klass)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
GeglOperationClass *operation_class;
|
|
Packit Service |
2781ba |
GeglOperationSinkClass *sink_class;
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
operation_class = GEGL_OPERATION_CLASS (klass);
|
|
Packit Service |
2781ba |
sink_class = GEGL_OPERATION_SINK_CLASS (klass);
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
sink_class->process = process;
|
|
Packit Service |
2781ba |
sink_class->needs_full = TRUE;
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
gegl_operation_class_set_keys (operation_class,
|
|
Packit Service |
2781ba |
"name" , "gegl:sdl-display",
|
|
Packit Service |
2781ba |
"categories" , "display",
|
|
Packit Service |
2781ba |
"description" ,
|
|
Packit Service |
2781ba |
_("Displays the input buffer in an SDL window (restricted to one"
|
|
Packit Service |
2781ba |
" display op/process, due to SDL implementation issues)."),
|
|
Packit Service |
2781ba |
NULL);
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
#endif
|