diff options
Diffstat (limited to 'libavcodec/pamenc.c')
-rw-r--r-- | libavcodec/pamenc.c | 87 |
1 files changed, 54 insertions, 33 deletions
diff --git a/libavcodec/pamenc.c b/libavcodec/pamenc.c index 2b63af9..50c9fcb 100644 --- a/libavcodec/pamenc.c +++ b/libavcodec/pamenc.c @@ -2,54 +2,39 @@ * PAM image format * Copyright (c) 2002, 2003 Fabrice Bellard * - * This file is part of Libav. + * This file is part of FFmpeg. * - * Libav is free software; you can redistribute it and/or + * FFmpeg is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * - * Libav is distributed in the hope that it will be useful, + * FFmpeg is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public - * License along with Libav; if not, write to the Free Software + * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include "libavutil/imgutils.h" - #include "avcodec.h" -#include "bytestream.h" #include "internal.h" static int pam_encode_frame(AVCodecContext *avctx, AVPacket *pkt, - const AVFrame *pict, int *got_packet) + const AVFrame *p, int *got_packet) { uint8_t *bytestream_start, *bytestream, *bytestream_end; - const AVFrame * const p = pict; int i, h, w, n, linesize, depth, maxval, ret; const char *tuple_type; uint8_t *ptr; - int size = av_image_get_buffer_size(avctx->pix_fmt, - avctx->width, avctx->height, 1); - - if ((ret = ff_alloc_packet(pkt, size + 200)) < 0) { - av_log(avctx, AV_LOG_ERROR, "encoded frame too large\n"); - return ret; - } - - bytestream_start = - bytestream = pkt->data; - bytestream_end = pkt->data + pkt->size; h = avctx->height; w = avctx->width; switch (avctx->pix_fmt) { - case AV_PIX_FMT_MONOWHITE: - n = (w + 7) >> 3; + case AV_PIX_FMT_MONOBLACK: + n = w; depth = 1; maxval = 1; tuple_type = "BLACKANDWHITE"; @@ -60,21 +45,59 @@ static int pam_encode_frame(AVCodecContext *avctx, AVPacket *pkt, maxval = 255; tuple_type = "GRAYSCALE"; break; + case AV_PIX_FMT_GRAY16BE: + n = w * 2; + depth = 1; + maxval = 0xFFFF; + tuple_type = "GRAYSCALE"; + break; + case AV_PIX_FMT_GRAY8A: + n = w * 2; + depth = 2; + maxval = 255; + tuple_type = "GRAYSCALE_ALPHA"; + break; + case AV_PIX_FMT_YA16BE: + n = w * 4; + depth = 2; + maxval = 0xFFFF; + tuple_type = "GRAYSCALE_ALPHA"; + break; case AV_PIX_FMT_RGB24: n = w * 3; depth = 3; maxval = 255; tuple_type = "RGB"; break; - case AV_PIX_FMT_RGB32: + case AV_PIX_FMT_RGBA: n = w * 4; depth = 4; maxval = 255; tuple_type = "RGB_ALPHA"; break; + case AV_PIX_FMT_RGB48BE: + n = w * 6; + depth = 3; + maxval = 0xFFFF; + tuple_type = "RGB"; + break; + case AV_PIX_FMT_RGBA64BE: + n = w * 8; + depth = 4; + maxval = 0xFFFF; + tuple_type = "RGB_ALPHA"; + break; default: return -1; } + + if ((ret = ff_alloc_packet2(avctx, pkt, n*h + 200, 0)) < 0) + return ret; + + bytestream_start = + bytestream = pkt->data; + bytestream_end = pkt->data + pkt->size; + snprintf(bytestream, bytestream_end - bytestream, "P7\nWIDTH %d\nHEIGHT %d\nDEPTH %d\nMAXVAL %d\nTUPLTYPE %s\nENDHDR\n", w, h, depth, maxval, tuple_type); @@ -83,16 +106,11 @@ static int pam_encode_frame(AVCodecContext *avctx, AVPacket *pkt, ptr = p->data[0]; linesize = p->linesize[0]; - if (avctx->pix_fmt == AV_PIX_FMT_RGB32) { + if (avctx->pix_fmt == AV_PIX_FMT_MONOBLACK){ int j; - unsigned int v; - for (i = 0; i < h; i++) { - for (j = 0; j < w; j++) { - v = ((uint32_t *)ptr)[j]; - bytestream_put_be24(&bytestream, v); - *bytestream++ = v >> 24; - } + for (j = 0; j < w; j++) + *bytestream++ = ptr[j >> 3] >> (7 - j & 7) & 1; ptr += linesize; } } else { @@ -129,7 +147,10 @@ AVCodec ff_pam_encoder = { .init = pam_encode_init, .encode2 = pam_encode_frame, .pix_fmts = (const enum AVPixelFormat[]){ - AV_PIX_FMT_RGB24, AV_PIX_FMT_RGB32, AV_PIX_FMT_GRAY8, AV_PIX_FMT_MONOWHITE, - AV_PIX_FMT_NONE + AV_PIX_FMT_RGB24, AV_PIX_FMT_RGBA, + AV_PIX_FMT_RGB48BE, AV_PIX_FMT_RGBA64BE, + AV_PIX_FMT_GRAY8, AV_PIX_FMT_GRAY8A, + AV_PIX_FMT_GRAY16BE, AV_PIX_FMT_YA16BE, + AV_PIX_FMT_MONOBLACK, AV_PIX_FMT_NONE }, }; |