3 * Copyright (C) 1998, 2000, 2004, 2006, 2011 Free Software Foundation, Inc.
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public License
7 * as published by the Free Software Foundation; either version 3, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this software; see the file COPYING.LESSER. If
17 * not, write to the Free Software Foundation, Inc., 51 Franklin
18 * Street, Fifth Floor, Boston, MA 02110-1301 USA
24 static scm_t_bits image_tag
;
31 /* The name of this image */
34 /* A function to call when this image is
35 modified, e.g., to update the screen,
36 or SCM_BOOL_F if no action necessary */
41 make_image (SCM name
, SCM s_width
, SCM s_height
)
45 int width
= scm_to_int (s_width
);
46 int height
= scm_to_int (s_height
);
48 /* Step 1: Allocate the memory block.
50 image
= (struct image
*) scm_gc_malloc (sizeof (struct image
), "image");
52 /* Step 2: Initialize it with straight code.
55 image
->height
= height
;
57 image
->name
= SCM_BOOL_F
;
58 image
->update_func
= SCM_BOOL_F
;
60 /* Step 3: Create the smob.
62 SCM_NEWSMOB (smob
, image_tag
, image
);
64 /* Step 4: Finish the initialization.
67 image
->pixels
= scm_gc_malloc_pointerless (width
* height
, "image pixels");
73 clear_image (SCM image_smob
)
78 scm_assert_smob_type (image_tag
, image_smob
);
80 image
= (struct image
*) SCM_SMOB_DATA (image_smob
);
81 area
= image
->width
* image
->height
;
82 memset (image
->pixels
, 0, area
);
84 /* Invoke the image's update function.
86 if (scm_is_true (image
->update_func
))
87 scm_call_0 (image
->update_func
);
89 scm_remember_upto_here_1 (image_smob
);
91 return SCM_UNSPECIFIED
;
95 print_image (SCM image_smob
, SCM port
, scm_print_state
*pstate
)
97 struct image
*image
= (struct image
*) SCM_SMOB_DATA (image_smob
);
99 scm_puts ("#<image ", port
);
100 scm_display (image
->name
, port
);
101 scm_puts (">", port
);
103 /* non-zero means success */
108 init_image_type (void)
110 image_tag
= scm_make_smob_type ("image", sizeof (struct image
));
111 scm_set_smob_print (image_tag
, print_image
);
113 scm_c_define_gsubr ("clear-image", 1, 0, 0, clear_image
);
114 scm_c_define_gsubr ("make-image", 3, 0, 0, make_image
);