| 195 | } |
| 196 | |
| 197 | int ff_mjpeg_decode_sof(MJpegDecodeContext *s) |
| 198 | { |
| 199 | int len, nb_components, i, width, height, pix_fmt_id; |
| 200 | |
| 201 | /* XXX: verify len field validity */ |
| 202 | len = get_bits(&s->gb, 16); |
| 203 | s->bits= get_bits(&s->gb, 8); |
| 204 | |
| 205 | if(s->pegasus_rct) s->bits=9; |
| 206 | if(s->bits==9 && !s->pegasus_rct) s->rct=1; //FIXME ugly |
| 207 | |
| 208 | if (s->bits != 8 && !s->lossless){ |
| 209 | av_log(s->avctx, AV_LOG_ERROR, "only 8 bits/component accepted\n"); |
| 210 | return -1; |
| 211 | } |
| 212 | |
| 213 | height = get_bits(&s->gb, 16); |
| 214 | width = get_bits(&s->gb, 16); |
| 215 | |
| 216 | //HACK for odd_height.mov |
| 217 | if(s->interlaced && s->width == width && s->height == height + 1) |
| 218 | height= s->height; |
| 219 | |
| 220 | av_log(s->avctx, AV_LOG_DEBUG, "sof0: picture: %dx%d\n", width, height); |
| 221 | if(avcodec_check_dimensions(s->avctx, width, height)) |
| 222 | return -1; |
| 223 | |
| 224 | nb_components = get_bits(&s->gb, 8); |
| 225 | if (nb_components <= 0 || |
| 226 | nb_components > MAX_COMPONENTS) |
| 227 | return -1; |
| 228 | if (s->ls && !(s->bits <= 8 || nb_components == 1)){ |
| 229 | av_log(s->avctx, AV_LOG_ERROR, "only <= 8 bits/component or 16-bit gray accepted for JPEG-LS\n"); |
| 230 | return -1; |
| 231 | } |
| 232 | s->nb_components = nb_components; |
| 233 | s->h_max = 1; |
| 234 | s->v_max = 1; |
| 235 | for(i=0;i<nb_components;i++) { |
| 236 | /* component id */ |
| 237 | s->component_id[i] = get_bits(&s->gb, 8) - 1; |
| 238 | s->h_count[i] = get_bits(&s->gb, 4); |
| 239 | s->v_count[i] = get_bits(&s->gb, 4); |
| 240 | /* compute hmax and vmax (only used in interleaved case) */ |
| 241 | if (s->h_count[i] > s->h_max) |
| 242 | s->h_max = s->h_count[i]; |
| 243 | if (s->v_count[i] > s->v_max) |
| 244 | s->v_max = s->v_count[i]; |
| 245 | s->quant_index[i] = get_bits(&s->gb, 8); |
| 246 | if (s->quant_index[i] >= 4) |
| 247 | return -1; |
| 248 | av_log(s->avctx, AV_LOG_DEBUG, "component %d %d:%d id: %d quant:%d\n", i, s->h_count[i], |
| 249 | s->v_count[i], s->component_id[i], s->quant_index[i]); |
| 250 | } |
| 251 | |
| 252 | if(s->ls && (s->h_max > 1 || s->v_max > 1)) { |
| 253 | av_log(s->avctx, AV_LOG_ERROR, "Subsampling in JPEG-LS is not supported.\n"); |
| 254 | return -1; |
no test coverage detected