3 * Copyright (C) 1998, 2000, 2004, 2006 Free Software Foundation, Inc.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this software; see the file COPYING. If not, write to
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301 USA
24 static scm_t_bits image_tag;
30 /* The name of this image */
33 /* A function to call when this image is
34 modified, e.g., to update the screen,
35 or SCM_BOOL_F if no action necessary */
40 make_image (SCM name, SCM s_width, SCM s_height)
44 int width = scm_to_int (s_width);
45 int height = scm_to_int (s_height);
47 /* Step 1: Allocate the memory block.
49 image = (struct image *) scm_gc_malloc (sizeof (struct image), "image");
51 /* Step 2: Initialize it with straight code.
54 image->height = height;
56 image->name = SCM_BOOL_F;
57 image->update_func = SCM_BOOL_F;
59 /* Step 3: Create the smob.
61 SCM_NEWSMOB (smob, image_tag, image);
63 /* Step 4: Finish the initialization.
66 image->pixels = scm_gc_malloc (width * height, "image pixels");
72 clear_image (SCM image_smob)
77 scm_assert_smob_type (image_tag, image_smob);
79 image = (struct image *) SCM_SMOB_DATA (image_smob);
80 area = image->width * image->height;
81 memset (image->pixels, 0, area);
83 /* Invoke the image's update function.
85 if (scm_is_true (image->update_func))
86 scm_call_0 (image->update_func);
88 scm_remember_upto_here_1 (image_smob);
90 return SCM_UNSPECIFIED;
94 mark_image (SCM image_smob)
96 /* Mark the image's name and update function. */
97 struct image *image = (struct image *) SCM_SMOB_DATA (image_smob);
99 scm_gc_mark (image->name);
100 return image->update_func;
104 free_image (SCM image_smob)
106 struct image *image = (struct image *) SCM_SMOB_DATA (image_smob);
108 scm_gc_free (image->pixels, image->width * image->height, "image pixels");
109 scm_gc_free (image, sizeof (struct image), "image");
115 print_image (SCM image_smob, SCM port, scm_print_state *pstate)
117 struct image *image = (struct image *) SCM_SMOB_DATA (image_smob);
119 scm_puts ("#<image ", port);
120 scm_display (image->name, port);
121 scm_puts (">", port);
123 /* non-zero means success */
128 init_image_type (void)
130 image_tag = scm_make_smob_type ("image", sizeof (struct image));
131 scm_set_smob_mark (image_tag, mark_image);
132 scm_set_smob_free (image_tag, free_image);
133 scm_set_smob_print (image_tag, print_image);
135 scm_c_define_gsubr ("clear-image", 1, 0, 0, clear_image);
136 scm_c_define_gsubr ("make-image", 3, 0, 0, make_image);