annotate libmpcodecs/vd_qtrle.c @ 7800:1dd34db6cb92

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