annotate libmpcodecs/vd_qtrle.c @ 7051:d03fad6123a3

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