add blend mode tests
[swfdec.git] / swfdec / swfdec_video_decoder_vp6_alpha.c
blob8e443fcbbc5861cb7f4d52ca3f786bbcec1c77e6
1 /* Swfdec
2 * Copyright (C) 2007-2008 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.
8 *
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
20 #ifdef HAVE_CONFIG_H
21 #include "config.h"
22 #endif
24 #include <liboil/liboil.h>
25 #include "swfdec_video_decoder_vp6_alpha.h"
26 #include "swfdec_bits.h"
27 #include "swfdec_debug.h"
29 G_DEFINE_TYPE (SwfdecVideoDecoderVp6Alpha, swfdec_video_decoder_vp6_alpha, SWFDEC_TYPE_VIDEO_DECODER)
31 static gboolean
32 swfdec_video_decoder_vp6_alpha_prepare (guint codec, char **missing)
34 if (codec != SWFDEC_VIDEO_CODEC_VP6_ALPHA)
35 return FALSE;
37 return swfdec_video_decoder_prepare (SWFDEC_VIDEO_CODEC_VP6, missing);
40 static SwfdecVideoDecoder *
41 swfdec_video_decoder_vp6_alpha_create (guint codec)
43 if (codec != SWFDEC_VIDEO_CODEC_VP6_ALPHA)
44 return NULL;
46 return g_object_new (SWFDEC_TYPE_VIDEO_DECODER_VP6_ALPHA, NULL);
49 static void
50 swfdec_video_decoder_vp6_alpha_decode (SwfdecVideoDecoder *dec, SwfdecBuffer *buffer)
52 SwfdecVideoDecoderVp6Alpha *vp6 = SWFDEC_VIDEO_DECODER_VP6_ALPHA (dec);
53 SwfdecBuffer *tmp;
54 SwfdecBits bits;
55 guint size;
57 swfdec_bits_init (&bits, buffer);
58 size = swfdec_bits_get_bu24 (&bits);
59 tmp = swfdec_bits_get_buffer (&bits, size);
60 if (tmp == NULL) {
61 swfdec_video_decoder_error (dec, "invalid buffer size for image buffer");
62 return;
64 swfdec_video_decoder_decode (vp6->image, tmp);
65 swfdec_buffer_unref (tmp);
66 tmp = swfdec_bits_get_buffer (&bits, -1);
67 if (tmp == NULL) {
68 swfdec_video_decoder_error (dec, "invalid buffer size for mask buffer");
69 return;
71 swfdec_video_decoder_decode (vp6->mask, tmp);
72 swfdec_buffer_unref (tmp);
73 if (swfdec_video_decoder_get_error (vp6->image) ||
74 swfdec_video_decoder_get_error (vp6->mask)) {
75 swfdec_video_decoder_error (dec, "decoding of VP6 data failed");
76 return;
79 if (swfdec_video_decoder_get_width (vp6->image) != swfdec_video_decoder_get_width (vp6->mask) ||
80 swfdec_video_decoder_get_height (vp6->image) != swfdec_video_decoder_get_height (vp6->mask)) {
81 SWFDEC_ERROR ("size of mask %ux%u doesn't match image size %ux%u",
82 swfdec_video_decoder_get_width (vp6->mask), swfdec_video_decoder_get_height (vp6->mask),
83 swfdec_video_decoder_get_width (vp6->image), swfdec_video_decoder_get_height (vp6->image));
84 return;
86 dec->width = swfdec_video_decoder_get_width (vp6->image);
87 dec->height = swfdec_video_decoder_get_height (vp6->image);
88 dec->plane[0] = vp6->image->plane[0];
89 dec->plane[1] = vp6->image->plane[1];
90 dec->plane[2] = vp6->image->plane[2];
91 dec->rowstride[0] = vp6->image->rowstride[0];
92 dec->rowstride[1] = vp6->image->rowstride[1];
93 dec->rowstride[2] = vp6->image->rowstride[2];
94 dec->mask = vp6->mask->plane[0];
95 dec->mask_rowstride = vp6->mask->rowstride[0];
98 static void
99 swfdec_video_decoder_vp6_alpha_dispose (GObject *object)
101 SwfdecVideoDecoderVp6Alpha *vp6 = SWFDEC_VIDEO_DECODER_VP6_ALPHA (object);
103 if (vp6->image) {
104 g_object_unref (vp6->image);
105 vp6->image = NULL;
107 if (vp6->mask) {
108 g_object_unref (vp6->mask);
109 vp6->mask = NULL;
112 G_OBJECT_CLASS (swfdec_video_decoder_vp6_alpha_parent_class)->dispose (object);
115 static void
116 swfdec_video_decoder_vp6_alpha_class_init (SwfdecVideoDecoderVp6AlphaClass *klass)
118 GObjectClass *object_class = G_OBJECT_CLASS (klass);
119 SwfdecVideoDecoderClass *decoder_class = SWFDEC_VIDEO_DECODER_CLASS (klass);
121 object_class->dispose = swfdec_video_decoder_vp6_alpha_dispose;
123 decoder_class->prepare = swfdec_video_decoder_vp6_alpha_prepare;
124 decoder_class->create = swfdec_video_decoder_vp6_alpha_create;
125 decoder_class->decode = swfdec_video_decoder_vp6_alpha_decode;
128 static void
129 swfdec_video_decoder_vp6_alpha_init (SwfdecVideoDecoderVp6Alpha *vp6)
131 vp6->image = swfdec_video_decoder_new (SWFDEC_VIDEO_CODEC_VP6);
132 vp6->mask = swfdec_video_decoder_new (SWFDEC_VIDEO_CODEC_VP6);
134 if (swfdec_video_decoder_get_error (vp6->image) ||
135 swfdec_video_decoder_get_error (vp6->mask)) {
136 swfdec_video_decoder_error (SWFDEC_VIDEO_DECODER (vp6),
137 "error initializing children VP6 decoders");