Commit cc7d5cfe authored by Diego Biurrun's avatar Diego Biurrun

img2: K&R formatting cosmetics

Also introduce local img_ namespace to simplify debugging.
parent c1fcf563
...@@ -29,50 +29,51 @@ typedef struct { ...@@ -29,50 +29,51 @@ typedef struct {
} IdStrMap; } IdStrMap;
static const IdStrMap img_tags[] = { static const IdStrMap img_tags[] = {
{ AV_CODEC_ID_MJPEG , "jpeg"}, { AV_CODEC_ID_MJPEG, "jpeg" },
{ AV_CODEC_ID_MJPEG , "jpg"}, { AV_CODEC_ID_MJPEG, "jpg" },
{ AV_CODEC_ID_LJPEG , "ljpg"}, { AV_CODEC_ID_LJPEG, "ljpg" },
{ AV_CODEC_ID_PNG , "png"}, { AV_CODEC_ID_PNG, "png" },
{ AV_CODEC_ID_PNG , "mng"}, { AV_CODEC_ID_PNG, "mng" },
{ AV_CODEC_ID_PPM , "ppm"}, { AV_CODEC_ID_PPM, "ppm" },
{ AV_CODEC_ID_PPM , "pnm"}, { AV_CODEC_ID_PPM, "pnm" },
{ AV_CODEC_ID_PGM , "pgm"}, { AV_CODEC_ID_PGM, "pgm" },
{ AV_CODEC_ID_PGMYUV , "pgmyuv"}, { AV_CODEC_ID_PGMYUV, "pgmyuv" },
{ AV_CODEC_ID_PBM , "pbm"}, { AV_CODEC_ID_PBM, "pbm" },
{ AV_CODEC_ID_PAM , "pam"}, { AV_CODEC_ID_PAM, "pam" },
{ AV_CODEC_ID_MPEG1VIDEO, "mpg1-img"}, { AV_CODEC_ID_MPEG1VIDEO, "mpg1-img" },
{ AV_CODEC_ID_MPEG2VIDEO, "mpg2-img"}, { AV_CODEC_ID_MPEG2VIDEO, "mpg2-img" },
{ AV_CODEC_ID_MPEG4 , "mpg4-img"}, { AV_CODEC_ID_MPEG4, "mpg4-img" },
{ AV_CODEC_ID_FFV1 , "ffv1-img"}, { AV_CODEC_ID_FFV1, "ffv1-img" },
{ AV_CODEC_ID_RAWVIDEO , "y"}, { AV_CODEC_ID_RAWVIDEO, "y" },
{ AV_CODEC_ID_BMP , "bmp"}, { AV_CODEC_ID_BMP, "bmp" },
{ AV_CODEC_ID_GIF , "gif"}, { AV_CODEC_ID_GIF, "gif" },
{ AV_CODEC_ID_TARGA , "tga"}, { AV_CODEC_ID_TARGA, "tga" },
{ AV_CODEC_ID_TIFF , "tiff"}, { AV_CODEC_ID_TIFF, "tiff" },
{ AV_CODEC_ID_TIFF , "tif"}, { AV_CODEC_ID_TIFF, "tif" },
{ AV_CODEC_ID_SGI , "sgi"}, { AV_CODEC_ID_SGI, "sgi" },
{ AV_CODEC_ID_PTX , "ptx"}, { AV_CODEC_ID_PTX, "ptx" },
{ AV_CODEC_ID_PCX , "pcx"}, { AV_CODEC_ID_PCX, "pcx" },
{ AV_CODEC_ID_SUNRAST , "sun"}, { AV_CODEC_ID_SUNRAST, "sun" },
{ AV_CODEC_ID_SUNRAST , "ras"}, { AV_CODEC_ID_SUNRAST, "ras" },
{ AV_CODEC_ID_SUNRAST , "rs"}, { AV_CODEC_ID_SUNRAST, "rs" },
{ AV_CODEC_ID_SUNRAST , "im1"}, { AV_CODEC_ID_SUNRAST, "im1" },
{ AV_CODEC_ID_SUNRAST , "im8"}, { AV_CODEC_ID_SUNRAST, "im8" },
{ AV_CODEC_ID_SUNRAST , "im24"}, { AV_CODEC_ID_SUNRAST, "im24" },
{ AV_CODEC_ID_SUNRAST , "sunras"}, { AV_CODEC_ID_SUNRAST, "sunras" },
{ AV_CODEC_ID_JPEG2000 , "jp2"}, { AV_CODEC_ID_JPEG2000, "jp2" },
{ AV_CODEC_ID_JPEG2000 , "jpc"}, { AV_CODEC_ID_JPEG2000, "jpc" },
{ AV_CODEC_ID_DPX , "dpx"}, { AV_CODEC_ID_DPX, "dpx" },
{ AV_CODEC_ID_PICTOR , "pic"}, { AV_CODEC_ID_PICTOR, "pic" },
{ AV_CODEC_ID_XBM , "xbm"}, { AV_CODEC_ID_XBM, "xbm" },
{ AV_CODEC_ID_XWD , "xwd"}, { AV_CODEC_ID_XWD, "xwd" },
{ AV_CODEC_ID_NONE , NULL} { AV_CODEC_ID_NONE, NULL }
}; };
static enum AVCodecID av_str2id(const IdStrMap *tags, const char *str) static enum AVCodecID av_str2id(const IdStrMap *tags, const char *str)
{ {
str= strrchr(str, '.'); str = strrchr(str, '.');
if(!str) return AV_CODEC_ID_NONE; if (!str)
return AV_CODEC_ID_NONE;
str++; str++;
while (tags->id) { while (tags->id) {
......
This diff is collapsed.
...@@ -55,45 +55,46 @@ static int write_packet(AVFormatContext *s, AVPacket *pkt) ...@@ -55,45 +55,46 @@ static int write_packet(AVFormatContext *s, AVPacket *pkt)
VideoMuxData *img = s->priv_data; VideoMuxData *img = s->priv_data;
AVIOContext *pb[3]; AVIOContext *pb[3];
char filename[1024]; char filename[1024];
AVCodecContext *codec= s->streams[ pkt->stream_index ]->codec; AVCodecContext *codec = s->streams[pkt->stream_index]->codec;
int i; int i;
if (!img->is_pipe) { if (!img->is_pipe) {
if (av_get_frame_filename(filename, sizeof(filename), if (av_get_frame_filename(filename, sizeof(filename),
img->path, img->img_number) < 0 && img->img_number>1) { img->path, img->img_number) < 0 && img->img_number > 1) {
av_log(s, AV_LOG_ERROR, av_log(s, AV_LOG_ERROR,
"Could not get frame filename number %d from pattern '%s'\n", "Could not get frame filename number %d from pattern '%s'\n",
img->img_number, img->path); img->img_number, img->path);
return AVERROR(EIO); return AVERROR(EIO);
} }
for(i=0; i<3; i++){ for (i = 0; i < 3; i++) {
if (avio_open2(&pb[i], filename, AVIO_FLAG_WRITE, if (avio_open2(&pb[i], filename, AVIO_FLAG_WRITE,
&s->interrupt_callback, NULL) < 0) { &s->interrupt_callback, NULL) < 0) {
av_log(s, AV_LOG_ERROR, "Could not open file : %s\n",filename); av_log(s, AV_LOG_ERROR, "Could not open file : %s\n", filename);
return AVERROR(EIO); return AVERROR(EIO);
} }
if(codec->codec_id != AV_CODEC_ID_RAWVIDEO) if (codec->codec_id != AV_CODEC_ID_RAWVIDEO)
break; break;
filename[ strlen(filename) - 1 ]= 'U' + i; filename[strlen(filename) - 1] = 'U' + i;
} }
} else { } else {
pb[0] = s->pb; pb[0] = s->pb;
} }
if(codec->codec_id == AV_CODEC_ID_RAWVIDEO){ if (codec->codec_id == AV_CODEC_ID_RAWVIDEO) {
int ysize = codec->width * codec->height; int ysize = codec->width * codec->height;
avio_write(pb[0], pkt->data , ysize); avio_write(pb[0], pkt->data, ysize);
avio_write(pb[1], pkt->data + ysize, (pkt->size - ysize)/2); avio_write(pb[1], pkt->data + ysize, (pkt->size - ysize) / 2);
avio_write(pb[2], pkt->data + ysize +(pkt->size - ysize)/2, (pkt->size - ysize)/2); avio_write(pb[2], pkt->data + ysize + (pkt->size - ysize) / 2, (pkt->size - ysize) / 2);
avio_close(pb[1]); avio_close(pb[1]);
avio_close(pb[2]); avio_close(pb[2]);
}else{ } else {
if(ff_guess_image2_codec(s->filename) == AV_CODEC_ID_JPEG2000){ if (ff_guess_image2_codec(s->filename) == AV_CODEC_ID_JPEG2000) {
AVStream *st = s->streams[0]; AVStream *st = s->streams[0];
if(st->codec->extradata_size > 8 && if (st->codec->extradata_size > 8 &&
AV_RL32(st->codec->extradata+4) == MKTAG('j','p','2','h')){ AV_RL32(st->codec->extradata + 4) == MKTAG('j', 'p', '2', 'h')) {
if(pkt->size < 8 || AV_RL32(pkt->data+4) != MKTAG('j','p','2','c')) if (pkt->size < 8 ||
AV_RL32(pkt->data + 4) != MKTAG('j', 'p', '2', 'c'))
goto error; goto error;
avio_wb32(pb[0], 12); avio_wb32(pb[0], 12);
ffio_wfourcc(pb[0], "jP "); ffio_wfourcc(pb[0], "jP ");
...@@ -104,10 +105,10 @@ static int write_packet(AVFormatContext *s, AVPacket *pkt) ...@@ -104,10 +105,10 @@ static int write_packet(AVFormatContext *s, AVPacket *pkt)
avio_wb32(pb[0], 0); avio_wb32(pb[0], 0);
ffio_wfourcc(pb[0], "jp2 "); ffio_wfourcc(pb[0], "jp2 ");
avio_write(pb[0], st->codec->extradata, st->codec->extradata_size); avio_write(pb[0], st->codec->extradata, st->codec->extradata_size);
}else if(pkt->size < 8 || } else if (pkt->size < 8 ||
(!st->codec->extradata_size && (!st->codec->extradata_size &&
AV_RL32(pkt->data+4) != MKTAG('j','P',' ',' '))){ // signature AV_RL32(pkt->data + 4) != MKTAG('j', 'P', ' ', ' '))) { // signature
error: error:
av_log(s, AV_LOG_ERROR, "malformed JPEG 2000 codestream\n"); av_log(s, AV_LOG_ERROR, "malformed JPEG 2000 codestream\n");
return -1; return -1;
} }
...@@ -126,7 +127,7 @@ static int write_packet(AVFormatContext *s, AVPacket *pkt) ...@@ -126,7 +127,7 @@ static int write_packet(AVFormatContext *s, AVPacket *pkt)
#define OFFSET(x) offsetof(VideoMuxData, x) #define OFFSET(x) offsetof(VideoMuxData, x)
#define ENC AV_OPT_FLAG_ENCODING_PARAM #define ENC AV_OPT_FLAG_ENCODING_PARAM
static const AVOption muxoptions[] = { static const AVOption muxoptions[] = {
{ "start_number", "first number in the sequence", OFFSET(img_number), AV_OPT_TYPE_INT, {.i64 = 1}, 1, INT_MAX, ENC }, { "start_number", "first number in the sequence", OFFSET(img_number), AV_OPT_TYPE_INT, { .i64 = 1 }, 1, INT_MAX, ENC },
{ NULL }, { NULL },
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment