Mercurial > libavcodec.hg
annotate sunrast.c @ 11124:85a1b00a2413 libavcodec
Use int8_t instead of char, the signedness of char can differ between systems.
| author | reimar |
|---|---|
| date | Fri, 12 Feb 2010 18:18:35 +0000 |
| parents | 028a4deb56d3 |
| children | 8a4984c5cacc |
| rev | line source |
|---|---|
| 6084 | 1 /* |
| 2 * Sun Rasterfile (.sun/.ras/im{1,8,24}/.sunras) image decoder | |
| 3 * Copyright (c) 2007, 2008 Ivo van Poorten | |
| 4 * | |
| 5 * This file is part of FFmpeg. | |
| 6 * | |
| 7 * FFmpeg is free software; you can redistribute it and/or | |
| 8 * modify it under the terms of the GNU Lesser General Public | |
| 9 * License as published by the Free Software Foundation; either | |
| 10 * version 2.1 of the License, or (at your option) any later version. | |
| 11 * | |
| 12 * FFmpeg is distributed in the hope that it will be useful, | |
| 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 15 * Lesser General Public License for more details. | |
| 16 * | |
| 17 * You should have received a copy of the GNU Lesser General Public | |
| 18 * License along with FFmpeg; if not, write to the Free Software | |
| 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
| 20 */ | |
| 21 | |
|
8573
2acf0ae7b041
Fix build: Add intreadwrite.h and bswap.h #includes where necessary.
diego
parents:
7040
diff
changeset
|
22 #include "libavutil/intreadwrite.h" |
| 6084 | 23 #include "avcodec.h" |
| 24 | |
| 25 #define RT_OLD 0 | |
| 26 #define RT_STANDARD 1 | |
| 27 #define RT_BYTE_ENCODED 2 | |
| 28 #define RT_FORMAT_RGB 3 | |
| 29 #define RT_FORMAT_TIFF 4 | |
| 30 #define RT_FORMAT_IFF 5 | |
| 31 | |
| 32 typedef struct SUNRASTContext { | |
| 33 AVFrame picture; | |
| 34 } SUNRASTContext; | |
| 35 | |
|
6517
48759bfbd073
Apply 'cold' attribute to init/uninit functions in libavcodec
zuxy
parents:
6254
diff
changeset
|
36 static av_cold int sunrast_init(AVCodecContext *avctx) { |
| 6084 | 37 SUNRASTContext *s = avctx->priv_data; |
| 38 | |
| 39 avcodec_get_frame_defaults(&s->picture); | |
| 40 avctx->coded_frame= &s->picture; | |
| 41 | |
| 42 return 0; | |
| 43 } | |
| 44 | |
| 45 static int sunrast_decode_frame(AVCodecContext *avctx, void *data, | |
|
9355
54bc8a2727b0
Implement avcodec_decode_video2(), _audio3() and _subtitle2() which takes an
rbultje
parents:
8573
diff
changeset
|
46 int *data_size, AVPacket *avpkt) { |
|
54bc8a2727b0
Implement avcodec_decode_video2(), _audio3() and _subtitle2() which takes an
rbultje
parents:
8573
diff
changeset
|
47 const uint8_t *buf = avpkt->data; |
| 6084 | 48 SUNRASTContext * const s = avctx->priv_data; |
| 49 AVFrame *picture = data; | |
| 50 AVFrame * const p = &s->picture; | |
| 51 unsigned int w, h, depth, type, maptype, maplength, stride, x, y, len, alen; | |
| 6254 | 52 uint8_t *ptr; |
| 53 const uint8_t *bufstart = buf; | |
| 6084 | 54 |
| 55 if (AV_RB32(buf) != 0x59a66a95) { | |
| 56 av_log(avctx, AV_LOG_ERROR, "this is not sunras encoded data\n"); | |
| 57 return -1; | |
| 58 } | |
| 59 | |
| 60 w = AV_RB32(buf+4); | |
| 61 h = AV_RB32(buf+8); | |
| 62 depth = AV_RB32(buf+12); | |
| 63 type = AV_RB32(buf+20); | |
| 64 maptype = AV_RB32(buf+24); | |
| 65 maplength = AV_RB32(buf+28); | |
| 66 | |
| 10358 | 67 if (type == RT_FORMAT_TIFF || type == RT_FORMAT_IFF) { |
| 6084 | 68 av_log(avctx, AV_LOG_ERROR, "unsupported (compression) type\n"); |
| 69 return -1; | |
| 70 } | |
| 71 if (type > RT_FORMAT_IFF) { | |
| 72 av_log(avctx, AV_LOG_ERROR, "invalid (compression) type\n"); | |
| 73 return -1; | |
| 74 } | |
| 75 if (maptype & ~1) { | |
| 76 av_log(avctx, AV_LOG_ERROR, "invalid colormap type\n"); | |
| 77 return -1; | |
| 78 } | |
| 79 | |
| 80 buf += 32; | |
| 81 | |
| 82 switch (depth) { | |
| 83 case 1: | |
| 84 avctx->pix_fmt = PIX_FMT_MONOWHITE; | |
| 85 break; | |
| 86 case 8: | |
| 87 avctx->pix_fmt = PIX_FMT_PAL8; | |
| 88 break; | |
| 89 case 24: | |
| 10358 | 90 avctx->pix_fmt = (type == RT_FORMAT_RGB) ? PIX_FMT_RGB24 : PIX_FMT_BGR24; |
| 6084 | 91 break; |
| 92 default: | |
| 93 av_log(avctx, AV_LOG_ERROR, "invalid depth\n"); | |
| 94 return -1; | |
| 95 } | |
| 96 | |
| 97 if (p->data[0]) | |
| 98 avctx->release_buffer(avctx, p); | |
| 99 | |
| 100 if (avcodec_check_dimensions(avctx, w, h)) | |
| 101 return -1; | |
| 102 if (w != avctx->width || h != avctx->height) | |
| 103 avcodec_set_dimensions(avctx, w, h); | |
| 104 if (avctx->get_buffer(avctx, p) < 0) { | |
| 105 av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); | |
| 106 return -1; | |
| 107 } | |
| 108 | |
| 109 p->pict_type = FF_I_TYPE; | |
| 110 | |
| 111 if (depth != 8 && maplength) { | |
| 112 av_log(avctx, AV_LOG_WARNING, "useless colormap found or file is corrupted, trying to recover\n"); | |
| 113 | |
| 114 } else if (depth == 8) { | |
| 115 unsigned int len = maplength / 3; | |
| 116 | |
| 117 if (!maplength) { | |
| 118 av_log(avctx, AV_LOG_ERROR, "colormap expected\n"); | |
| 119 return -1; | |
| 120 } | |
| 121 if (maplength % 3 || maplength > 768) { | |
| 122 av_log(avctx, AV_LOG_WARNING, "invalid colormap length\n"); | |
| 123 return -1; | |
| 124 } | |
| 125 | |
| 126 ptr = p->data[1]; | |
| 127 for (x=0; x<len; x++, ptr+=4) | |
| 128 *(uint32_t *)ptr = (buf[x]<<16) + (buf[len+x]<<8) + buf[len+len+x]; | |
| 129 } | |
| 130 | |
| 131 buf += maplength; | |
| 132 | |
| 133 ptr = p->data[0]; | |
| 134 stride = p->linesize[0]; | |
| 135 | |
| 136 /* scanlines are aligned on 16 bit boundaries */ | |
| 137 len = (depth * w + 7) >> 3; | |
| 138 alen = len + (len&1); | |
| 139 | |
| 140 if (type == RT_BYTE_ENCODED) { | |
| 141 int value, run; | |
| 142 uint8_t *end = ptr + h*stride; | |
| 143 | |
| 144 x = 0; | |
| 145 while (ptr != end) { | |
| 146 run = 1; | |
| 147 if ((value = *buf++) == 0x80) { | |
| 148 run = *buf++ + 1; | |
| 149 if (run != 1) | |
| 150 value = *buf++; | |
| 151 } | |
| 152 while (run--) { | |
| 153 if (x < len) | |
| 154 ptr[x] = value; | |
| 155 if (++x >= alen) { | |
| 156 x = 0; | |
| 157 ptr += stride; | |
| 158 if (ptr == end) | |
| 159 break; | |
| 160 } | |
| 161 } | |
| 162 } | |
| 163 } else { | |
| 164 for (y=0; y<h; y++) { | |
| 165 memcpy(ptr, buf, len); | |
| 166 ptr += stride; | |
| 167 buf += alen; | |
| 168 } | |
| 169 } | |
| 170 | |
| 171 *picture = s->picture; | |
| 172 *data_size = sizeof(AVFrame); | |
| 173 | |
| 174 return buf - bufstart; | |
| 175 } | |
| 176 | |
|
6517
48759bfbd073
Apply 'cold' attribute to init/uninit functions in libavcodec
zuxy
parents:
6254
diff
changeset
|
177 static av_cold int sunrast_end(AVCodecContext *avctx) { |
| 6084 | 178 SUNRASTContext *s = avctx->priv_data; |
| 179 | |
| 180 if(s->picture.data[0]) | |
| 181 avctx->release_buffer(avctx, &s->picture); | |
| 182 | |
| 183 return 0; | |
| 184 } | |
| 185 | |
| 186 AVCodec sunrast_decoder = { | |
| 187 "sunrast", | |
| 188 CODEC_TYPE_VIDEO, | |
| 189 CODEC_ID_SUNRAST, | |
| 190 sizeof(SUNRASTContext), | |
| 191 sunrast_init, | |
| 192 NULL, | |
| 193 sunrast_end, | |
| 194 sunrast_decode_frame, | |
|
9809
6a3f4053d935
sun rasterfile image decoder uses get_buffer, set CODEC_CAP_DR1
bcoudurier
parents:
9385
diff
changeset
|
195 CODEC_CAP_DR1, |
| 6722 | 196 NULL, |
|
7040
e943e1409077
Make AVCodec long_names definition conditional depending on CONFIG_SMALL.
stefano
parents:
6722
diff
changeset
|
197 .long_name = NULL_IF_CONFIG_SMALL("Sun Rasterfile image"), |
| 6084 | 198 }; |
