4989
|
1 #include <stdio.h>
|
|
2 #include <stdlib.h>
|
|
3
|
|
4 #include "config.h"
|
|
5 #include "mp_msg.h"
|
|
6
|
|
7 #include "vd_internal.h"
|
|
8
|
|
9 static vd_info_t info = {
|
|
10 "Quicktime Animation (RLE) decoder",
|
|
11 "qtrle",
|
|
12 VFM_QTRLE,
|
|
13 "A'rpi",
|
|
14 "Mike Melanson",
|
|
15 "native codec"
|
|
16 };
|
|
17
|
|
18 LIBVD_EXTERN(qtrle)
|
|
19
|
6720
|
20 typedef struct {
|
|
21 int depth;
|
|
22 void *palette;
|
|
23 } vd_qtrle_ctx;
|
|
24
|
4989
|
25 // to set/get/query special features/parameters
|
|
26 static int control(sh_video_t *sh,int cmd,void* arg,...){
|
6720
|
27 vd_qtrle_ctx *ctx = sh->context;
|
|
28 switch(cmd)
|
|
29 {
|
|
30 case VDCTRL_QUERY_FORMAT:
|
|
31 {
|
|
32 int req_format = *((int*)arg);
|
|
33
|
|
34 /* qtrle24 supports 32bit output too */
|
|
35 if ((req_format == (IMGFMT_BGR|ctx->depth)) ||
|
|
36 ((IMGFMT_BGR_DEPTH(req_format) == 32) && (ctx->depth == 24)))
|
|
37 return(CONTROL_TRUE);
|
|
38 else
|
|
39 return(CONTROL_FALSE);
|
|
40 }
|
|
41 }
|
4989
|
42 return CONTROL_UNKNOWN;
|
|
43 }
|
|
44
|
|
45 // init driver
|
|
46 static int init(sh_video_t *sh){
|
6720
|
47 vd_qtrle_ctx *ctx;
|
|
48
|
|
49 ctx = sh->context = malloc(sizeof(vd_qtrle_ctx));
|
|
50 if (!ctx)
|
|
51 return(0);
|
|
52 memset(ctx, 0, sizeof(vd_qtrle_ctx));
|
4989
|
53
|
6720
|
54 if (!sh->bih)
|
|
55 return(0);
|
|
56 ctx->depth = sh->bih->biBitCount;
|
|
57
|
|
58 switch(ctx->depth)
|
|
59 {
|
|
60 case 2:
|
|
61 case 4:
|
|
62 case 8:
|
|
63 if (sh->bih->biSize > 40)
|
|
64 {
|
|
65 ctx->palette = malloc(sh->bih->biSize-40);
|
|
66 memcpy(ctx->palette, sh->bih+40, sh->bih->biSize-40);
|
|
67 }
|
|
68 break;
|
|
69 case 16:
|
|
70 ctx->depth--; /* this is the trick ;) */
|
|
71 break;
|
|
72 case 24:
|
|
73 break;
|
|
74 default:
|
|
75 mp_msg(MSGT_DECVIDEO,MSGL_ERR,
|
|
76 "*** FYI: This Quicktime file is using %d-bit RLE Animation\n" \
|
|
77 "encoding, which is not yet supported by MPlayer. But if you upload\n" \
|
|
78 "this Quicktime file to the MPlayer FTP, the team could look at it.\n",
|
|
79 ctx->depth);
|
|
80 return(0);
|
|
81 }
|
|
82
|
|
83 return mpcodecs_config_vo(sh,sh->disp_w,sh->disp_h,IMGFMT_BGR|ctx->depth);
|
4989
|
84 }
|
|
85
|
|
86 // uninit driver
|
|
87 static void uninit(sh_video_t *sh){
|
6720
|
88 vd_qtrle_ctx *ctx = sh->context;
|
|
89
|
|
90 if (ctx->palette)
|
|
91 free(ctx->palette);
|
|
92 free(ctx);
|
4989
|
93 }
|
|
94
|
|
95 //mp_image_t* mpcodecs_get_image(sh_video_t *sh, int mp_imgtype, int mp_imgflag, int w, int h);
|
|
96
|
|
97 void qt_decode_rle(
|
|
98 unsigned char *encoded,
|
|
99 int encoded_size,
|
|
100 unsigned char *decoded,
|
|
101 int width,
|
|
102 int height,
|
|
103 int encoded_bpp,
|
|
104 int bytes_per_pixel);
|
|
105
|
|
106 // decode a frame
|
|
107 static mp_image_t* decode(sh_video_t *sh,void* data,int len,int flags){
|
6720
|
108 vd_qtrle_ctx *ctx = sh->context;
|
4989
|
109 mp_image_t* mpi;
|
|
110 if(len<=0) return NULL; // skipped frame
|
|
111
|
|
112 mpi=mpcodecs_get_image(sh, MP_IMGTYPE_STATIC, MP_IMGFLAG_PRESERVE,
|
|
113 sh->disp_w, sh->disp_h);
|
|
114 if(!mpi) return NULL;
|
|
115
|
|
116 qt_decode_rle(
|
|
117 data,len, mpi->planes[0],
|
|
118 sh->disp_w, sh->disp_h,
|
|
119 sh->bih->biBitCount,
|
|
120 mpi->bpp/8);
|
6720
|
121
|
|
122 if (ctx->palette)
|
|
123 mpi->planes[1] = ctx->palette;
|
4989
|
124
|
|
125 return mpi;
|
|
126 }
|