Mercurial > libavcodec.hg
annotate ptx.c @ 6517:48759bfbd073 libavcodec
Apply 'cold' attribute to init/uninit functions in libavcodec
| author | zuxy |
|---|---|
| date | Fri, 21 Mar 2008 03:11:20 +0000 |
| parents | ce0378d4c06c |
| children | 6eeb19edcee3 |
| rev | line source |
|---|---|
| 4884 | 1 /* |
| 2 * V.Flash PTX (.ptx) image decoder | |
| 3 * Copyright (c) 2007 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 | |
| 22 #include "avcodec.h" | |
| 23 | |
| 24 typedef struct PTXContext { | |
| 25 AVFrame picture; | |
| 26 } PTXContext; | |
| 27 | |
|
6517
48759bfbd073
Apply 'cold' attribute to init/uninit functions in libavcodec
zuxy
parents:
6246
diff
changeset
|
28 static av_cold int ptx_init(AVCodecContext *avctx) { |
| 4884 | 29 PTXContext *s = avctx->priv_data; |
| 30 | |
| 6070 | 31 avcodec_get_frame_defaults(&s->picture); |
| 32 avctx->coded_frame= &s->picture; | |
| 4884 | 33 |
| 34 return 0; | |
| 35 } | |
| 36 | |
| 37 static int ptx_decode_frame(AVCodecContext *avctx, void *data, int *data_size, | |
| 6246 | 38 const uint8_t *buf, int buf_size) { |
| 4884 | 39 PTXContext * const s = avctx->priv_data; |
| 40 AVFrame *picture = data; | |
| 6075 | 41 AVFrame * const p = &s->picture; |
| 4884 | 42 unsigned int offset, w, h, y, stride, bytes_per_pixel; |
| 43 uint8_t *ptr; | |
| 44 | |
| 45 offset = AV_RL16(buf); | |
| 46 w = AV_RL16(buf+8); | |
| 47 h = AV_RL16(buf+10); | |
| 48 bytes_per_pixel = AV_RL16(buf+12) >> 3; | |
| 49 | |
| 50 if (bytes_per_pixel != 2) { | |
| 51 av_log(avctx, AV_LOG_ERROR, "image format is not rgb15, please report on ffmpeg-users mailing list\n"); | |
| 52 return -1; | |
| 53 } | |
| 54 | |
| 55 avctx->pix_fmt = PIX_FMT_RGB555; | |
| 56 | |
| 57 if (offset != 0x2c) | |
| 58 av_log(avctx, AV_LOG_WARNING, "offset != 0x2c, untested due to lack of sample files\n"); | |
| 59 | |
| 60 buf += offset; | |
| 61 | |
| 62 if (p->data[0]) | |
| 63 avctx->release_buffer(avctx, p); | |
| 64 | |
| 65 if (avcodec_check_dimensions(avctx, w, h)) | |
| 66 return -1; | |
| 67 if (w != avctx->width || h != avctx->height) | |
| 68 avcodec_set_dimensions(avctx, w, h); | |
| 69 if (avctx->get_buffer(avctx, p) < 0) { | |
| 70 av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); | |
| 71 return -1; | |
| 72 } | |
| 73 | |
| 74 p->pict_type = FF_I_TYPE; | |
| 75 | |
| 76 ptr = p->data[0]; | |
| 77 stride = p->linesize[0]; | |
| 78 | |
| 79 for (y=0; y<h; y++) { | |
| 80 #ifdef WORDS_BIGENDIAN | |
| 81 unsigned int x; | |
| 82 for (x=0; x<w*bytes_per_pixel; x+=bytes_per_pixel) | |
|
5520
c16a59ef6a86
* renaming (ST|LD)(16|32|64) -> AV_(R|W)N(16|32|64)
romansh
parents:
5215
diff
changeset
|
83 AV_WN16(ptr+x, AV_RL16(buf+x)); |
| 4884 | 84 #else |
| 85 memcpy(ptr, buf, w*bytes_per_pixel); | |
| 86 #endif | |
| 87 ptr += stride; | |
| 88 buf += w*bytes_per_pixel; | |
| 89 } | |
| 90 | |
| 6070 | 91 *picture = s->picture; |
| 4884 | 92 *data_size = sizeof(AVPicture); |
| 93 | |
| 94 return offset + w*h*bytes_per_pixel; | |
| 95 } | |
| 96 | |
|
6517
48759bfbd073
Apply 'cold' attribute to init/uninit functions in libavcodec
zuxy
parents:
6246
diff
changeset
|
97 static av_cold int ptx_end(AVCodecContext *avctx) { |
| 4884 | 98 PTXContext *s = avctx->priv_data; |
| 99 | |
| 100 if(s->picture.data[0]) | |
| 101 avctx->release_buffer(avctx, &s->picture); | |
| 102 | |
| 103 return 0; | |
| 104 } | |
| 105 | |
| 106 AVCodec ptx_decoder = { | |
| 107 "ptx", | |
| 108 CODEC_TYPE_VIDEO, | |
| 109 CODEC_ID_PTX, | |
| 110 sizeof(PTXContext), | |
| 111 ptx_init, | |
| 112 NULL, | |
| 113 ptx_end, | |
| 114 ptx_decode_frame, | |
| 115 0, | |
| 116 NULL | |
| 117 }; |
