FFmpeg  4.3
sgirledec.c
Go to the documentation of this file.
1 /*
2  * Silicon Graphics RLE 8-bit video decoder
3  * Copyright (c) 2012 Peter Ross
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 /**
23  * @file
24  * Silicon Graphics RLE 8-bit video decoder
25  * @note Data is packed in rbg323 with rle, contained in mv or mov.
26  * The algorithm and pixfmt are subtly different from SGI images.
27  */
28 
29 #include "libavutil/common.h"
30 
31 #include "avcodec.h"
32 #include "internal.h"
33 
35 {
36  avctx->pix_fmt = AV_PIX_FMT_BGR8;
37  return 0;
38 }
39 
40 /**
41  * Convert SGI RBG323 pixel into AV_PIX_FMT_BGR8
42  * SGI RGB data is packed as 8bpp, (msb)3R 2B 3G(lsb)
43  */
44 #define RBG323_TO_BGR8(x) ((((x) << 3) & 0xC0) | \
45  (((x) << 3) & 0x38) | \
46  (((x) >> 5) & 7))
47 static av_always_inline
48 void rbg323_to_bgr8(uint8_t *dst, const uint8_t *src, int size)
49 {
50  int i;
51  for (i = 0; i < size; i++)
52  dst[i] = RBG323_TO_BGR8(src[i]);
53 }
54 
55 /**
56  * @param[out] dst Destination buffer
57  * @param[in] src Source buffer
58  * @param src_size Source buffer size (bytes)
59  * @param width Width of destination buffer (pixels)
60  * @param height Height of destination buffer (pixels)
61  * @param linesize Line size of destination buffer (bytes)
62  *
63  * @return <0 on error
64  */
65 static int decode_sgirle8(AVCodecContext *avctx, uint8_t *dst,
66  const uint8_t *src, int src_size,
67  int width, int height, ptrdiff_t linesize)
68 {
69  const uint8_t *src_end = src + src_size;
70  int x = 0, y = 0;
71 
72 #define INC_XY(n) \
73  x += n; \
74  if (x >= width) { \
75  y++; \
76  if (y >= height) \
77  return 0; \
78  x = 0; \
79  }
80 
81  while (src_end - src >= 2) {
82  uint8_t v = *src++;
83  if (v > 0 && v < 0xC0) {
84  do {
85  int length = FFMIN(v, width - x);
86  if (length <= 0)
87  break;
88  memset(dst + y * linesize + x, RBG323_TO_BGR8(*src), length);
89  INC_XY(length);
90  v -= length;
91  } while (v > 0);
92  src++;
93  } else if (v >= 0xC1) {
94  v -= 0xC0;
95  do {
96  int length = FFMIN3(v, width - x, src_end - src);
97  if (src_end - src < length || length <= 0)
98  break;
99  rbg323_to_bgr8(dst + y * linesize + x, src, length);
100  INC_XY(length);
101  src += length;
102  v -= length;
103  } while (v > 0);
104  } else {
105  avpriv_request_sample(avctx, "opcode %d", v);
106  return AVERROR_PATCHWELCOME;
107  }
108  }
109  return 0;
110 }
111 
112 static int sgirle_decode_frame(AVCodecContext *avctx, void *data,
113  int *got_frame, AVPacket *avpkt)
114 {
115  AVFrame *frame = data;
116  int ret;
117 
118  if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
119  return ret;
120 
121  ret = decode_sgirle8(avctx, frame->data[0], avpkt->data, avpkt->size,
122  avctx->width, avctx->height, frame->linesize[0]);
123  if (ret < 0)
124  return ret;
125 
126  frame->pict_type = AV_PICTURE_TYPE_I;
127  frame->key_frame = 1;
128 
129  *got_frame = 1;
130 
131  return avpkt->size;
132 }
133 
135  .name = "sgirle",
136  .long_name = NULL_IF_CONFIG_SMALL("Silicon Graphics RLE 8-bit video"),
137  .type = AVMEDIA_TYPE_VIDEO,
138  .id = AV_CODEC_ID_SGIRLE,
139  .init = sgirle_decode_init,
140  .decode = sgirle_decode_frame,
141  .capabilities = AV_CODEC_CAP_DR1,
142 };
AVCodec
AVCodec.
Definition: codec.h:190
rbg323_to_bgr8
static av_always_inline void rbg323_to_bgr8(uint8_t *dst, const uint8_t *src, int size)
Definition: sgirledec.c:48
sgirle_decode_init
static av_cold int sgirle_decode_init(AVCodecContext *avctx)
Definition: sgirledec.c:34
INC_XY
#define INC_XY(n)
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:300
internal.h
AVPacket::data
uint8_t * data
Definition: packet.h:355
data
const char data[16]
Definition: mxf.c:91
x
FFmpeg Automated Testing Environment ************************************Introduction Using FATE from your FFmpeg source directory Submitting the results to the FFmpeg result aggregation server Uploading new samples to the fate suite FATE makefile targets and variables Makefile targets Makefile variables Examples Introduction **************FATE is an extended regression suite on the client side and a means for results aggregation and presentation on the server side The first part of this document explains how you can use FATE from your FFmpeg source directory to test your ffmpeg binary The second part describes how you can run FATE to submit the results to FFmpeg’s FATE server In any way you can have a look at the publicly viewable FATE results by visiting this as it can be seen if some test on some platform broke with their recent contribution This usually happens on the platforms the developers could not test on The second part of this document describes how you can run FATE to submit your results to FFmpeg’s FATE server If you want to submit your results be sure to check that your combination of OS and compiler is not already listed on the above mentioned website In the third part you can find a comprehensive listing of FATE makefile targets and variables Using FATE from your FFmpeg source directory **********************************************If you want to run FATE on your machine you need to have the samples in place You can get the samples via the build target fate rsync Use this command from the top level source this will cause FATE to fail NOTE To use a custom wrapper to run the pass ‘ target exec’ to ‘configure’ or set the TARGET_EXEC Make variable Submitting the results to the FFmpeg result aggregation server ****************************************************************To submit your results to the server you should run fate through the shell script ‘tests fate sh’ from the FFmpeg sources This script needs to be invoked with a configuration file as its first argument tests fate sh path to fate_config A configuration file template with comments describing the individual configuration variables can be found at ‘doc fate_config sh template’ Create a configuration that suits your based on the configuration template The ‘slot’ configuration variable can be any string that is not yet but it is suggested that you name it adhering to the following pattern ‘ARCH OS COMPILER COMPILER VERSION’ The configuration file itself will be sourced in a shell therefore all shell features may be used This enables you to setup the environment as you need it for your build For your first test runs the ‘fate_recv’ variable should be empty or commented out This will run everything as normal except that it will omit the submission of the results to the server The following files should be present in $workdir as specified in the configuration it may help to try out the ‘ssh’ command with one or more ‘ v’ options You should get detailed output concerning your SSH configuration and the authentication process The only thing left is to automate the execution of the fate sh script and the synchronisation of the samples directory Uploading new samples to the fate suite *****************************************If you need a sample uploaded send a mail to samples request This is for developers who have an account on the fate suite server If you upload new please make sure they are as small as space on each network bandwidth and so on benefit from smaller test cases Also keep in mind older checkouts use existing sample that means in practice generally do not remove or overwrite files as it likely would break older checkouts or releases Also all needed samples for a commit should be ideally before the push If you need an account for frequently uploading samples or you wish to help others by doing that send a mail to ffmpeg devel rsync vauL Duo x
Definition: fate.txt:150
FFMIN3
#define FFMIN3(a, b, c)
Definition: common.h:97
ff_sgirle_decoder
AVCodec ff_sgirle_decoder
Definition: sgirledec.c:134
AV_PIX_FMT_BGR8
@ AV_PIX_FMT_BGR8
packed RGB 3:3:2, 8bpp, (msb)2B 3G 3R(lsb)
Definition: pixfmt.h:83
av_cold
#define av_cold
Definition: attributes.h:90
width
#define width
AVERROR_PATCHWELCOME
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition: error.h:62
AV_PICTURE_TYPE_I
@ AV_PICTURE_TYPE_I
Intra.
Definition: avutil.h:274
src
#define src
Definition: vp8dsp.c:254
ff_get_buffer
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
Definition: decode.c:1854
AV_CODEC_CAP_DR1
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
Definition: codec.h:50
AVPacket::size
int size
Definition: packet.h:356
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:186
size
int size
Definition: twinvq_data.h:11134
height
#define height
FFMIN
#define FFMIN(a, b)
Definition: common.h:96
sgirle_decode_frame
static int sgirle_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
Definition: sgirledec.c:112
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:269
common.h
av_always_inline
#define av_always_inline
Definition: attributes.h:49
uint8_t
uint8_t
Definition: audio_convert.c:194
AVCodec::name
const char * name
Name of the codec implementation.
Definition: codec.h:197
AVCodecContext::height
int height
Definition: avcodec.h:699
AVCodecContext::pix_fmt
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:736
avcodec.h
ret
ret
Definition: filter_design.txt:187
RBG323_TO_BGR8
#define RBG323_TO_BGR8(x)
Convert SGI RBG323 pixel into AV_PIX_FMT_BGR8 SGI RGB data is packed as 8bpp, (msb)3R 2B 3G(lsb)
Definition: sgirledec.c:44
frame
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
Definition: filter_design.txt:264
AVCodecContext
main external API structure.
Definition: avcodec.h:526
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
avpriv_request_sample
#define avpriv_request_sample(...)
Definition: tableprint_vlc.h:39
AVPacket
This structure stores compressed data.
Definition: packet.h:332
AV_CODEC_ID_SGIRLE
@ AV_CODEC_ID_SGIRLE
Definition: codec_id.h:232
AVCodecContext::width
int width
picture width / height.
Definition: avcodec.h:699
decode_sgirle8
static int decode_sgirle8(AVCodecContext *avctx, uint8_t *dst, const uint8_t *src, int src_size, int width, int height, ptrdiff_t linesize)
Definition: sgirledec.c:65