mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2024-12-23 12:43:46 +02:00
Merge remote-tracking branch 'qatar/master'
* qatar/master: tests: Refactor rotozoom/videogen common code into a separate file. tests: Mark some file-internal symbols as static. build: Drop leftover .exp pattern from LIBSUFFIXES list. vsrc_buffer: return EAGAIN if no frame is available. WMAL: Shift output samples by the specified number of padding zeroes. WMAL: Restore removed code in mclms_predict() rtpdec_h264: Remove a useless ifdef rtpdec_h264: Remove outdated/useless/incorrect comments rtpdec_h264: Remove useless memory corruption checks rtpdec_h264: Return proper error codes rtpdec_h264: Check the available data length before reading rtpdec_h264: Add input size checks png: check bit depth for PAL8/Y400A pixel formats. ea: check chunk_size for validity. celp filters: Do not read earlier than the start of the 'out' vector. Conflicts: libavcodec/pngdec.c libavfilter/src_buffer.c tests/rotozoom.c Merged-by: Michael Niedermayer <michaelni@gmx.at>
This commit is contained in:
commit
517dcc9b5f
@ -115,6 +115,6 @@ OBJDIRS := $(OBJDIRS) $(dir $(OBJS) $(HOSTOBJS) $(TESTOBJS))
|
||||
|
||||
CLEANSUFFIXES = *.d *.o *~ *.ho *.map *.ver *.gcno *.gcda
|
||||
DISTCLEANSUFFIXES = *.pc
|
||||
LIBSUFFIXES = *.a *.lib *.so *.so.* *.dylib *.dll *.def *.dll.a *.exp
|
||||
LIBSUFFIXES = *.a *.lib *.so *.so.* *.dylib *.dll *.def *.dll.a
|
||||
|
||||
-include $(wildcard $(OBJS:.o=.d) $(TESTOBJS:.o=.d))
|
||||
|
@ -133,9 +133,8 @@ void ff_celp_lp_synthesis_filterf(float *out, const float *filter_coeffs,
|
||||
out2 -= val * old_out2;
|
||||
out3 -= val * old_out3;
|
||||
|
||||
old_out3 = out[-5];
|
||||
|
||||
for (i = 5; i <= filter_length; i += 2) {
|
||||
old_out3 = out[-i];
|
||||
val = filter_coeffs[i-1];
|
||||
|
||||
out0 -= val * old_out3;
|
||||
@ -154,7 +153,6 @@ void ff_celp_lp_synthesis_filterf(float *out, const float *filter_coeffs,
|
||||
|
||||
FFSWAP(float, old_out0, old_out2);
|
||||
old_out1 = old_out3;
|
||||
old_out3 = out[-i-2];
|
||||
}
|
||||
|
||||
tmp0 = out0;
|
||||
|
@ -501,7 +501,7 @@ static int decode_frame(AVCodecContext *avctx,
|
||||
avctx->pix_fmt = PIX_FMT_MONOBLACK;
|
||||
} else if (s->bit_depth == 8 &&
|
||||
s->color_type == PNG_COLOR_TYPE_GRAY_ALPHA) {
|
||||
avctx->pix_fmt = PIX_FMT_GRAY8A;
|
||||
avctx->pix_fmt = PIX_FMT_Y400A;
|
||||
} else {
|
||||
av_log(avctx, AV_LOG_ERROR, "unsupported bit depth %d "
|
||||
"and color type %d\n",
|
||||
|
@ -658,9 +658,9 @@ static void mclms_predict(WmallDecodeCtx *s, int icoef, int *pred)
|
||||
int num_channels = s->num_channels;
|
||||
|
||||
for (ich = 0; ich < num_channels; ich++) {
|
||||
pred[ich] = 0;
|
||||
if (!s->is_channel_coded[ich])
|
||||
continue;
|
||||
pred[ich] = 0;
|
||||
for (i = 0; i < order * num_channels; i++)
|
||||
pred[ich] += s->mclms_prevvalues[i + s->mclms_recent] *
|
||||
s->mclms_coeffs[i + order * num_channels * ich];
|
||||
@ -983,10 +983,10 @@ static int decode_subframe(WmallDecodeCtx *s)
|
||||
|
||||
for (j = 0; j < subframe_len; j++) {
|
||||
if (s->bits_per_sample == 16) {
|
||||
*s->samples_16[c] = (int16_t) s->channel_residues[c][j];
|
||||
*s->samples_16[c] = (int16_t) s->channel_residues[c][j] << padding_zeroes;
|
||||
s->samples_16[c] += s->num_channels;
|
||||
} else {
|
||||
*s->samples_32[c] = s->channel_residues[c][j];
|
||||
*s->samples_32[c] = s->channel_residues[c][j] << padding_zeroes;
|
||||
s->samples_32[c] += s->num_channels;
|
||||
}
|
||||
}
|
||||
|
@ -495,12 +495,17 @@ static int ea_read_packet(AVFormatContext *s,
|
||||
|
||||
while (!packet_read || partial_packet) {
|
||||
chunk_type = avio_rl32(pb);
|
||||
chunk_size = (ea->big_endian ? avio_rb32(pb) : avio_rl32(pb)) - 8;
|
||||
chunk_size = ea->big_endian ? avio_rb32(pb) : avio_rl32(pb);
|
||||
if (chunk_size <= 8)
|
||||
return AVERROR_INVALIDDATA;
|
||||
chunk_size -= 8;
|
||||
|
||||
switch (chunk_type) {
|
||||
/* audio data */
|
||||
case ISNh_TAG:
|
||||
/* header chunk also contains data; skip over the header portion*/
|
||||
if (chunk_size < 32)
|
||||
return AVERROR_INVALIDDATA;
|
||||
avio_skip(pb, 32);
|
||||
chunk_size -= 32;
|
||||
case ISNd_TAG:
|
||||
|
@ -30,10 +30,6 @@
|
||||
* Single Nal Unit Mode (0), or
|
||||
* Non-Interleaved Mode (1). It currently does not support
|
||||
* Interleaved Mode (2). (This requires implementing STAP-B, MTAP16, MTAP24, FU-B packet types)
|
||||
*
|
||||
* @note TODO:
|
||||
* 1) RTCP sender reports for udp streams are required..
|
||||
*
|
||||
*/
|
||||
|
||||
#include "libavutil/base64.h"
|
||||
@ -49,26 +45,17 @@
|
||||
#include "rtpdec.h"
|
||||
#include "rtpdec_formats.h"
|
||||
|
||||
/**
|
||||
RTP/H264 specific private data.
|
||||
*/
|
||||
struct PayloadContext {
|
||||
unsigned long cookie; ///< sanity check, to make sure we get the pointer we're expecting.
|
||||
|
||||
//sdp setup parameters
|
||||
uint8_t profile_idc; ///< from the sdp setup parameters.
|
||||
uint8_t profile_iop; ///< from the sdp setup parameters.
|
||||
uint8_t level_idc; ///< from the sdp setup parameters.
|
||||
int packetization_mode; ///< from the sdp setup parameters.
|
||||
uint8_t profile_idc;
|
||||
uint8_t profile_iop;
|
||||
uint8_t level_idc;
|
||||
int packetization_mode;
|
||||
#ifdef DEBUG
|
||||
int packet_types_received[32];
|
||||
#endif
|
||||
};
|
||||
|
||||
#define MAGIC_COOKIE (0xdeadbeef) ///< Cookie for the extradata; to verify we are what we think we are, and that we haven't been freed.
|
||||
#define DEAD_COOKIE (0xdeaddead) ///< Cookie for the extradata; once it is freed.
|
||||
|
||||
/* ---------------- private code */
|
||||
static int sdp_parse_fmtp_config_h264(AVStream * stream,
|
||||
PayloadContext * h264_data,
|
||||
char *attr, char *value)
|
||||
@ -104,7 +91,6 @@ static int sdp_parse_fmtp_config_h264(AVStream * stream,
|
||||
buffer[0] = value[4]; buffer[1] = value[5];
|
||||
level_idc = strtol(buffer, NULL, 16);
|
||||
|
||||
// set the parameters...
|
||||
av_log(codec, AV_LOG_DEBUG,
|
||||
"RTP Profile IDC: %x Profile IOP: %x Level: %x\n",
|
||||
profile_idc, profile_iop, level_idc);
|
||||
@ -141,7 +127,6 @@ static int sdp_parse_fmtp_config_h264(AVStream * stream,
|
||||
{
|
||||
if(codec->extradata_size)
|
||||
{
|
||||
// av_realloc?
|
||||
memcpy(dest, codec->extradata, codec->extradata_size);
|
||||
av_free(codec->extradata);
|
||||
}
|
||||
@ -173,15 +158,19 @@ static int h264_handle_packet(AVFormatContext *ctx,
|
||||
const uint8_t * buf,
|
||||
int len, int flags)
|
||||
{
|
||||
uint8_t nal = buf[0];
|
||||
uint8_t type = (nal & 0x1f);
|
||||
uint8_t nal;
|
||||
uint8_t type;
|
||||
int result= 0;
|
||||
uint8_t start_sequence[] = { 0, 0, 0, 1 };
|
||||
|
||||
#ifdef DEBUG
|
||||
if (!len) {
|
||||
av_log(ctx, AV_LOG_ERROR, "Empty H264 RTP packet\n");
|
||||
return AVERROR_INVALIDDATA;
|
||||
}
|
||||
nal = buf[0];
|
||||
type = nal & 0x1f;
|
||||
|
||||
assert(data);
|
||||
assert(data->cookie == MAGIC_COOKIE);
|
||||
#endif
|
||||
assert(buf);
|
||||
|
||||
if (type >= 1 && type <= 23)
|
||||
@ -211,8 +200,8 @@ static int h264_handle_packet(AVFormatContext *ctx,
|
||||
const uint8_t *src= buf;
|
||||
int src_len= len;
|
||||
|
||||
do {
|
||||
uint16_t nal_size = AV_RB16(src); // this going to be a problem if unaligned (can it be?)
|
||||
while (src_len > 2) {
|
||||
uint16_t nal_size = AV_RB16(src);
|
||||
|
||||
// consume the length of the aggregate...
|
||||
src += 2;
|
||||
@ -245,7 +234,7 @@ static int h264_handle_packet(AVFormatContext *ctx,
|
||||
if (src_len < 0)
|
||||
av_log(ctx, AV_LOG_ERROR,
|
||||
"Consumed more bytes than we got! (%d)\n", src_len);
|
||||
} while (src_len > 2); // because there could be rtp padding..
|
||||
}
|
||||
|
||||
if(pass==0) {
|
||||
// now we know the total size of the packet (with the start sequences added)
|
||||
@ -265,16 +254,16 @@ static int h264_handle_packet(AVFormatContext *ctx,
|
||||
av_log(ctx, AV_LOG_ERROR,
|
||||
"Unhandled type (%d) (See RFC for implementation details\n",
|
||||
type);
|
||||
result= -1;
|
||||
result = AVERROR(ENOSYS);
|
||||
break;
|
||||
|
||||
case 28: // FU-A (fragmented nal)
|
||||
buf++;
|
||||
len--; // skip the fu_indicator
|
||||
{
|
||||
if (len > 1) {
|
||||
// these are the same as above, we just redo them here for clarity...
|
||||
uint8_t fu_indicator = nal;
|
||||
uint8_t fu_header = *buf; // read the fu_header.
|
||||
uint8_t fu_header = *buf;
|
||||
uint8_t start_bit = fu_header >> 7;
|
||||
// uint8_t end_bit = (fu_header & 0x40) >> 6;
|
||||
uint8_t nal_type = (fu_header & 0x1f);
|
||||
@ -302,6 +291,9 @@ static int h264_handle_packet(AVFormatContext *ctx,
|
||||
av_new_packet(pkt, len);
|
||||
memcpy(pkt->data, buf, len);
|
||||
}
|
||||
} else {
|
||||
av_log(ctx, AV_LOG_ERROR, "Too short data for FU-A H264 RTP packet\n");
|
||||
result = AVERROR_INVALIDDATA;
|
||||
}
|
||||
break;
|
||||
|
||||
@ -309,7 +301,7 @@ static int h264_handle_packet(AVFormatContext *ctx,
|
||||
case 31: // undefined
|
||||
default:
|
||||
av_log(ctx, AV_LOG_ERROR, "Undefined type (%d)", type);
|
||||
result= -1;
|
||||
result = AVERROR_INVALIDDATA;
|
||||
break;
|
||||
}
|
||||
|
||||
@ -318,18 +310,9 @@ static int h264_handle_packet(AVFormatContext *ctx,
|
||||
return result;
|
||||
}
|
||||
|
||||
/* ---------------- public code */
|
||||
static PayloadContext *h264_new_context(void)
|
||||
{
|
||||
PayloadContext *data =
|
||||
av_mallocz(sizeof(PayloadContext) +
|
||||
FF_INPUT_BUFFER_PADDING_SIZE);
|
||||
|
||||
if (data) {
|
||||
data->cookie = MAGIC_COOKIE;
|
||||
}
|
||||
|
||||
return data;
|
||||
return av_mallocz(sizeof(PayloadContext) + FF_INPUT_BUFFER_PADDING_SIZE);
|
||||
}
|
||||
|
||||
static void h264_free_context(PayloadContext *data)
|
||||
@ -344,13 +327,6 @@ static void h264_free_context(PayloadContext *data)
|
||||
}
|
||||
#endif
|
||||
|
||||
assert(data);
|
||||
assert(data->cookie == MAGIC_COOKIE);
|
||||
|
||||
// avoid stale pointers (assert)
|
||||
data->cookie = DEAD_COOKIE;
|
||||
|
||||
// and clear out this...
|
||||
av_free(data);
|
||||
}
|
||||
|
||||
@ -366,7 +342,6 @@ static int parse_h264_sdp_line(AVFormatContext *s, int st_index,
|
||||
|
||||
stream = s->streams[st_index];
|
||||
codec = stream->codec;
|
||||
assert(h264_data->cookie == MAGIC_COOKIE);
|
||||
|
||||
if (av_strstart(p, "framesize:", &p)) {
|
||||
char buf1[50];
|
||||
@ -392,12 +367,9 @@ static int parse_h264_sdp_line(AVFormatContext *s, int st_index,
|
||||
// could use this if we wanted.
|
||||
}
|
||||
|
||||
return 0; // keep processing it the normal way...
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
This is the structure for expanding on the dynamic rtp protocols (makes everything static. yay!)
|
||||
*/
|
||||
RTPDynamicProtocolHandler ff_h264_dynamic_handler = {
|
||||
.enc_name = "H264",
|
||||
.codec_type = AVMEDIA_TYPE_VIDEO,
|
||||
|
@ -17,6 +17,9 @@ ffservertest: ffserver$(EXESUF) tests/vsynth1/00.pgm tests/data/asynth1.sw
|
||||
|
||||
OBJDIRS += tests/data tests/vsynth1 tests/vsynth2
|
||||
|
||||
# Required due to missing automatic dependency tracking for HOSTOBJS.
|
||||
tests/rotozoom.o tests/videogen.o: tests/utils.c
|
||||
|
||||
tests/vsynth1/00.pgm: tests/videogen$(HOSTEXESUF) | tests/vsynth1
|
||||
$(M)./$< 'tests/vsynth1/'
|
||||
|
||||
|
136
tests/rotozoom.c
136
tests/rotozoom.c
@ -24,6 +24,8 @@
|
||||
#include <stdio.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
#include "utils.c"
|
||||
|
||||
#define FIXP (1 << 16)
|
||||
#define MY_PI 205887 // (M_PI * FIX)
|
||||
|
||||
@ -53,136 +55,12 @@ static int64_t int_sin(int64_t a)
|
||||
return a - int_pow(a, 3) / 6 + int_pow(a, 5) / 120 - int_pow(a, 7) / 5040;
|
||||
}
|
||||
|
||||
#define SCALEBITS 8
|
||||
#define ONE_HALF (1 << (SCALEBITS - 1))
|
||||
#define FIX(x) ((int) ((x) * (1L << SCALEBITS) + 0.5))
|
||||
static unsigned char tab_r[256 * 256];
|
||||
static unsigned char tab_g[256 * 256];
|
||||
static unsigned char tab_b[256 * 256];
|
||||
|
||||
static void rgb24_to_yuv420p(unsigned char *lum, unsigned char *cb,
|
||||
unsigned char *cr, const unsigned char *src,
|
||||
int width, int height)
|
||||
{
|
||||
int wrap, wrap3, x, y;
|
||||
int r, g, b, r1, g1, b1;
|
||||
const unsigned char *p;
|
||||
|
||||
wrap = width;
|
||||
wrap3 = width * 3;
|
||||
p = src;
|
||||
for (y = 0; y < height; y += 2) {
|
||||
for (x = 0; x < width; x += 2) {
|
||||
r = p[0];
|
||||
g = p[1];
|
||||
b = p[2];
|
||||
r1 = r;
|
||||
g1 = g;
|
||||
b1 = b;
|
||||
lum[0] = (FIX(0.29900) * r + FIX(0.58700) * g +
|
||||
FIX(0.11400) * b + ONE_HALF) >> SCALEBITS;
|
||||
r = p[3];
|
||||
g = p[4];
|
||||
b = p[5];
|
||||
r1 += r;
|
||||
g1 += g;
|
||||
b1 += b;
|
||||
lum[1] = (FIX(0.29900) * r + FIX(0.58700) * g +
|
||||
FIX(0.11400) * b + ONE_HALF) >> SCALEBITS;
|
||||
p += wrap3;
|
||||
lum += wrap;
|
||||
|
||||
r = p[0];
|
||||
g = p[1];
|
||||
b = p[2];
|
||||
r1 += r;
|
||||
g1 += g;
|
||||
b1 += b;
|
||||
lum[0] = (FIX(0.29900) * r + FIX(0.58700) * g +
|
||||
FIX(0.11400) * b + ONE_HALF) >> SCALEBITS;
|
||||
r = p[3];
|
||||
g = p[4];
|
||||
b = p[5];
|
||||
r1 += r;
|
||||
g1 += g;
|
||||
b1 += b;
|
||||
lum[1] = (FIX(0.29900) * r + FIX(0.58700) * g +
|
||||
FIX(0.11400) * b + ONE_HALF) >> SCALEBITS;
|
||||
|
||||
cb[0] = ((- FIX(0.16874) * r1 - FIX(0.33126) * g1 +
|
||||
FIX(0.50000) * b1 + 4 * ONE_HALF - 1) >> (SCALEBITS + 2)) + 128;
|
||||
cr[0] = ((FIX(0.50000) * r1 - FIX(0.41869) * g1 -
|
||||
FIX(0.08131) * b1 + 4 * ONE_HALF - 1) >> (SCALEBITS + 2)) + 128;
|
||||
|
||||
cb++;
|
||||
cr++;
|
||||
p += -wrap3 + 2 * 3;
|
||||
lum += -wrap + 2;
|
||||
}
|
||||
p += wrap3;
|
||||
lum += wrap;
|
||||
}
|
||||
}
|
||||
|
||||
/* cif format */
|
||||
#define DEFAULT_WIDTH 352
|
||||
#define DEFAULT_HEIGHT 288
|
||||
#define DEFAULT_NB_PICT 50
|
||||
|
||||
static void pgmyuv_save(const char *filename, int w, int h,
|
||||
unsigned char *rgb_tab)
|
||||
{
|
||||
FILE *f;
|
||||
int i, h2, w2;
|
||||
unsigned char *cb, *cr;
|
||||
unsigned char *lum_tab, *cb_tab, *cr_tab;
|
||||
|
||||
lum_tab = malloc(w * h);
|
||||
cb_tab = malloc(w * h / 4);
|
||||
cr_tab = malloc(w * h / 4);
|
||||
|
||||
rgb24_to_yuv420p(lum_tab, cb_tab, cr_tab, rgb_tab, w, h);
|
||||
|
||||
f = fopen(filename, "wb");
|
||||
fprintf(f, "P5\n%d %d\n%d\n", w, h * 3 / 2, 255);
|
||||
fwrite(lum_tab, 1, w * h, f);
|
||||
h2 = h / 2;
|
||||
w2 = w / 2;
|
||||
cb = cb_tab;
|
||||
cr = cr_tab;
|
||||
for (i = 0; i < h2; i++) {
|
||||
fwrite(cb, 1, w2, f);
|
||||
fwrite(cr, 1, w2, f);
|
||||
cb += w2;
|
||||
cr += w2;
|
||||
}
|
||||
fclose(f);
|
||||
|
||||
free(lum_tab);
|
||||
free(cb_tab);
|
||||
free(cr_tab);
|
||||
}
|
||||
|
||||
unsigned char *rgb_tab;
|
||||
int width, height, wrap;
|
||||
|
||||
static void put_pixel(int x, int y, int r, int g, int b)
|
||||
{
|
||||
unsigned char *p;
|
||||
|
||||
if (x < 0 || x >= width ||
|
||||
y < 0 || y >= height)
|
||||
return;
|
||||
|
||||
p = rgb_tab + y * wrap + x * 3;
|
||||
p[0] = r;
|
||||
p[1] = g;
|
||||
p[2] = b;
|
||||
}
|
||||
|
||||
unsigned char tab_r[256 * 256];
|
||||
unsigned char tab_g[256 * 256];
|
||||
unsigned char tab_b[256 * 256];
|
||||
|
||||
int h_cos[360];
|
||||
int h_sin[360];
|
||||
static int h_cos[360];
|
||||
static int h_sin[360];
|
||||
|
||||
static int ipol(uint8_t *src, int x, int y)
|
||||
{
|
||||
|
146
tests/utils.c
Normal file
146
tests/utils.c
Normal file
@ -0,0 +1,146 @@
|
||||
/*
|
||||
* copyright (c) Sebastien Bechet <s.bechet@av7.net>
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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 FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#define SCALEBITS 8
|
||||
#define ONE_HALF (1 << (SCALEBITS - 1))
|
||||
#define FIX(x) ((int) ((x) * (1L << SCALEBITS) + 0.5))
|
||||
|
||||
static void rgb24_to_yuv420p(unsigned char *lum, unsigned char *cb,
|
||||
unsigned char *cr, unsigned char *src,
|
||||
int width, int height)
|
||||
{
|
||||
int wrap, wrap3, x, y;
|
||||
int r, g, b, r1, g1, b1;
|
||||
unsigned char *p;
|
||||
|
||||
wrap = width;
|
||||
wrap3 = width * 3;
|
||||
p = src;
|
||||
for (y = 0; y < height; y += 2) {
|
||||
for (x = 0; x < width; x += 2) {
|
||||
r = p[0];
|
||||
g = p[1];
|
||||
b = p[2];
|
||||
r1 = r;
|
||||
g1 = g;
|
||||
b1 = b;
|
||||
lum[0] = (FIX(0.29900) * r + FIX(0.58700) * g +
|
||||
FIX(0.11400) * b + ONE_HALF) >> SCALEBITS;
|
||||
r = p[3];
|
||||
g = p[4];
|
||||
b = p[5];
|
||||
r1 += r;
|
||||
g1 += g;
|
||||
b1 += b;
|
||||
lum[1] = (FIX(0.29900) * r + FIX(0.58700) * g +
|
||||
FIX(0.11400) * b + ONE_HALF) >> SCALEBITS;
|
||||
p += wrap3;
|
||||
lum += wrap;
|
||||
|
||||
r = p[0];
|
||||
g = p[1];
|
||||
b = p[2];
|
||||
r1 += r;
|
||||
g1 += g;
|
||||
b1 += b;
|
||||
lum[0] = (FIX(0.29900) * r + FIX(0.58700) * g +
|
||||
FIX(0.11400) * b + ONE_HALF) >> SCALEBITS;
|
||||
r = p[3];
|
||||
g = p[4];
|
||||
b = p[5];
|
||||
r1 += r;
|
||||
g1 += g;
|
||||
b1 += b;
|
||||
lum[1] = (FIX(0.29900) * r + FIX(0.58700) * g +
|
||||
FIX(0.11400) * b + ONE_HALF) >> SCALEBITS;
|
||||
|
||||
cb[0] = ((- FIX(0.16874) * r1 - FIX(0.33126) * g1 +
|
||||
FIX(0.50000) * b1 + 4 * ONE_HALF - 1) >> (SCALEBITS + 2)) + 128;
|
||||
cr[0] = ((FIX(0.50000) * r1 - FIX(0.41869) * g1 -
|
||||
FIX(0.08131) * b1 + 4 * ONE_HALF - 1) >> (SCALEBITS + 2)) + 128;
|
||||
|
||||
cb++;
|
||||
cr++;
|
||||
p += -wrap3 + 2 * 3;
|
||||
lum += -wrap + 2;
|
||||
}
|
||||
p += wrap3;
|
||||
lum += wrap;
|
||||
}
|
||||
}
|
||||
|
||||
/* cif format */
|
||||
#define DEFAULT_WIDTH 352
|
||||
#define DEFAULT_HEIGHT 288
|
||||
#define DEFAULT_NB_PICT 50
|
||||
|
||||
static void pgmyuv_save(const char *filename, int w, int h,
|
||||
unsigned char *rgb_tab)
|
||||
{
|
||||
FILE *f;
|
||||
int i, h2, w2;
|
||||
unsigned char *cb, *cr;
|
||||
unsigned char *lum_tab, *cb_tab, *cr_tab;
|
||||
|
||||
lum_tab = malloc(w * h);
|
||||
cb_tab = malloc(w * h / 4);
|
||||
cr_tab = malloc(w * h / 4);
|
||||
|
||||
rgb24_to_yuv420p(lum_tab, cb_tab, cr_tab, rgb_tab, w, h);
|
||||
|
||||
f = fopen(filename, "wb");
|
||||
fprintf(f, "P5\n%d %d\n%d\n", w, h * 3 / 2, 255);
|
||||
fwrite(lum_tab, 1, w * h, f);
|
||||
h2 = h / 2;
|
||||
w2 = w / 2;
|
||||
cb = cb_tab;
|
||||
cr = cr_tab;
|
||||
for (i = 0; i < h2; i++) {
|
||||
fwrite(cb, 1, w2, f);
|
||||
fwrite(cr, 1, w2, f);
|
||||
cb += w2;
|
||||
cr += w2;
|
||||
}
|
||||
fclose(f);
|
||||
|
||||
free(lum_tab);
|
||||
free(cb_tab);
|
||||
free(cr_tab);
|
||||
}
|
||||
|
||||
static unsigned char *rgb_tab;
|
||||
static int width, height, wrap;
|
||||
|
||||
static void put_pixel(int x, int y, int r, int g, int b)
|
||||
{
|
||||
unsigned char *p;
|
||||
|
||||
if (x < 0 || x >= width ||
|
||||
y < 0 || y >= height)
|
||||
return;
|
||||
|
||||
p = rgb_tab + y * wrap + x * 3;
|
||||
p[0] = r;
|
||||
p[1] = g;
|
||||
p[2] = b;
|
||||
}
|
133
tests/videogen.c
133
tests/videogen.c
@ -25,134 +25,7 @@
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#define SCALEBITS 8
|
||||
#define ONE_HALF (1 << (SCALEBITS - 1))
|
||||
#define FIX(x) ((int) ((x) * (1L << SCALEBITS) + 0.5))
|
||||
|
||||
static void rgb24_to_yuv420p(uint8_t *lum, uint8_t *cb, uint8_t *cr,
|
||||
uint8_t *src, int width, int height)
|
||||
{
|
||||
int wrap, wrap3, x, y;
|
||||
int r, g, b, r1, g1, b1;
|
||||
uint8_t *p;
|
||||
|
||||
wrap = width;
|
||||
wrap3 = width * 3;
|
||||
p = src;
|
||||
for (y = 0; y < height; y += 2) {
|
||||
for (x = 0; x < width; x += 2) {
|
||||
r = p[0];
|
||||
g = p[1];
|
||||
b = p[2];
|
||||
r1 = r;
|
||||
g1 = g;
|
||||
b1 = b;
|
||||
lum[0] = (FIX(0.29900) * r + FIX(0.58700) * g +
|
||||
FIX(0.11400) * b + ONE_HALF) >> SCALEBITS;
|
||||
r = p[3];
|
||||
g = p[4];
|
||||
b = p[5];
|
||||
r1 += r;
|
||||
g1 += g;
|
||||
b1 += b;
|
||||
lum[1] = (FIX(0.29900) * r + FIX(0.58700) * g +
|
||||
FIX(0.11400) * b + ONE_HALF) >> SCALEBITS;
|
||||
p += wrap3;
|
||||
lum += wrap;
|
||||
|
||||
r = p[0];
|
||||
g = p[1];
|
||||
b = p[2];
|
||||
r1 += r;
|
||||
g1 += g;
|
||||
b1 += b;
|
||||
lum[0] = (FIX(0.29900) * r + FIX(0.58700) * g +
|
||||
FIX(0.11400) * b + ONE_HALF) >> SCALEBITS;
|
||||
r = p[3];
|
||||
g = p[4];
|
||||
b = p[5];
|
||||
r1 += r;
|
||||
g1 += g;
|
||||
b1 += b;
|
||||
lum[1] = (FIX(0.29900) * r + FIX(0.58700) * g +
|
||||
FIX(0.11400) * b + ONE_HALF) >> SCALEBITS;
|
||||
|
||||
cb[0] = 128 + ((- FIX(0.16874) * r1 -
|
||||
FIX(0.33126) * g1 +
|
||||
FIX(0.50000) * b1 +
|
||||
4 * ONE_HALF - 1)
|
||||
>> (SCALEBITS + 2));
|
||||
cr[0] = 128 + ((FIX(0.50000) * r1 -
|
||||
FIX(0.41869) * g1 -
|
||||
FIX(0.08131) * b1 +
|
||||
4 * ONE_HALF - 1)
|
||||
>> (SCALEBITS + 2));
|
||||
|
||||
cb++;
|
||||
cr++;
|
||||
p += -wrap3 + 2 * 3;
|
||||
lum += -wrap + 2;
|
||||
}
|
||||
p += wrap3;
|
||||
lum += wrap;
|
||||
}
|
||||
}
|
||||
|
||||
/* cif format */
|
||||
#define DEFAULT_WIDTH 352
|
||||
#define DEFAULT_HEIGHT 288
|
||||
#define DEFAULT_NB_PICT 50 /* 2 seconds */
|
||||
|
||||
static void pgmyuv_save(const char *filename, int w, int h,
|
||||
unsigned char *rgb_tab)
|
||||
{
|
||||
FILE *f;
|
||||
int i, h2, w2;
|
||||
unsigned char *cb, *cr;
|
||||
unsigned char *lum_tab, *cb_tab, *cr_tab;
|
||||
|
||||
lum_tab = malloc(w * h);
|
||||
cb_tab = malloc((w * h) / 4);
|
||||
cr_tab = malloc((w * h) / 4);
|
||||
|
||||
rgb24_to_yuv420p(lum_tab, cb_tab, cr_tab, rgb_tab, w, h);
|
||||
|
||||
f = fopen(filename, "wb");
|
||||
fprintf(f, "P5\n%d %d\n%d\n", w, (h * 3) / 2, 255);
|
||||
fwrite(lum_tab, 1, w * h, f);
|
||||
h2 = h / 2;
|
||||
w2 = w / 2;
|
||||
cb = cb_tab;
|
||||
cr = cr_tab;
|
||||
for (i = 0; i < h2; i++) {
|
||||
fwrite(cb, 1, w2, f);
|
||||
fwrite(cr, 1, w2, f);
|
||||
cb += w2;
|
||||
cr += w2;
|
||||
}
|
||||
fclose(f);
|
||||
|
||||
free(lum_tab);
|
||||
free(cb_tab);
|
||||
free(cr_tab);
|
||||
}
|
||||
|
||||
unsigned char *rgb_tab;
|
||||
int width, height, wrap;
|
||||
|
||||
static void put_pixel(int x, int y, int r, int g, int b)
|
||||
{
|
||||
unsigned char *p;
|
||||
|
||||
if (x < 0 || x >= width ||
|
||||
y < 0 || y >= height)
|
||||
return;
|
||||
|
||||
p = rgb_tab + y * wrap + x * 3;
|
||||
p[0] = r;
|
||||
p[1] = g;
|
||||
p[2] = b;
|
||||
}
|
||||
#include "utils.c"
|
||||
|
||||
static unsigned int myrnd(unsigned int *seed_ptr, int n)
|
||||
{
|
||||
@ -200,9 +73,9 @@ typedef struct VObj {
|
||||
int r, g, b;
|
||||
} VObj;
|
||||
|
||||
VObj objs[NB_OBJS];
|
||||
static VObj objs[NB_OBJS];
|
||||
|
||||
unsigned int seed = 1;
|
||||
static unsigned int seed = 1;
|
||||
|
||||
static void gen_image(int num, int w, int h)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user