while (elapsed > seconds_per_frame) {
elapsed -= seconds_per_frame;
- if (++newframe >= info.nframes) {
+ if (++newframe >= image->frames) {
if (!info.looping) {
gtk_toggle_button_set_active(play, FALSE);
break;
static int alloc_framebuffer(struct lbx_image *image)
{
- struct lbx_imginfo info;
GtkSpinButton *spin;
if (framebuf)
g_object_unref(framebuf);
- lbx_img_getinfo(image, &info);
framebuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8,
- info.width, info.height);
+ image->width, image->height);
g_return_val_if_fail(framebuf, -1);
spin = GTK_SPIN_BUTTON(gtk_builder_get_object(builder, "framespin"));
- gtk_spin_button_set_range(spin, 0, info.nframes-1);
+ gtk_spin_button_set_range(spin, 0, image->frames-1);
gtk_spin_button_set_value(spin, 0);
- gtk_widget_set_size_request(canvas, info.width, info.height);
+ gtk_widget_set_size_request(canvas, image->width, image->height);
return 0;
}
int render_to_pixbuf(struct lbx_image *image, GdkPixbuf *pixbuf, unsigned frame)
{
unsigned char **framedata, **framemask, *outbuf;
- struct lbx_imginfo info;
unsigned stride;
- lbx_img_getinfo(image, &info);
- assert(info.width == gdk_pixbuf_get_width(pixbuf));
- assert(info.height == gdk_pixbuf_get_height(pixbuf));
+ assert(image->width == gdk_pixbuf_get_width(pixbuf));
+ assert(image->height == gdk_pixbuf_get_height(pixbuf));
framedata = lbx_img_getframe(image, frame);
g_return_val_if_fail(framedata, -1);
outbuf = gdk_pixbuf_get_pixels(pixbuf);
stride = gdk_pixbuf_get_rowstride(pixbuf);
- for (unsigned i = 0; i < info.height; i++) {
+ for (unsigned i = 0; i < image->height; i++) {
unsigned char (*px)[4] = (void *)(outbuf + i*stride);
- for (unsigned j = 0; j < info.width; j++) {
+ for (unsigned j = 0; j < image->width; j++) {
if (framemask[i][j])
get_colour(framedata[i][j], px[j]);
else
MODE_IDENT,
};
-int parserange(struct lbx_imginfo *info, char *str, unsigned char *bits)
+int parserange(unsigned frames, char *str, unsigned char *bits)
{
unsigned long start, end;
unsigned int i;
char *endptr;
start = strtoul(str, &endptr, 0);
- if (start >= info->nframes) {
+ if (start >= frames) {
errmsg("frame %lu out of range.\n", start);
return -1;
}
break;
case '-':
end = strtoul(endptr+1, &endptr, 0);
- if (end >= info->nframes) {
+ if (end >= frames) {
errmsg("frame %lu out of range.\n", end);
return -1;
}
if (endptr == str)
- end = info->nframes - 1;
+ end = frames - 1;
break;
default:
errmsg("invalid frame range: %s.\n", str);
lbx_img_getinfo(img, &info);
- framebits = calloc(1, info.nframes / CHAR_BIT + 1);
+ framebits = calloc(1, img->frames / CHAR_BIT + 1);
if (!framebits) {
return EXIT_FAILURE;
}
/* Figure out what images we're extracting. */
if (!argv[0]) {
/* extract all images by default. */
- memset(framebits, -1, info.nframes / CHAR_BIT + 1);
+ memset(framebits, -1, img->frames / CHAR_BIT + 1);
} else {
for (i = 0; argv[i]; i++) {
- parserange(&info, argv[i], framebits);
+ parserange(img->frames, argv[i], framebits);
}
}
}
/* Extract the images, in order. */
- for (i = 0; i < info.nframes; i++) {
+ for (i = 0; i < img->frames; i++) {
unsigned char **data;
unsigned char **mask;
mask = lbx_img_getmask(img);
- if (!outpng(i, data, mask, info.width, info.height, palette)) {
+ if (!outpng(i, data, mask, img->width, img->height, palette)) {
extracted = 1;
}
}
lbx_img_getinfo(img, &info);
printf("%s is %ux%u LBX image, %u frame(s)%s%s\n",
- file, info.width, info.height, info.nframes,
+ file, img->width, img->height, img->frames,
info.palettesz ? ", embedded palette" : "",
- info.chunk ? ", chunked" : "",
+ img->chunk ? ", chunked" : "",
info.looping ? ", loops" : "");
}