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
26 #include <liboil/liboil.h>
28 #include "swfdec_codec_video.h"
29 #include "swfdec_bits.h"
30 #include "swfdec_debug.h"
31 #include "swfdec_internal.h"
33 typedef struct _SwfdecCodecVp6Alpha SwfdecCodecVp6Alpha
;
35 struct _SwfdecCodecVp6Alpha
{
36 SwfdecVideoDecoder decoder
; /* the decoder */
37 SwfdecVideoDecoder
* image
; /* the image decoder */
38 SwfdecVideoDecoder
* alpha
; /* the alpha decoder */
42 swfdec_video_decoder_vp6_alpha_decode (SwfdecVideoDecoder
*dec
, SwfdecBuffer
*buffer
,
43 SwfdecVideoImage
*image
)
45 SwfdecCodecVp6Alpha
*vp6
= (SwfdecCodecVp6Alpha
*) dec
;
47 SwfdecVideoImage alpha
;
51 swfdec_bits_init (&bits
, buffer
);
52 size
= swfdec_bits_get_bu24 (&bits
);
53 tmp
= swfdec_bits_get_buffer (&bits
, size
);
56 if (!vp6
->image
->decode (vp6
->image
, tmp
, image
)) {
57 swfdec_buffer_unref (tmp
);
60 swfdec_buffer_unref (tmp
);
61 tmp
= swfdec_bits_get_buffer (&bits
, -1);
64 if (!vp6
->alpha
->decode (vp6
->alpha
, tmp
, &alpha
)) {
65 swfdec_buffer_unref (tmp
);
68 swfdec_buffer_unref (tmp
);
69 if (alpha
.width
!= image
->width
|| alpha
.height
!= image
->height
) {
70 SWFDEC_ERROR ("size of mask doesn't match image: %ux%u vs %ux%u",
71 alpha
.width
, alpha
.height
, image
->width
, image
->height
);
74 image
->mask
= alpha
.plane
[0];
75 image
->mask_rowstride
= alpha
.rowstride
[0];
80 swfdec_video_decoder_vp6_alpha_free (SwfdecVideoDecoder
*dec
)
82 SwfdecCodecVp6Alpha
*vp6
= (SwfdecCodecVp6Alpha
*) dec
;
85 swfdec_video_decoder_free (vp6
->image
);
87 swfdec_video_decoder_free (vp6
->alpha
);
92 swfdec_video_decoder_vp6_alpha_new (SwfdecVideoCodec type
)
94 SwfdecCodecVp6Alpha
*vp6
;
96 if (type
!= SWFDEC_VIDEO_CODEC_VP6_ALPHA
)
99 vp6
= g_new0 (SwfdecCodecVp6Alpha
, 1);
100 vp6
->decoder
.decode
= swfdec_video_decoder_vp6_alpha_decode
;
101 vp6
->decoder
.free
= swfdec_video_decoder_vp6_alpha_free
;
102 vp6
->image
= swfdec_video_decoder_new (SWFDEC_VIDEO_CODEC_VP6
);
103 vp6
->alpha
= swfdec_video_decoder_new (SWFDEC_VIDEO_CODEC_VP6
);
104 if (vp6
->alpha
== NULL
|| vp6
->image
== NULL
) {
105 swfdec_video_decoder_vp6_alpha_free (&vp6
->decoder
);
109 return &vp6
->decoder
;