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)) ||
|
9114
|
35 ((IMGFMT_BGR_DEPTH(req_format) == 32) && (ctx->depth == 24)) ||
|
|
36 ((IMGFMT_BGR_DEPTH(req_format) == 24) && (ctx->depth == 32)))
|
6720
|
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;
|
9114
|
72 case 32:
|
|
73 mp_msg(MSGT_DECVIDEO,MSGL_INFO,"[qtrle] 32 bpp file, alpha channel will be ignored.\n");
|
6720
|
74 case 24:
|
|
75 break;
|
|
76 default:
|
|
77 mp_msg(MSGT_DECVIDEO,MSGL_ERR,
|
|
78 "*** FYI: This Quicktime file is using %d-bit RLE Animation\n" \
|
|
79 "encoding, which is not yet supported by MPlayer. But if you upload\n" \
|
|
80 "this Quicktime file to the MPlayer FTP, the team could look at it.\n",
|
|
81 ctx->depth);
|
|
82 return(0);
|
|
83 }
|
|
84
|
|
85 return mpcodecs_config_vo(sh,sh->disp_w,sh->disp_h,IMGFMT_BGR|ctx->depth);
|
4989
|
86 }
|
|
87
|
|
88 // uninit driver
|
|
89 static void uninit(sh_video_t *sh){
|
6720
|
90 vd_qtrle_ctx *ctx = sh->context;
|
|
91
|
|
92 if (ctx->palette)
|
|
93 free(ctx->palette);
|
|
94 free(ctx);
|
4989
|
95 }
|
|
96
|
|
97 //mp_image_t* mpcodecs_get_image(sh_video_t *sh, int mp_imgtype, int mp_imgflag, int w, int h);
|
|
98
|
|
99 void qt_decode_rle(
|
|
100 unsigned char *encoded,
|
|
101 int encoded_size,
|
|
102 unsigned char *decoded,
|
|
103 int width,
|
|
104 int height,
|
|
105 int encoded_bpp,
|
|
106 int bytes_per_pixel);
|
|
107
|
|
108 // decode a frame
|
|
109 static mp_image_t* decode(sh_video_t *sh,void* data,int len,int flags){
|
6720
|
110 vd_qtrle_ctx *ctx = sh->context;
|
4989
|
111 mp_image_t* mpi;
|
|
112 if(len<=0) return NULL; // skipped frame
|
|
113
|
|
114 mpi=mpcodecs_get_image(sh, MP_IMGTYPE_STATIC, MP_IMGFLAG_PRESERVE,
|
|
115 sh->disp_w, sh->disp_h);
|
|
116 if(!mpi) return NULL;
|
|
117
|
|
118 qt_decode_rle(
|
|
119 data,len, mpi->planes[0],
|
|
120 sh->disp_w, sh->disp_h,
|
|
121 sh->bih->biBitCount,
|
|
122 mpi->bpp/8);
|
6720
|
123
|
|
124 if (ctx->palette)
|
|
125 mpi->planes[1] = ctx->palette;
|
4989
|
126
|
|
127 return mpi;
|
|
128 }
|