Mercurial > libavcodec.hg
comparison mjpegdec.c @ 5042:259b58518ecc libavcodec
move sp5x decoder in its own file
author | aurel |
---|---|
date | Sat, 19 May 2007 14:40:02 +0000 |
parents | 01a165280429 |
children | 924fdd6175b1 |
comparison
equal
deleted
inserted
replaced
5041:01a165280429 | 5042:259b58518ecc |
---|---|
1415 } | 1415 } |
1416 | 1416 |
1417 return buf_ptr - buf; | 1417 return buf_ptr - buf; |
1418 } | 1418 } |
1419 | 1419 |
1420 #include "sp5x.h" | |
1421 | |
1422 static int sp5x_decode_frame(AVCodecContext *avctx, | |
1423 void *data, int *data_size, | |
1424 uint8_t *buf, int buf_size) | |
1425 { | |
1426 #if 0 | |
1427 MJpegDecodeContext *s = avctx->priv_data; | |
1428 #endif | |
1429 const int qscale = 5; | |
1430 uint8_t *buf_ptr, *buf_end, *recoded; | |
1431 int i = 0, j = 0; | |
1432 | |
1433 if (!avctx->width || !avctx->height) | |
1434 return -1; | |
1435 | |
1436 buf_ptr = buf; | |
1437 buf_end = buf + buf_size; | |
1438 | |
1439 #if 1 | |
1440 recoded = av_mallocz(buf_size + 1024); | |
1441 if (!recoded) | |
1442 return -1; | |
1443 | |
1444 /* SOI */ | |
1445 recoded[j++] = 0xFF; | |
1446 recoded[j++] = 0xD8; | |
1447 | |
1448 memcpy(recoded+j, &sp5x_data_dqt[0], sizeof(sp5x_data_dqt)); | |
1449 memcpy(recoded+j+5, &sp5x_quant_table[qscale * 2], 64); | |
1450 memcpy(recoded+j+70, &sp5x_quant_table[(qscale * 2) + 1], 64); | |
1451 j += sizeof(sp5x_data_dqt); | |
1452 | |
1453 memcpy(recoded+j, &sp5x_data_dht[0], sizeof(sp5x_data_dht)); | |
1454 j += sizeof(sp5x_data_dht); | |
1455 | |
1456 memcpy(recoded+j, &sp5x_data_sof[0], sizeof(sp5x_data_sof)); | |
1457 recoded[j+5] = (avctx->coded_height >> 8) & 0xFF; | |
1458 recoded[j+6] = avctx->coded_height & 0xFF; | |
1459 recoded[j+7] = (avctx->coded_width >> 8) & 0xFF; | |
1460 recoded[j+8] = avctx->coded_width & 0xFF; | |
1461 j += sizeof(sp5x_data_sof); | |
1462 | |
1463 memcpy(recoded+j, &sp5x_data_sos[0], sizeof(sp5x_data_sos)); | |
1464 j += sizeof(sp5x_data_sos); | |
1465 | |
1466 for (i = 14; i < buf_size && j < buf_size+1024-2; i++) | |
1467 { | |
1468 recoded[j++] = buf[i]; | |
1469 if (buf[i] == 0xff) | |
1470 recoded[j++] = 0; | |
1471 } | |
1472 | |
1473 /* EOI */ | |
1474 recoded[j++] = 0xFF; | |
1475 recoded[j++] = 0xD9; | |
1476 | |
1477 i = ff_mjpeg_decode_frame(avctx, data, data_size, recoded, j); | |
1478 | |
1479 av_free(recoded); | |
1480 | |
1481 #else | |
1482 /* SOF */ | |
1483 s->bits = 8; | |
1484 s->width = avctx->coded_width; | |
1485 s->height = avctx->coded_height; | |
1486 s->nb_components = 3; | |
1487 s->component_id[0] = 0; | |
1488 s->h_count[0] = 2; | |
1489 s->v_count[0] = 2; | |
1490 s->quant_index[0] = 0; | |
1491 s->component_id[1] = 1; | |
1492 s->h_count[1] = 1; | |
1493 s->v_count[1] = 1; | |
1494 s->quant_index[1] = 1; | |
1495 s->component_id[2] = 2; | |
1496 s->h_count[2] = 1; | |
1497 s->v_count[2] = 1; | |
1498 s->quant_index[2] = 1; | |
1499 s->h_max = 2; | |
1500 s->v_max = 2; | |
1501 | |
1502 s->qscale_table = av_mallocz((s->width+15)/16); | |
1503 avctx->pix_fmt = s->cs_itu601 ? PIX_FMT_YUV420P : PIX_FMT_YUVJ420; | |
1504 s->interlaced = 0; | |
1505 | |
1506 s->picture.reference = 0; | |
1507 if (avctx->get_buffer(avctx, &s->picture) < 0) | |
1508 { | |
1509 av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); | |
1510 return -1; | |
1511 } | |
1512 | |
1513 s->picture.pict_type = I_TYPE; | |
1514 s->picture.key_frame = 1; | |
1515 | |
1516 for (i = 0; i < 3; i++) | |
1517 s->linesize[i] = s->picture.linesize[i] << s->interlaced; | |
1518 | |
1519 /* DQT */ | |
1520 for (i = 0; i < 64; i++) | |
1521 { | |
1522 j = s->scantable.permutated[i]; | |
1523 s->quant_matrixes[0][j] = sp5x_quant_table[(qscale * 2) + i]; | |
1524 } | |
1525 s->qscale[0] = FFMAX( | |
1526 s->quant_matrixes[0][s->scantable.permutated[1]], | |
1527 s->quant_matrixes[0][s->scantable.permutated[8]]) >> 1; | |
1528 | |
1529 for (i = 0; i < 64; i++) | |
1530 { | |
1531 j = s->scantable.permutated[i]; | |
1532 s->quant_matrixes[1][j] = sp5x_quant_table[(qscale * 2) + 1 + i]; | |
1533 } | |
1534 s->qscale[1] = FFMAX( | |
1535 s->quant_matrixes[1][s->scantable.permutated[1]], | |
1536 s->quant_matrixes[1][s->scantable.permutated[8]]) >> 1; | |
1537 | |
1538 /* DHT */ | |
1539 | |
1540 /* SOS */ | |
1541 s->comp_index[0] = 0; | |
1542 s->nb_blocks[0] = s->h_count[0] * s->v_count[0]; | |
1543 s->h_scount[0] = s->h_count[0]; | |
1544 s->v_scount[0] = s->v_count[0]; | |
1545 s->dc_index[0] = 0; | |
1546 s->ac_index[0] = 0; | |
1547 | |
1548 s->comp_index[1] = 1; | |
1549 s->nb_blocks[1] = s->h_count[1] * s->v_count[1]; | |
1550 s->h_scount[1] = s->h_count[1]; | |
1551 s->v_scount[1] = s->v_count[1]; | |
1552 s->dc_index[1] = 1; | |
1553 s->ac_index[1] = 1; | |
1554 | |
1555 s->comp_index[2] = 2; | |
1556 s->nb_blocks[2] = s->h_count[2] * s->v_count[2]; | |
1557 s->h_scount[2] = s->h_count[2]; | |
1558 s->v_scount[2] = s->v_count[2]; | |
1559 s->dc_index[2] = 1; | |
1560 s->ac_index[2] = 1; | |
1561 | |
1562 for (i = 0; i < 3; i++) | |
1563 s->last_dc[i] = 1024; | |
1564 | |
1565 s->mb_width = (s->width * s->h_max * 8 -1) / (s->h_max * 8); | |
1566 s->mb_height = (s->height * s->v_max * 8 -1) / (s->v_max * 8); | |
1567 | |
1568 init_get_bits(&s->gb, buf+14, (buf_size-14)*8); | |
1569 | |
1570 return mjpeg_decode_scan(s); | |
1571 #endif | |
1572 | |
1573 return i; | |
1574 } | |
1575 | |
1576 int ff_mjpeg_decode_end(AVCodecContext *avctx) | 1420 int ff_mjpeg_decode_end(AVCodecContext *avctx) |
1577 { | 1421 { |
1578 MJpegDecodeContext *s = avctx->priv_data; | 1422 MJpegDecodeContext *s = avctx->priv_data; |
1579 int i, j; | 1423 int i, j; |
1580 | 1424 |
1624 ff_mjpeg_decode_end, | 1468 ff_mjpeg_decode_end, |
1625 mjpegb_decode_frame, | 1469 mjpegb_decode_frame, |
1626 CODEC_CAP_DR1, | 1470 CODEC_CAP_DR1, |
1627 NULL | 1471 NULL |
1628 }; | 1472 }; |
1629 | |
1630 AVCodec sp5x_decoder = { | |
1631 "sp5x", | |
1632 CODEC_TYPE_VIDEO, | |
1633 CODEC_ID_SP5X, | |
1634 sizeof(MJpegDecodeContext), | |
1635 ff_mjpeg_decode_init, | |
1636 NULL, | |
1637 ff_mjpeg_decode_end, | |
1638 sp5x_decode_frame, | |
1639 CODEC_CAP_DR1, | |
1640 NULL | |
1641 }; |