2 * Copyright (C) 2007 Benjamin Otte <otte@gnome.org>
4 * This library 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.
9 * This library 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.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301 USA
24 #include "swfdec_image_decoder.h"
25 #include "swfdec_debug.h"
26 #include "swfdec_image.h"
28 G_DEFINE_TYPE (SwfdecImageDecoder
, swfdec_image_decoder
, SWFDEC_TYPE_DECODER
)
31 swfdec_image_decoder_dispose (GObject
*object
)
33 SwfdecImageDecoder
*image
= SWFDEC_IMAGE_DECODER (object
);
36 swfdec_buffer_queue_unref (image
->queue
);
41 g_object_unref (image
->image
);
45 G_OBJECT_CLASS (swfdec_image_decoder_parent_class
)->dispose (object
);
49 swfdec_image_decoder_parse (SwfdecDecoder
*dec
, SwfdecBuffer
*buffer
)
51 SwfdecImageDecoder
*image
= SWFDEC_IMAGE_DECODER (dec
);
53 if (image
->queue
== NULL
)
54 image
->queue
= swfdec_buffer_queue_new ();
55 swfdec_buffer_queue_push (image
->queue
, buffer
);
56 dec
->bytes_loaded
+= buffer
->length
;
57 if (dec
->bytes_loaded
> dec
->bytes_total
)
58 dec
->bytes_total
= dec
->bytes_loaded
;
62 /* FIXME: move this to swfdec_image API? */
64 swfdec_image_get_size (SwfdecImage
*image
, guint
*w
, guint
*h
)
66 cairo_surface_t
*surface
;
68 surface
= swfdec_image_create_surface (image
, NULL
);
73 *w
= cairo_image_surface_get_width (surface
);
75 *h
= cairo_image_surface_get_width (surface
);
77 cairo_surface_destroy (surface
);
83 swfdec_image_decoder_eof (SwfdecDecoder
*dec
)
85 SwfdecImageDecoder
*image
= SWFDEC_IMAGE_DECODER (dec
);
89 if (image
->queue
== NULL
)
91 depth
= swfdec_buffer_queue_get_depth (image
->queue
);
93 swfdec_buffer_queue_unref (image
->queue
);
95 return SWFDEC_STATUS_ERROR
;
97 buffer
= swfdec_buffer_queue_pull (image
->queue
,
98 swfdec_buffer_queue_get_depth (image
->queue
));
99 swfdec_buffer_queue_unref (image
->queue
);
101 image
->image
= swfdec_image_new (buffer
);
102 if (!swfdec_image_get_size (image
->image
, &dec
->width
, &dec
->height
))
103 return SWFDEC_STATUS_ERROR
;
104 dec
->frames_loaded
= 1;
105 dec
->frames_total
= 1;
106 if (image
->image
->type
== SWFDEC_IMAGE_TYPE_JPEG
)
107 dec
->data_type
= SWFDEC_LOADER_DATA_JPEG
;
108 else if (image
->image
->type
== SWFDEC_IMAGE_TYPE_PNG
)
109 dec
->data_type
= SWFDEC_LOADER_DATA_PNG
;
112 return SWFDEC_STATUS_INIT
| SWFDEC_STATUS_IMAGE
;
116 swfdec_image_decoder_class_init (SwfdecImageDecoderClass
*class)
118 GObjectClass
*object_class
= G_OBJECT_CLASS (class);
119 SwfdecDecoderClass
*decoder_class
= SWFDEC_DECODER_CLASS (class);
121 object_class
->dispose
= swfdec_image_decoder_dispose
;
123 decoder_class
->parse
= swfdec_image_decoder_parse
;
124 decoder_class
->eof
= swfdec_image_decoder_eof
;
128 swfdec_image_decoder_init (SwfdecImageDecoder
*s
)