Mercurial > mplayer.hg
annotate libmpcodecs/vd_zrmjpeg.c @ 36588:dfde4dedb965
Add MSGTR_PREFERENCES_FontAutoScaleMode.
author | ib |
---|---|
date | Tue, 21 Jan 2014 20:19:51 +0000 |
parents | 494c251bd39e |
children |
rev | line source |
---|---|
11386
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
1 /* |
27509
d97a607821f1
Replace casual GPL notices by proper license headers.
diego
parents:
25962
diff
changeset
|
2 * Copyright (C) 2005 Rik Snel <rsnel@cube.dyndns.org> |
d97a607821f1
Replace casual GPL notices by proper license headers.
diego
parents:
25962
diff
changeset
|
3 * - based on vd_mpegpes.c by A'rpi (C) 2002-2003 |
11386
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
4 * - guess_mjpeg_type code stolen from lav_io.c (C) 2000 Rainer Johanni |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
5 * <Rainer@Johanni.de> from the mjpegtools package |
27509
d97a607821f1
Replace casual GPL notices by proper license headers.
diego
parents:
25962
diff
changeset
|
6 * |
d97a607821f1
Replace casual GPL notices by proper license headers.
diego
parents:
25962
diff
changeset
|
7 * This file is part of MPlayer. |
d97a607821f1
Replace casual GPL notices by proper license headers.
diego
parents:
25962
diff
changeset
|
8 * |
d97a607821f1
Replace casual GPL notices by proper license headers.
diego
parents:
25962
diff
changeset
|
9 * MPlayer is free software; you can redistribute it and/or modify |
d97a607821f1
Replace casual GPL notices by proper license headers.
diego
parents:
25962
diff
changeset
|
10 * it under the terms of the GNU General Public License as published by |
d97a607821f1
Replace casual GPL notices by proper license headers.
diego
parents:
25962
diff
changeset
|
11 * the Free Software Foundation; either version 2 of the License, or |
d97a607821f1
Replace casual GPL notices by proper license headers.
diego
parents:
25962
diff
changeset
|
12 * (at your option) any later version. |
d97a607821f1
Replace casual GPL notices by proper license headers.
diego
parents:
25962
diff
changeset
|
13 * |
d97a607821f1
Replace casual GPL notices by proper license headers.
diego
parents:
25962
diff
changeset
|
14 * MPlayer is distributed in the hope that it will be useful, |
d97a607821f1
Replace casual GPL notices by proper license headers.
diego
parents:
25962
diff
changeset
|
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
d97a607821f1
Replace casual GPL notices by proper license headers.
diego
parents:
25962
diff
changeset
|
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
d97a607821f1
Replace casual GPL notices by proper license headers.
diego
parents:
25962
diff
changeset
|
17 * GNU General Public License for more details. |
d97a607821f1
Replace casual GPL notices by proper license headers.
diego
parents:
25962
diff
changeset
|
18 * |
d97a607821f1
Replace casual GPL notices by proper license headers.
diego
parents:
25962
diff
changeset
|
19 * You should have received a copy of the GNU General Public License along |
d97a607821f1
Replace casual GPL notices by proper license headers.
diego
parents:
25962
diff
changeset
|
20 * with MPlayer; if not, write to the Free Software Foundation, Inc., |
d97a607821f1
Replace casual GPL notices by proper license headers.
diego
parents:
25962
diff
changeset
|
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
11386
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
22 */ |
27509
d97a607821f1
Replace casual GPL notices by proper license headers.
diego
parents:
25962
diff
changeset
|
23 |
11386
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
24 #include <stdio.h> |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
25 #include <stdlib.h> |
35912 | 26 #include <strings.h> |
11386
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
27 |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
28 #include "config.h" |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
29 #include "mp_msg.h" |
15212
05aa13cdf92f
replace VO and VF numeric flags with #defined identifiers
henry
parents:
14429
diff
changeset
|
30 #include "vfcap.h" |
11386
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
31 |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
32 /* some convenient #define's, is this portable enough? */ |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
33 #define VERBOSE(...) mp_msg(MSGT_DECVIDEO, MSGL_V, "vd_zrmjpeg: " __VA_ARGS__) |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
34 #define ERROR(...) mp_msg(MSGT_DECVIDEO, MSGL_ERR, "vd_zrmjpeg: " __VA_ARGS__) |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
35 #define WARNING(...) mp_msg(MSGT_DECVIDEO, MSGL_WARN, \ |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
36 "vd_zrmjpeg: " __VA_ARGS__) |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
37 |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
38 #include "vd_internal.h" |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
39 |
30504
cc27da5d7286
Mark all ad_info_t/vd_info_t structure declarations as const.
diego
parents:
29263
diff
changeset
|
40 static const vd_info_t info = |
11386
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
41 { |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
42 "Zoran MJPEG Video passthrough", |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
43 "zrmjpeg", |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
44 "Rik Snel <snel@phys.uu.nl>", |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
45 "Rik Snel <snel@phys.uu.nl>", |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
46 "for hw decoders (DC10(+)/buz/lml33)" |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
47 }; |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
48 |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
49 LIBVD_EXTERN(zrmjpeg) |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
50 |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
51 #include "libvo/video_out.h" |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
52 |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
53 typedef struct { |
25962 | 54 int vo_initialized; |
11386
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
55 unsigned int preferred_csp; |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
56 } vd_zrmjpeg_ctx_t; |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
57 |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
58 static int query_format(sh_video_t *sh, unsigned int format) { |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
59 vd_zrmjpeg_ctx_t *ctx = sh->context; |
15212
05aa13cdf92f
replace VO and VF numeric flags with #defined identifiers
henry
parents:
14429
diff
changeset
|
60 if (format == ctx->preferred_csp) return VFCAP_CSP_SUPPORTED; |
11386
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
61 return CONTROL_FALSE; |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
62 } |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
27731
diff
changeset
|
63 |
11386
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
64 // to set/get/query special features/parameters |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
65 static int control(sh_video_t *sh, int cmd, void* arg, ...) { |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
66 switch (cmd) { |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
67 case VDCTRL_QUERY_FORMAT: |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
68 return query_format(sh, *((unsigned int*)arg)); |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
69 } |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
70 return CONTROL_UNKNOWN; |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
71 } |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
72 |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
73 // init driver |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
74 static int init(sh_video_t *sh) { |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
75 vd_zrmjpeg_ctx_t *ctx; |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
76 |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
77 VERBOSE("init called\n"); |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
78 ctx = malloc(sizeof(*ctx)); |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
79 if (!ctx) return 0; |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
80 memset(ctx, 0, sizeof(*ctx)); |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
81 sh->context = ctx; |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
82 |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
83 /* defer init of vo until the first frame is known */ |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
27731
diff
changeset
|
84 return 1; |
11386
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
85 #if 0 |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
27731
diff
changeset
|
86 return mpcodecs_config_vo(sh, sh->disp_w, sh->disp_h, IMGFMT_ZRMJPEGIT); |
11386
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
87 #endif |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
88 } |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
89 |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
90 // uninit driver |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
91 static void uninit(sh_video_t *sh) { |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
92 free(sh->context); |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
93 } |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
94 |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
95 /* parts directly stolen from scan_jpg() and lav_open_input_file */ |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
96 static int get_int2(unsigned char *buf) { |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
97 return buf[0]*256 + buf[1]; |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
98 } |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
99 |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
100 #define M_SOF0 0xC0 |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
101 #define M_SOF1 0xC1 |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
102 #define M_DHT 0xC4 |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
103 #define M_SOI 0xD8 /* Start Of Image (beginning of datastream) */ |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
104 #define M_EOI 0xD9 /* End Of Image (end of datastream) */ |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
105 #define M_SOS 0xDA /* Start Of Scan (begins compressed data) */ |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
106 #define M_DQT 0xDB |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
107 #define M_APP0 0xE0 |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
108 #define M_APP1 0xE1 |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
109 /* returns 0 in case of failure */ |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
110 static unsigned int guess_mjpeg_type(unsigned char *data, unsigned int size, |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
111 int d_height) { |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
112 unsigned int p; |
27731 | 113 int marker, length, height, i, hf[3], vf[3]; |
11386
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
114 unsigned int app0 = 0, header = 0; |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
115 |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
116 /* The initial marker must be SIO */ |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
117 if (size < 2) { |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
118 ERROR("JPEG data too short (%d bytes)\n", size); |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
119 return 0; |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
120 } |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
121 |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
122 if (data[0] != 0xFF || data[1] != M_SOI) { |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
123 ERROR("JPEG data must start with FFD8, but doesn't\n"); |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
124 return 0; |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
125 } |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
27731
diff
changeset
|
126 |
11386
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
127 p = 2; /* pointer within jpeg data */ |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
128 |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
129 while (p < size) { |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
130 /* search 0xFF */ |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
131 while(data[p] != 0xFF) { |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
132 p++; |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
133 if (p >= size) return 0; |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
134 } |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
27731
diff
changeset
|
135 |
11386
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
136 /* get marker code, skip duplicate FF's */ |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
137 while(data[p] == 0xFF) { |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
138 p++; |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
139 if (p >= size) return 0; |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
140 } |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
141 |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
142 marker = data[p++]; |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
143 |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
144 /* marker may have an associated length */ |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
145 if (p <= size - 2) length = get_int2(data+p); |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
27731
diff
changeset
|
146 else length = 0; |
11386
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
147 |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
148 switch (marker) { |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
149 case M_SOF0: |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
150 case M_SOF1: |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
151 header = p-2; |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
152 VERBOSE("found offset of header %u\n", |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
153 header); |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
154 break; |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
155 case M_SOS: |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
156 size = 0; |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
157 continue; |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
158 case M_APP0: |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
159 app0 = p-2; |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
160 VERBOSE("found offset of APP0 %u\n", |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
161 app0); |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
162 break; |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
163 } |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
164 |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
165 /* these markers shouldn't have parameters, |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
166 * i.e. we don't need to skip anaything */ |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
27731
diff
changeset
|
167 if (marker == 0 || marker == 1 || |
11386
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
168 (marker >= 0xd0 && marker < 0xd8)) |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
27731
diff
changeset
|
169 continue; |
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
27731
diff
changeset
|
170 |
11386
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
171 if (p + length <= size) p += length; |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
172 else { |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
173 ERROR("input JPEG too short, data missing\n"); |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
174 return 0; |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
175 } |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
176 } |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
177 |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
178 if (!header) { |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
179 ERROR("JPEG header (with resolution and sampling factors) not found\n"); |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
180 return 0; |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
181 } |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
182 |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
183 if (data[header + 9] != 3) { |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
184 ERROR("JPEG has wrong number of components\n"); |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
185 return 0; |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
186 } |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
187 |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
188 /* get the horizontal and vertical sample factors */ |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
189 for (i = 0; i < 3; i++) { |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
190 hf[i] = data[header + 10 + 3*i + 1]>>4; |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
191 vf[i] = data[header + 10 + 3*i + 1]&0x0F; |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
192 } |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
193 |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
194 if (hf[0] != 2 || hf[1] != 1 || hf[2] != 1 || |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
195 vf[0] != 1 || vf[1] != 1 || vf[2] != 1) { |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
196 ERROR("JPEG has wrong internal image format\n"); |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
197 } else VERBOSE("JPEG has colorspace YUV422 with minimal sampling factors (good)\n"); |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
198 |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
199 height = get_int2(data + header + 5); |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
200 if (height == d_height) { |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
201 VERBOSE("data is non interlaced\n"); |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
202 return IMGFMT_ZRMJPEGNI; |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
203 } |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
204 |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
205 if (2*height != d_height) { |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
206 ERROR("something very inconsistent happened\n"); |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
207 return 0; |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
208 } |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
209 |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
210 |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
211 if (app0 && get_int2(data + app0 + 2) >= 5 && |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
212 strncasecmp((char*)(data + app0 + 4), "AVI1", 4) == 0) { |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
213 if (data[app0+8] == 1) { |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
214 VERBOSE("data is interlaced, APP0: top-first (1)\n"); |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
215 return IMGFMT_ZRMJPEGIT; |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
216 } else { |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
217 VERBOSE("data is interlaced, APP0: bottom-first (%d)\n", |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
218 data[app0+8]); |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
219 return IMGFMT_ZRMJPEGIB; |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
220 } |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
221 } else { |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
222 VERBOSE("data is interlaced, no (valid) APP0 marker, " |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
223 "guessing top-first\n"); |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
224 return IMGFMT_ZRMJPEGIT; |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
225 } |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
226 |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
27731
diff
changeset
|
227 |
11386
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
228 return 0; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
27731
diff
changeset
|
229 } |
11386
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
230 |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
231 // decode a frame |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
232 static mp_image_t* decode(sh_video_t *sh, void* data, int len, int flags) { |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
233 mp_image_t* mpi; |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
234 vd_zrmjpeg_ctx_t *ctx = sh->context; |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
235 |
34772 | 236 if (len <= 0 && !data) return NULL; // delay flush |
237 | |
25962 | 238 if (!ctx->vo_initialized) { |
11386
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
239 ctx->preferred_csp = guess_mjpeg_type(data, len, sh->disp_h); |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
240 if (ctx->preferred_csp == 0) return NULL; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
27731
diff
changeset
|
241 mpcodecs_config_vo(sh, sh->disp_w, sh->disp_h, |
11386
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
242 ctx->preferred_csp); |
25962 | 243 ctx->vo_initialized = 1; |
11386
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
244 } |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
245 |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
27731
diff
changeset
|
246 mpi = mpcodecs_get_image(sh, MP_IMGTYPE_EXPORT, 0, |
11386
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
247 sh->disp_w, sh->disp_h); |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
248 /* abuse of mpi */ |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
249 mpi->planes[0]=(uint8_t*)data; |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
250 mpi->planes[1]=(uint8_t*)len; |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
251 return mpi; |
229079491864
addition of special image formats for Zoran MJPEG, and vd_zrmjpeg.c
rik
parents:
diff
changeset
|
252 } |