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