From: Kirill Gavrilov <kir...@sview.ru> Use optional sTER chunk defining side-by-side stereo pair within "Extensions to the PNG 1.2 Specification", version 1.3.0.
Signed-off-by: Vittorio Giovara <vittorio.giov...@gmail.com> --- Minor nits, applies to libav, simiplifies reading/setting the mode. Vittorio libavcodec/pngdec.c | 18 ++++++++++++++++++ libavcodec/pngenc.c | 22 ++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/libavcodec/pngdec.c b/libavcodec/pngdec.c index 5fa7a2d..b52bf60 100644 --- a/libavcodec/pngdec.c +++ b/libavcodec/pngdec.c @@ -21,6 +21,8 @@ #include "libavutil/avstring.h" #include "libavutil/imgutils.h" +#include "libavutil/stereo3d.h" + #include "avcodec.h" #include "bytestream.h" #include "internal.h" @@ -608,6 +610,22 @@ static int decode_frame(AVCodecContext *avctx, bytestream2_skip(&s->gb, 4); /* crc */ } break; + case MKTAG('s', 'T', 'E', 'R'): { + int mode = bytestream2_get_byte(&s->gb); + AVStereo3D *stereo3d = av_stereo3d_create_side_data(p); + if (!stereo3d) + goto the_end; + + if (mode == 0 || mode == 1) { + stereo3d->type = AV_STEREO3D_SIDEBYSIDE; + stereo3d->flags = mode ? 0 : AV_STEREO3D_FLAG_INVERT; + } else { + av_log(avctx, AV_LOG_WARNING, + "Unknown value in sTER chunk (%d)\n", mode); + } + bytestream2_skip(&s->gb, 4); /* crc */ + break; + } case MKTAG('I', 'E', 'N', 'D'): if (!(s->state & PNG_ALLIMAGE)) goto fail; diff --git a/libavcodec/pngenc.c b/libavcodec/pngenc.c index 6ab4b7f..96146ac 100644 --- a/libavcodec/pngenc.c +++ b/libavcodec/pngenc.c @@ -19,6 +19,8 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#include "libavutil/stereo3d.h" + #include "avcodec.h" #include "bytestream.h" #include "huffyuvencdsp.h" @@ -233,6 +235,7 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *pict, int *got_packet) { PNGEncContext *s = avctx->priv_data; + AVFrameSideData *side_data; const AVFrame *const p = pict; int bit_depth, color_type, y, len, row_size, ret, is_progressive; int bits_per_pixel, pass_row_size, enc_row_size, max_packet_size; @@ -416,6 +419,25 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, top = ptr; } } + + /* write stereoscopic information */ + side_data = av_frame_get_side_data(pict, AV_FRAME_DATA_STEREO3D); + if (side_data) { + AVStereo3D *stereo3d = (AVStereo3D *)side_data->data; + switch (stereo3d->type) { + case AV_STEREO3D_SIDEBYSIDE: + s->buf[0] = !(stereo3d->flags & AV_STEREO3D_FLAG_INVERT); + png_write_chunk(&s->bytestream, MKTAG('s', 'T', 'E', 'R'), s->buf, 1); + break; + case AV_STEREO3D_2D: + break; + default: + av_log(avctx, AV_LOG_WARNING, + "Only side-by-side stereo3d flag can be defined within sTER chunk\n"); + break; + } + } + /* compress last bytes */ for (;;) { ret = deflate(&s->zstream, Z_FINISH); -- 1.9.5 (Apple Git-50.3) _______________________________________________ libav-devel mailing list libav-devel@libav.org https://lists.libav.org/mailman/listinfo/libav-devel