You've already forked FFmpeg
							
							
				mirror of
				https://github.com/FFmpeg/FFmpeg.git
				synced 2025-10-30 23:18:11 +02:00 
			
		
		
		
	Merge remote-tracking branch 'qatar/master'
* qatar/master: avprobe, cmdutils: K&R formatting cosmetics tests: K&R formatting cosmetics for test programs lavf: free packets for muxers implementing interleave_packet(). lavf: fix and extend av_interleaved_write_frame() doxy. mov: Remove dead stores for spherical coordinates for channel position. error_resilience: K&R formatting cosmetics RELEASE_NOTES: mention hiding private symbols in shared builds. RELEASE_NOTES: mention some notable API changes in 0.8 Conflicts: cmdutils.h doc/RELEASE_NOTES ffprobe.c libavcodec/error_resilience.c Merged-by: Michael Niedermayer <michaelni@gmx.at>
This commit is contained in:
		
							
								
								
									
										18
									
								
								cmdutils.h
									
									
									
									
									
								
							
							
						
						
									
										18
									
								
								cmdutils.h
									
									
									
									
									
								
							| @@ -105,7 +105,8 @@ int opt_timelimit(const char *opt, const char *arg); | ||||
|  * @param min the minimum valid accepted value | ||||
|  * @param max the maximum valid accepted value | ||||
|  */ | ||||
| double parse_number_or_die(const char *context, const char *numstr, int type, double min, double max); | ||||
| double parse_number_or_die(const char *context, const char *numstr, int type, | ||||
|                            double min, double max); | ||||
|  | ||||
| /** | ||||
|  * Parse a string specifying a time and return its corresponding | ||||
| @@ -121,7 +122,8 @@ double parse_number_or_die(const char *context, const char *numstr, int type, do | ||||
|  * | ||||
|  * @see parse_date() | ||||
|  */ | ||||
| int64_t parse_time_or_die(const char *context, const char *timestr, int is_duration); | ||||
| int64_t parse_time_or_die(const char *context, const char *timestr, | ||||
|                           int is_duration); | ||||
|  | ||||
| typedef struct SpecifierOpt { | ||||
|     char *specifier;    /**< stream/chapter/program/... specifier */ | ||||
| @@ -167,7 +169,8 @@ typedef struct { | ||||
|     const char *argname; | ||||
| } OptionDef; | ||||
|  | ||||
| void show_help_options(const OptionDef *options, const char *msg, int mask, int value); | ||||
| void show_help_options(const OptionDef *options, const char *msg, int mask, | ||||
|                        int value); | ||||
|  | ||||
| /** | ||||
|  * Show help for all options with given flags in class and all its | ||||
| @@ -193,7 +196,8 @@ void parse_options(void *optctx, int argc, char **argv, const OptionDef *options | ||||
|  * | ||||
|  * @return on success 1 if arg was consumed, 0 otherwise; negative number on error | ||||
|  */ | ||||
| int parse_option(void *optctx, const char *opt, const char *arg, const OptionDef *options); | ||||
| int parse_option(void *optctx, const char *opt, const char *arg, | ||||
|                  const OptionDef *options); | ||||
|  | ||||
| /** | ||||
|  * Find the '-loglevel' option in the command line args and apply it. | ||||
| @@ -221,7 +225,8 @@ int check_stream_specifier(AVFormatContext *s, AVStream *st, const char *spec); | ||||
|  * @param st A stream from s for which the options should be filtered. | ||||
|  * @return a pointer to the created dictionary | ||||
|  */ | ||||
| AVDictionary *filter_codec_opts(AVDictionary *opts, AVCodec *codec, AVFormatContext *s, AVStream *st); | ||||
| AVDictionary *filter_codec_opts(AVDictionary *opts, AVCodec *codec, | ||||
|                                 AVFormatContext *s, AVStream *st); | ||||
|  | ||||
| /** | ||||
|  * Setup AVCodecContext options for avformat_find_stream_info(). | ||||
| @@ -234,7 +239,8 @@ AVDictionary *filter_codec_opts(AVDictionary *opts, AVCodec *codec, AVFormatCont | ||||
|  * @return pointer to the created array of dictionaries, NULL if it | ||||
|  * cannot be created | ||||
|  */ | ||||
| AVDictionary **setup_find_stream_info_opts(AVFormatContext *s, AVDictionary *codec_opts); | ||||
| AVDictionary **setup_find_stream_info_opts(AVFormatContext *s, | ||||
|                                            AVDictionary *codec_opts); | ||||
|  | ||||
| /** | ||||
|  * Print an error message to stderr, indicating filename and a human | ||||
|   | ||||
| @@ -6,7 +6,6 @@ Release Notes | ||||
|  | ||||
| General notes | ||||
| ------------- | ||||
|  | ||||
| This release is binary compatible with 0.8. The 'ffmpeg' command-line tool has | ||||
| been extended to also support the command line syntax and features of a tool | ||||
| called avconv. | ||||
| @@ -32,7 +31,30 @@ API changes | ||||
|  | ||||
| A number of additional APIs have been introduced and some existing | ||||
| functions have been deprecated and are scheduled for removal in the next | ||||
| release. Please see the file doc/APIchanges for details along with | ||||
| release. Significant API changes include: | ||||
|  | ||||
| * new audio decoding API which decodes from an AVPacket to an AVFrame and | ||||
| is able to use AVCodecContext.get_buffer() in the similar way as video decoding. | ||||
|  | ||||
| * new audio encoding API which encodes from an AVFrame to an AVPacket, thus | ||||
| allowing it to properly output timing information and side data. | ||||
|  | ||||
| * rewritten AVOptions API with better built-in support for private options. | ||||
|  | ||||
| * private options support for demuxers [avformat_open_input()], muxers | ||||
| [avformat_write_header()], encoders and decoders [avcodec_open2()]. | ||||
| As a result, many format- or codec-specific fields and flags in AVFormatContext | ||||
| and AVCodecContext were deprecated -- notably most of CODEC_FLAG2_* and many | ||||
| CODEC_FLAG_*. | ||||
|  | ||||
| * new API for custom IO interrupt callbacks. | ||||
|  | ||||
| * #include cleanup in libavutil -- libavutil/avutil.h no longer includes all | ||||
| the other headers in libavutil, they must be included manually. One specific | ||||
| result is that libavutil/mathematics.h is no longer included from | ||||
| libavcodec/avcodec.h, which is a common source of errors. | ||||
|  | ||||
| Please see the file doc/APIchanges for details along with | ||||
| similar programmer-centric information. | ||||
|  | ||||
|  | ||||
| @@ -40,5 +62,13 @@ similar programmer-centric information. | ||||
| Other notable changes | ||||
| --------------------- | ||||
|  | ||||
| Libavcodec and libavformat built as shared libraries now hide non-public | ||||
| symbols. This will break applications using those symbols. Possible solutions | ||||
| are, in order of preference: | ||||
| 1) Try finding a way of accomplishing the same with public API. | ||||
| 2) If there is no corresponding public API, but you think there should be, | ||||
| post a request on the user mailing list or IRC channel. | ||||
| 3) Finally if your program needs access to FFmpeg / libavcodec / libavformat | ||||
| internals for some special reason then the best solution is to link statically. | ||||
|  | ||||
| Please see the Changelog file for a more detailed list of changes. | ||||
|   | ||||
							
								
								
									
										21
									
								
								ffprobe.c
									
									
									
									
									
								
							
							
						
						
									
										21
									
								
								ffprobe.c
									
									
									
									
									
								
							| @@ -109,13 +109,13 @@ static char *value_string(char *buf, int buf_size, struct unit_value uv) | ||||
|  | ||||
|         if (uv.unit == unit_byte_str && use_byte_value_binary_prefix) { | ||||
|             index = (long long int) (log(vald)/log(2)) / 10; | ||||
|             index = av_clip(index, 0, FF_ARRAY_ELEMS(binary_unit_prefixes) -1); | ||||
|             vald /= pow(2, index*10); | ||||
|             index = av_clip(index, 0, FF_ARRAY_ELEMS(binary_unit_prefixes) - 1); | ||||
|             vald /= pow(2, index * 10); | ||||
|             prefix_string = binary_unit_prefixes[index]; | ||||
|         } else { | ||||
|             index = (long long int) (log10(vald)) / 3; | ||||
|             index = av_clip(index, 0, FF_ARRAY_ELEMS(decimal_unit_prefixes) -1); | ||||
|             vald /= pow(10, index*3); | ||||
|             index = av_clip(index, 0, FF_ARRAY_ELEMS(decimal_unit_prefixes) - 1); | ||||
|             vald /= pow(10, index * 3); | ||||
|             prefix_string = decimal_unit_prefixes[index]; | ||||
|         } | ||||
|  | ||||
| @@ -1557,7 +1557,8 @@ static int open_input_file(AVFormatContext **fmt_ctx_ptr, const char *filename) | ||||
|     AVFormatContext *fmt_ctx = NULL; | ||||
|     AVDictionaryEntry *t; | ||||
|  | ||||
|     if ((err = avformat_open_input(&fmt_ctx, filename, iformat, &format_opts)) < 0) { | ||||
|     if ((err = avformat_open_input(&fmt_ctx, filename, | ||||
|                                    iformat, &format_opts)) < 0) { | ||||
|         print_error(filename, err); | ||||
|         return err; | ||||
|     } | ||||
| @@ -1581,8 +1582,9 @@ static int open_input_file(AVFormatContext **fmt_ctx_ptr, const char *filename) | ||||
|         AVCodec *codec; | ||||
|  | ||||
|         if (!(codec = avcodec_find_decoder(stream->codec->codec_id))) { | ||||
|             av_log(NULL, AV_LOG_ERROR, "Unsupported codec with id %d for input stream %d\n", | ||||
|                    stream->codec->codec_id, stream->index); | ||||
|             av_log(NULL, AV_LOG_ERROR, | ||||
|                     "Unsupported codec with id %d for input stream %d\n", | ||||
|                     stream->codec->codec_id, stream->index); | ||||
|         } else if (avcodec_open2(stream->codec, codec, NULL) < 0) { | ||||
|             av_log(NULL, AV_LOG_ERROR, "Error while opening codec for input stream %d\n", | ||||
|                    stream->index); | ||||
| @@ -1700,8 +1702,9 @@ static int opt_format(const char *opt, const char *arg) | ||||
| static void opt_input_file(void *optctx, const char *arg) | ||||
| { | ||||
|     if (input_filename) { | ||||
|         av_log(NULL, AV_LOG_ERROR, "Argument '%s' provided as input filename, but '%s' was already specified.\n", | ||||
|                arg, input_filename); | ||||
|         av_log(NULL, AV_LOG_ERROR, | ||||
|                 "Argument '%s' provided as input filename, but '%s' was already specified.\n", | ||||
|                 arg, input_filename); | ||||
|         exit(1); | ||||
|     } | ||||
|     if (!strcmp(arg, "-")) | ||||
|   | ||||
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							| @@ -1819,9 +1819,18 @@ int av_write_frame(AVFormatContext *s, AVPacket *pkt); | ||||
|  * demuxer level. | ||||
|  * | ||||
|  * @param s media file handle | ||||
|  * @param pkt The packet, which contains the stream_index, buf/buf_size, | ||||
|               dts/pts, ... | ||||
|  * @return < 0 on error, = 0 if OK, 1 if end of stream wanted | ||||
|  * @param pkt The packet containing the data to be written. Libavformat takes | ||||
|  * ownership of the data and will free it when it sees fit using the packet's | ||||
|  * @ref AVPacket.destruct "destruct" field. The caller must not access the data | ||||
|  * after this function returns, as it may already be freed. | ||||
|  * Packet's @ref AVPacket.stream_index "stream_index" field must be set to the | ||||
|  * index of the corresponding stream in @ref AVFormatContext.streams | ||||
|  * "s.streams". | ||||
|  * It is very strongly recommended that timing information (@ref AVPacket.pts | ||||
|  * "pts", @ref AVPacket.dts "dts" @ref AVPacket.duration "duration") is set to | ||||
|  * correct values. | ||||
|  * | ||||
|  * @return 0 on success, a negative AVERROR on error. | ||||
|  */ | ||||
| int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt); | ||||
|  | ||||
|   | ||||
| @@ -602,12 +602,11 @@ static int mov_read_chan(MOVContext *c, AVIOContext *pb, MOVAtom atom) | ||||
|     label_mask = 0; | ||||
|     for (i = 0; i < num_descr; i++) { | ||||
|         uint32_t label, cflags; | ||||
|         float coords[3]; | ||||
|         label     = avio_rb32(pb);          // mChannelLabel | ||||
|         cflags    = avio_rb32(pb);          // mChannelFlags | ||||
|         AV_WN32(&coords[0], avio_rl32(pb)); // mCoordinates[0] | ||||
|         AV_WN32(&coords[1], avio_rl32(pb)); // mCoordinates[1] | ||||
|         AV_WN32(&coords[2], avio_rl32(pb)); // mCoordinates[2] | ||||
|         avio_rl32(pb);                      // mCoordinates[0] | ||||
|         avio_rl32(pb);                      // mCoordinates[1] | ||||
|         avio_rl32(pb);                      // mCoordinates[2] | ||||
|         if (layout_tag == 0) { | ||||
|             uint32_t mask_incr = ff_mov_get_channel_label(label); | ||||
|             if (mask_incr == 0) { | ||||
|   | ||||
| @@ -3492,9 +3492,12 @@ int av_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out, AVPacket *pk | ||||
|  *         < 0 if an error occurred | ||||
|  */ | ||||
| static int interleave_packet(AVFormatContext *s, AVPacket *out, AVPacket *in, int flush){ | ||||
|     if(s->oformat->interleave_packet) | ||||
|         return s->oformat->interleave_packet(s, out, in, flush); | ||||
|     else | ||||
|     if (s->oformat->interleave_packet) { | ||||
|         int ret = s->oformat->interleave_packet(s, out, in, flush); | ||||
|         if (in) | ||||
|             av_free_packet(in); | ||||
|         return ret; | ||||
|     } else | ||||
|         return av_interleave_packet_per_dts(s, out, in, flush); | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -48,23 +48,23 @@ static unsigned int myrnd(unsigned int *seed_ptr, int n) | ||||
|  | ||||
| /* integer cosinus */ | ||||
| static const unsigned short cos_table[(1 << COS_TABLE_BITS) + 2] = { | ||||
|  0x8000, 0x7ffe, 0x7ff6, 0x7fea, 0x7fd9, 0x7fc2, 0x7fa7, 0x7f87, | ||||
|  0x7f62, 0x7f38, 0x7f0a, 0x7ed6, 0x7e9d, 0x7e60, 0x7e1e, 0x7dd6, | ||||
|  0x7d8a, 0x7d3a, 0x7ce4, 0x7c89, 0x7c2a, 0x7bc6, 0x7b5d, 0x7aef, | ||||
|  0x7a7d, 0x7a06, 0x798a, 0x790a, 0x7885, 0x77fb, 0x776c, 0x76d9, | ||||
|  0x7642, 0x75a6, 0x7505, 0x7460, 0x73b6, 0x7308, 0x7255, 0x719e, | ||||
|  0x70e3, 0x7023, 0x6f5f, 0x6e97, 0x6dca, 0x6cf9, 0x6c24, 0x6b4b, | ||||
|  0x6a6e, 0x698c, 0x68a7, 0x67bd, 0x66d0, 0x65de, 0x64e9, 0x63ef, | ||||
|  0x62f2, 0x61f1, 0x60ec, 0x5fe4, 0x5ed7, 0x5dc8, 0x5cb4, 0x5b9d, | ||||
|  0x5a82, 0x5964, 0x5843, 0x571e, 0x55f6, 0x54ca, 0x539b, 0x5269, | ||||
|  0x5134, 0x4ffb, 0x4ec0, 0x4d81, 0x4c40, 0x4afb, 0x49b4, 0x486a, | ||||
|  0x471d, 0x45cd, 0x447b, 0x4326, 0x41ce, 0x4074, 0x3f17, 0x3db8, | ||||
|  0x3c57, 0x3af3, 0x398d, 0x3825, 0x36ba, 0x354e, 0x33df, 0x326e, | ||||
|  0x30fc, 0x2f87, 0x2e11, 0x2c99, 0x2b1f, 0x29a4, 0x2827, 0x26a8, | ||||
|  0x2528, 0x23a7, 0x2224, 0x209f, 0x1f1a, 0x1d93, 0x1c0c, 0x1a83, | ||||
|  0x18f9, 0x176e, 0x15e2, 0x1455, 0x12c8, 0x113a, 0x0fab, 0x0e1c, | ||||
|  0x0c8c, 0x0afb, 0x096b, 0x07d9, 0x0648, 0x04b6, 0x0324, 0x0192, | ||||
|  0x0000, 0x0000, | ||||
|     0x8000, 0x7ffe, 0x7ff6, 0x7fea, 0x7fd9, 0x7fc2, 0x7fa7, 0x7f87, | ||||
|     0x7f62, 0x7f38, 0x7f0a, 0x7ed6, 0x7e9d, 0x7e60, 0x7e1e, 0x7dd6, | ||||
|     0x7d8a, 0x7d3a, 0x7ce4, 0x7c89, 0x7c2a, 0x7bc6, 0x7b5d, 0x7aef, | ||||
|     0x7a7d, 0x7a06, 0x798a, 0x790a, 0x7885, 0x77fb, 0x776c, 0x76d9, | ||||
|     0x7642, 0x75a6, 0x7505, 0x7460, 0x73b6, 0x7308, 0x7255, 0x719e, | ||||
|     0x70e3, 0x7023, 0x6f5f, 0x6e97, 0x6dca, 0x6cf9, 0x6c24, 0x6b4b, | ||||
|     0x6a6e, 0x698c, 0x68a7, 0x67bd, 0x66d0, 0x65de, 0x64e9, 0x63ef, | ||||
|     0x62f2, 0x61f1, 0x60ec, 0x5fe4, 0x5ed7, 0x5dc8, 0x5cb4, 0x5b9d, | ||||
|     0x5a82, 0x5964, 0x5843, 0x571e, 0x55f6, 0x54ca, 0x539b, 0x5269, | ||||
|     0x5134, 0x4ffb, 0x4ec0, 0x4d81, 0x4c40, 0x4afb, 0x49b4, 0x486a, | ||||
|     0x471d, 0x45cd, 0x447b, 0x4326, 0x41ce, 0x4074, 0x3f17, 0x3db8, | ||||
|     0x3c57, 0x3af3, 0x398d, 0x3825, 0x36ba, 0x354e, 0x33df, 0x326e, | ||||
|     0x30fc, 0x2f87, 0x2e11, 0x2c99, 0x2b1f, 0x29a4, 0x2827, 0x26a8, | ||||
|     0x2528, 0x23a7, 0x2224, 0x209f, 0x1f1a, 0x1d93, 0x1c0c, 0x1a83, | ||||
|     0x18f9, 0x176e, 0x15e2, 0x1455, 0x12c8, 0x113a, 0x0fab, 0x0e1c, | ||||
|     0x0c8c, 0x0afb, 0x096b, 0x07d9, 0x0648, 0x04b6, 0x0324, 0x0192, | ||||
|     0x0000, 0x0000, | ||||
| }; | ||||
|  | ||||
| #define CSHIFT (FRAC_BITS - COS_TABLE_BITS - 2) | ||||
| @@ -80,7 +80,7 @@ static int int_cos(int a) | ||||
|     neg = 0; | ||||
|     if (a > (FRAC_ONE / 4)) { | ||||
|         neg = -1; | ||||
|         a = (FRAC_ONE / 2) - a; | ||||
|         a   = (FRAC_ONE / 2) - a; | ||||
|     } | ||||
|     p = cos_table + (a >> CSHIFT); | ||||
|     /* linear interpolation */ | ||||
| @@ -139,63 +139,63 @@ int main(int argc, char **argv) | ||||
|  | ||||
|     /* 1 second of single freq sinus at 1000 Hz */ | ||||
|     a = 0; | ||||
|     for(i=0;i<1 * sample_rate;i++) { | ||||
|     for (i = 0; i < 1 * sample_rate; i++) { | ||||
|         v = (int_cos(a) * 10000) >> FRAC_BITS; | ||||
|         for(j=0;j<nb_channels;j++) | ||||
|         for (j = 0; j < nb_channels; j++) | ||||
|             put_sample(v); | ||||
|         a += (1000 * FRAC_ONE) / sample_rate; | ||||
|     } | ||||
|  | ||||
|     /* 1 second of varing frequency between 100 and 10000 Hz */ | ||||
|     a = 0; | ||||
|     for(i=0;i<1 * sample_rate;i++) { | ||||
|     for (i = 0; i < 1 * sample_rate; i++) { | ||||
|         v = (int_cos(a) * 10000) >> FRAC_BITS; | ||||
|         for(j=0;j<nb_channels;j++) | ||||
|         for (j = 0; j < nb_channels; j++) | ||||
|             put_sample(v); | ||||
|         f = 100 + (((10000 - 100) * i) / sample_rate); | ||||
|         f  = 100 + (((10000 - 100) * i) / sample_rate); | ||||
|         a += (f * FRAC_ONE) / sample_rate; | ||||
|     } | ||||
|  | ||||
|     /* 0.5 second of low amplitude white noise */ | ||||
|     for(i=0;i<sample_rate / 2;i++) { | ||||
|     for (i = 0; i < sample_rate / 2; i++) { | ||||
|         v = myrnd(&seed, 20000) - 10000; | ||||
|         for(j=0;j<nb_channels;j++) | ||||
|         for (j = 0; j < nb_channels; j++) | ||||
|             put_sample(v); | ||||
|     } | ||||
|  | ||||
|     /* 0.5 second of high amplitude white noise */ | ||||
|     for(i=0;i<sample_rate / 2;i++) { | ||||
|     for (i = 0; i < sample_rate / 2; i++) { | ||||
|         v = myrnd(&seed, 65535) - 32768; | ||||
|         for(j=0;j<nb_channels;j++) | ||||
|         for (j = 0; j < nb_channels; j++) | ||||
|             put_sample(v); | ||||
|     } | ||||
|  | ||||
|     /* 1 second of unrelated ramps for each channel */ | ||||
|     for(j=0;j<nb_channels;j++) { | ||||
|         taba[j] = 0; | ||||
|     for (j = 0; j < nb_channels; j++) { | ||||
|         taba[j]  = 0; | ||||
|         tabf1[j] = 100 + myrnd(&seed, 5000); | ||||
|         tabf2[j] = 100 + myrnd(&seed, 5000); | ||||
|     } | ||||
|     for(i=0;i<1 * sample_rate;i++) { | ||||
|         for(j=0;j<nb_channels;j++) { | ||||
|     for (i = 0; i < 1 * sample_rate; i++) { | ||||
|         for (j = 0; j < nb_channels; j++) { | ||||
|             v = (int_cos(taba[j]) * 10000) >> FRAC_BITS; | ||||
|             put_sample(v); | ||||
|             f = tabf1[j] + (((tabf2[j] - tabf1[j]) * i) / sample_rate); | ||||
|             f        = tabf1[j] + (((tabf2[j] - tabf1[j]) * i) / sample_rate); | ||||
|             taba[j] += (f * FRAC_ONE) / sample_rate; | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     /* 2 seconds of 500 Hz with varying volume */ | ||||
|     a = 0; | ||||
|     a    = 0; | ||||
|     ampa = 0; | ||||
|     for(i=0;i<2 * sample_rate;i++) { | ||||
|         for(j=0;j<nb_channels;j++) { | ||||
|     for (i = 0; i < 2 * sample_rate; i++) { | ||||
|         for (j = 0; j < nb_channels; j++) { | ||||
|             amp = ((FRAC_ONE + int_cos(ampa)) * 5000) >> FRAC_BITS; | ||||
|             if (j & 1) | ||||
|                 amp = 10000 - amp; | ||||
|             v = (int_cos(a) * amp) >> FRAC_BITS; | ||||
|             put_sample(v); | ||||
|             a += (500 * FRAC_ONE) / sample_rate; | ||||
|             a    += (500 * FRAC_ONE) / sample_rate; | ||||
|             ampa += (2 * FRAC_ONE) / sample_rate; | ||||
|         } | ||||
|     } | ||||
|   | ||||
| @@ -27,18 +27,19 @@ int main(void) | ||||
|     static const char b64[] = | ||||
|         "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; | ||||
|     unsigned i_bits = 0; | ||||
|     int i_shift = 0; | ||||
|     int out_len = 0; | ||||
|     int i_shift     = 0; | ||||
|     int out_len     = 0; | ||||
|     int in; | ||||
|  | ||||
| #define putb64() do {                                   \ | ||||
| #define putb64()                                        \ | ||||
|     do {                                                \ | ||||
|         putchar(b64[(i_bits << 6 >> i_shift) & 0x3f]);  \ | ||||
|         out_len++;                                      \ | ||||
|         i_shift -= 6;                                   \ | ||||
|     } while (0) | ||||
|  | ||||
|     while ((in = getchar()) != EOF) { | ||||
|         i_bits = (i_bits << 8) + in; | ||||
|         i_bits   = (i_bits << 8) + in; | ||||
|         i_shift += 8; | ||||
|         while (i_shift > 6) | ||||
|             putb64(); | ||||
|   | ||||
							
								
								
									
										109
									
								
								tests/rotozoom.c
									
									
									
									
									
								
							
							
						
						
									
										109
									
								
								tests/rotozoom.c
									
									
									
									
									
								
							| @@ -25,7 +25,7 @@ | ||||
| #include <inttypes.h> | ||||
|  | ||||
| #define FIXP (1 << 16) | ||||
| #define MY_PI 205887 //(M_PI * FIX) | ||||
| #define MY_PI 205887 // (M_PI * FIX) | ||||
|  | ||||
| static int64_t int_pow(int64_t a, int p) | ||||
| { | ||||
| @@ -47,7 +47,7 @@ static int64_t int_sin(int64_t a) | ||||
|  | ||||
|     if (a >= MY_PI * 3 / 2) | ||||
|         a -= 2 * MY_PI; // -PI / 2 .. 3PI / 2 | ||||
|     if (a >= MY_PI /2) | ||||
|     if (a >= MY_PI / 2) | ||||
|         a = MY_PI - a;  // -PI / 2 ..  PI / 2 | ||||
|  | ||||
|     return a - int_pow(a, 3) / 6 + int_pow(a, 5) / 120 - int_pow(a, 7) / 5040; | ||||
| @@ -67,49 +67,49 @@ static void rgb24_to_yuv420p(unsigned char *lum, unsigned char *cb, | ||||
|  | ||||
|     wrap  = width; | ||||
|     wrap3 = width * 3; | ||||
|     p = src; | ||||
|     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; | ||||
|             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; | ||||
|             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[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++; | ||||
| @@ -171,7 +171,7 @@ static void put_pixel(int x, int y, int r, int g, int b) | ||||
|         y < 0 || y >= height) | ||||
|         return; | ||||
|  | ||||
|     p = rgb_tab + y * wrap + x * 3; | ||||
|     p    = rgb_tab + y * wrap + x * 3; | ||||
|     p[0] = r; | ||||
|     p[1] = g; | ||||
|     p[2] = b; | ||||
| @@ -181,8 +181,8 @@ 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]; | ||||
| int h_cos[360]; | ||||
| int h_sin[360]; | ||||
|  | ||||
| static int ipol(uint8_t *src, int x, int y) | ||||
| { | ||||
| @@ -202,8 +202,8 @@ static int ipol(uint8_t *src, int x, int y) | ||||
|  | ||||
| static void gen_image(int num, int w, int h) | ||||
| { | ||||
|     const int c = h_cos [num % 360]; | ||||
|     const int s = h_sin [num % 360]; | ||||
|     const int c = h_cos[num % 360]; | ||||
|     const int s = h_sin[num % 360]; | ||||
|  | ||||
|     const int xi = -(w / 2) * c; | ||||
|     const int yi =  (w / 2) * s; | ||||
| @@ -217,16 +217,19 @@ static void gen_image(int num, int w, int h) | ||||
|     int yprime = yj; | ||||
|  | ||||
|     for (j = 0; j < h; j++) { | ||||
|         x = xprime + xi + FIXP * w / 2; | ||||
|         x       = xprime + xi + FIXP * w / 2; | ||||
|         xprime += s; | ||||
|  | ||||
|         y = yprime + yi + FIXP * h / 2; | ||||
|         y       = yprime + yi + FIXP * h / 2; | ||||
|         yprime += c; | ||||
|  | ||||
|         for (i = 0; i < w; i++ ) { | ||||
|         for (i = 0; i < w; i++) { | ||||
|             x += c; | ||||
|             y -= s; | ||||
|             put_pixel(i, j, ipol(tab_r, x, y), ipol(tab_g, x, y), ipol(tab_b, x, y)); | ||||
|             put_pixel(i, j, | ||||
|                       ipol(tab_r, x, y), | ||||
|                       ipol(tab_g, x, y), | ||||
|                       ipol(tab_b, x, y)); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -264,13 +267,13 @@ static int init_demo(const char *filename) | ||||
|  | ||||
|     /* tables sin/cos */ | ||||
|     for (i = 0; i < 360; i++) { | ||||
|         radian = 2 * i * MY_PI / 360; | ||||
|         h      = 2 * FIXP + int_sin (radian); | ||||
|         radian   = 2 * i * MY_PI / 360; | ||||
|         h        = 2 * FIXP + int_sin(radian); | ||||
|         h_cos[i] = h * int_sin(radian + MY_PI / 2) / 2 / FIXP; | ||||
|         h_sin[i] = h * int_sin(radian)             / 2 / FIXP; | ||||
|     } | ||||
|  | ||||
|   return 0; | ||||
|     return 0; | ||||
| } | ||||
|  | ||||
| int main(int argc, char **argv) | ||||
|   | ||||
| @@ -24,32 +24,32 @@ | ||||
| #include <inttypes.h> | ||||
| #include <assert.h> | ||||
|  | ||||
| #define FFMIN(a,b) ((a) > (b) ? (b) : (a)) | ||||
| #define FFMIN(a, b) ((a) > (b) ? (b) : (a)) | ||||
| #define F 100 | ||||
| #define SIZE 2048 | ||||
|  | ||||
| uint64_t exp16_table[21]={ | ||||
|      65537, | ||||
|      65538, | ||||
|      65540, | ||||
|      65544, | ||||
|      65552, | ||||
|      65568, | ||||
|      65600, | ||||
|      65664, | ||||
|      65793, | ||||
|      66050, | ||||
|      66568, | ||||
|      67616, | ||||
|      69763, | ||||
|      74262, | ||||
|      84150, | ||||
|     108051, | ||||
|     178145, | ||||
|     484249, | ||||
|    3578144, | ||||
|  195360063, | ||||
|  582360139072LL, | ||||
| uint64_t exp16_table[21] = { | ||||
|            65537, | ||||
|            65538, | ||||
|            65540, | ||||
|            65544, | ||||
|            65552, | ||||
|            65568, | ||||
|            65600, | ||||
|            65664, | ||||
|            65793, | ||||
|            66050, | ||||
|            66568, | ||||
|            67616, | ||||
|            69763, | ||||
|            74262, | ||||
|            84150, | ||||
|           108051, | ||||
|           178145, | ||||
|           484249, | ||||
|          3578144, | ||||
|        195360063, | ||||
|     582360139072LL, | ||||
| }; | ||||
|  | ||||
| #if 0 | ||||
| @@ -68,63 +68,66 @@ static unsigned int exp16(unsigned int a){ | ||||
| #endif | ||||
|  | ||||
| // 16.16 fixpoint log() | ||||
| static int64_t log16(uint64_t a){ | ||||
| static int64_t log16(uint64_t a) | ||||
| { | ||||
|     int i; | ||||
|     int out=0; | ||||
|     int out = 0; | ||||
|  | ||||
|     if(a < 1<<16) | ||||
|         return -log16((1LL<<32) / a); | ||||
|     a<<=16; | ||||
|     if (a < 1 << 16) | ||||
|         return -log16((1LL << 32) / a); | ||||
|     a <<= 16; | ||||
|  | ||||
|     for(i=20;i>=0;i--){ | ||||
|         int64_t b= exp16_table[i]; | ||||
|         if(a<(b<<16)) continue; | ||||
|         out |= 1<<i; | ||||
|         a = ((a/b)<<16) + (((a%b)<<16) + b/2)/b; | ||||
|     for (i = 20; i >= 0; i--) { | ||||
|         int64_t b = exp16_table[i]; | ||||
|         if (a < (b << 16)) | ||||
|             continue; | ||||
|         out |= 1 << i; | ||||
|         a    = ((a / b) << 16) + (((a % b) << 16) + b / 2) / b; | ||||
|     } | ||||
|     return out; | ||||
| } | ||||
|  | ||||
| static uint64_t int_sqrt(uint64_t a) | ||||
| { | ||||
|     uint64_t ret=0; | ||||
|     uint64_t ret    = 0; | ||||
|     uint64_t ret_sq = 0; | ||||
|     int s; | ||||
|     uint64_t ret_sq=0; | ||||
|  | ||||
|     for(s=31; s>=0; s--){ | ||||
|         uint64_t b= ret_sq + (1ULL<<(s*2)) + (ret<<s)*2; | ||||
|         if(b<=a){ | ||||
|             ret_sq=b; | ||||
|             ret+= 1ULL<<s; | ||||
|     for (s = 31; s >= 0; s--) { | ||||
|         uint64_t b = ret_sq + (1ULL << (s * 2)) + (ret << s) * 2; | ||||
|         if (b <= a) { | ||||
|             ret_sq = b; | ||||
|             ret   += 1ULL << s; | ||||
|         } | ||||
|     } | ||||
|     return ret; | ||||
| } | ||||
|  | ||||
| int main(int argc,char* argv[]){ | ||||
| int main(int argc, char *argv[]) | ||||
| { | ||||
|     int i, j; | ||||
|     uint64_t sse=0; | ||||
|     uint64_t sse = 0; | ||||
|     uint64_t dev; | ||||
|     FILE *f[2]; | ||||
|     uint8_t buf[2][SIZE]; | ||||
|     uint64_t psnr; | ||||
|     int len= argc<4 ? 1 : atoi(argv[3]); | ||||
|     int64_t max= (1<<(8*len))-1; | ||||
|     int shift= argc<5 ? 0 : atoi(argv[4]); | ||||
|     int skip_bytes = argc<6 ? 0 : atoi(argv[5]); | ||||
|     int size0=0; | ||||
|     int size1=0; | ||||
|     int maxdist = 0; | ||||
|     int len        = argc < 4 ? 1 : atoi(argv[3]); | ||||
|     int64_t max    = (1 << (8 * len)) - 1; | ||||
|     int shift      = argc < 5 ? 0 : atoi(argv[4]); | ||||
|     int skip_bytes = argc < 6 ? 0 : atoi(argv[5]); | ||||
|     int size0      = 0; | ||||
|     int size1      = 0; | ||||
|     int maxdist    = 0; | ||||
|  | ||||
|     if(argc<3){ | ||||
|     if (argc < 3) { | ||||
|         printf("tiny_psnr <file1> <file2> [<elem size> [<shift> [<skip bytes>]]]\n"); | ||||
|         printf("WAV headers are skipped automatically.\n"); | ||||
|         return 1; | ||||
|     } | ||||
|  | ||||
|     f[0]= fopen(argv[1], "rb"); | ||||
|     f[1]= fopen(argv[2], "rb"); | ||||
|     if(!f[0] || !f[1]){ | ||||
|     f[0] = fopen(argv[1], "rb"); | ||||
|     f[1] = fopen(argv[2], "rb"); | ||||
|     if (!f[0] || !f[1]) { | ||||
|         fprintf(stderr, "Could not open input files.\n"); | ||||
|         return 1; | ||||
|     } | ||||
| @@ -133,12 +136,12 @@ int main(int argc,char* argv[]){ | ||||
|         uint8_t *p = buf[i]; | ||||
|         if (fread(p, 1, 12, f[i]) != 12) | ||||
|             return 1; | ||||
|         if (!memcmp(p,   "RIFF", 4) && | ||||
|             !memcmp(p+8, "WAVE", 4)) { | ||||
|         if (!memcmp(p, "RIFF", 4) && | ||||
|             !memcmp(p + 8, "WAVE", 4)) { | ||||
|             if (fread(p, 1, 8, f[i]) != 8) | ||||
|                 return 1; | ||||
|             while (memcmp(p, "data", 4)) { | ||||
|                 int s = p[4] | p[5]<<8 | p[6]<<16 | p[7]<<24; | ||||
|                 int s = p[4] | p[5] << 8 | p[6] << 16 | p[7] << 24; | ||||
|                 fseek(f[i], s, SEEK_CUR); | ||||
|                 if (fread(p, 1, 8, f[i]) != 8) | ||||
|                     return 1; | ||||
| @@ -148,47 +151,47 @@ int main(int argc,char* argv[]){ | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     fseek(f[shift<0], abs(shift), SEEK_CUR); | ||||
|     fseek(f[shift < 0], abs(shift), SEEK_CUR); | ||||
|  | ||||
|     fseek(f[0],skip_bytes,SEEK_CUR); | ||||
|     fseek(f[1],skip_bytes,SEEK_CUR); | ||||
|     fseek(f[0], skip_bytes, SEEK_CUR); | ||||
|     fseek(f[1], skip_bytes, SEEK_CUR); | ||||
|  | ||||
|     for(;;){ | ||||
|         int s0= fread(buf[0], 1, SIZE, f[0]); | ||||
|         int s1= fread(buf[1], 1, SIZE, f[1]); | ||||
|     for (;;) { | ||||
|         int s0 = fread(buf[0], 1, SIZE, f[0]); | ||||
|         int s1 = fread(buf[1], 1, SIZE, f[1]); | ||||
|  | ||||
|         for(j=0; j<FFMIN(s0,s1); j++){ | ||||
|             int64_t a= buf[0][j]; | ||||
|             int64_t b= buf[1][j]; | ||||
|         for (j = 0; j < FFMIN(s0, s1); j++) { | ||||
|             int64_t a = buf[0][j]; | ||||
|             int64_t b = buf[1][j]; | ||||
|             int dist; | ||||
|             if(len==2){ | ||||
|                 a= (int16_t)(a | (buf[0][++j]<<8)); | ||||
|                 b= (int16_t)(b | (buf[1][  j]<<8)); | ||||
|             if (len == 2) { | ||||
|                 a = (int16_t)(a | (buf[0][++j] << 8)); | ||||
|                 b = (int16_t)(b | (buf[1][  j] << 8)); | ||||
|             } | ||||
|             sse += (a-b) * (a-b); | ||||
|             dist = abs(a-b); | ||||
|             if (dist > maxdist) maxdist = dist; | ||||
|             sse += (a - b) * (a - b); | ||||
|             dist = abs(a - b); | ||||
|             if (dist > maxdist) | ||||
|                 maxdist = dist; | ||||
|         } | ||||
|         size0 += s0; | ||||
|         size1 += s1; | ||||
|         if(s0+s1<=0) | ||||
|         if (s0 + s1 <= 0) | ||||
|             break; | ||||
|     } | ||||
|  | ||||
|     i= FFMIN(size0,size1)/len; | ||||
|     if(!i) i=1; | ||||
|     dev= int_sqrt( ((sse/i)*F*F) + (((sse%i)*F*F) + i/2)/i ); | ||||
|     if(sse) | ||||
|         psnr= ((2*log16(max<<16) + log16(i) - log16(sse))*284619LL*F + (1LL<<31)) / (1LL<<32); | ||||
|     i = FFMIN(size0, size1) / len; | ||||
|     if (!i) | ||||
|         i = 1; | ||||
|     dev = int_sqrt(((sse / i) * F * F) + (((sse % i) * F * F) + i / 2) / i); | ||||
|     if (sse) | ||||
|         psnr = ((2 * log16(max << 16) + log16(i) - log16(sse)) * | ||||
|                 284619LL * F + (1LL << 31)) / (1LL << 32); | ||||
|     else | ||||
|         psnr= 1000*F-1; //floating point free infinity :) | ||||
|         psnr = 1000 * F - 1; // floating point free infinity :) | ||||
|  | ||||
|     printf("stddev:%5d.%02d PSNR:%3d.%02d MAXDIFF:%5d bytes:%9d/%9d\n", | ||||
|         (int)(dev/F), (int)(dev%F), | ||||
|         (int)(psnr/F), (int)(psnr%F), | ||||
|         maxdist, | ||||
|         size0, size1); | ||||
|            (int)(dev / F), (int)(dev % F), | ||||
|            (int)(psnr / F), (int)(psnr % F), | ||||
|            maxdist, size0, size1); | ||||
|     return 0; | ||||
| } | ||||
|  | ||||
|  | ||||
|   | ||||
							
								
								
									
										140
									
								
								tests/videogen.c
									
									
									
									
									
								
							
							
						
						
									
										140
									
								
								tests/videogen.c
									
									
									
									
									
								
							| @@ -27,67 +27,73 @@ | ||||
|  | ||||
| #define SCALEBITS 8 | ||||
| #define ONE_HALF  (1 << (SCALEBITS - 1)) | ||||
| #define FIX(x)    ((int) ((x) * (1L<<SCALEBITS) + 0.5)) | ||||
| #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) | ||||
|                              uint8_t *src, int width, int height) | ||||
| { | ||||
|     int wrap, wrap3, x, y; | ||||
|     int r, g, b, r1, g1, b1; | ||||
|     uint8_t *p; | ||||
|  | ||||
|     wrap = width; | ||||
|     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; | ||||
|     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; | ||||
|             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[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; | ||||
|             p   += -wrap3 + 2 * 3; | ||||
|             lum += -wrap + 2; | ||||
|         } | ||||
|         p += wrap3; | ||||
|         p   += wrap3; | ||||
|         lum += wrap; | ||||
|     } | ||||
| } | ||||
| @@ -106,19 +112,19 @@ static void pgmyuv_save(const char *filename, int w, int h, | ||||
|     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); | ||||
|     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"); | ||||
|     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++) { | ||||
|     for (i = 0; i < h2; i++) { | ||||
|         fwrite(cb, 1, w2, f); | ||||
|         fwrite(cr, 1, w2, f); | ||||
|         cb += w2; | ||||
| @@ -142,7 +148,7 @@ static void put_pixel(int x, int y, int r, int g, int b) | ||||
|         y < 0 || y >= height) | ||||
|         return; | ||||
|  | ||||
|     p = rgb_tab + y * wrap + x * 3; | ||||
|     p    = rgb_tab + y * wrap + x * 3; | ||||
|     p[0] = r; | ||||
|     p[1] = g; | ||||
|     p[2] = b; | ||||
| @@ -180,7 +186,7 @@ static int int_cos(int a) | ||||
|     neg = 0; | ||||
|     if (a > (FRAC_ONE / 4)) { | ||||
|         neg = -1; | ||||
|         a = (FRAC_ONE / 2) - a; | ||||
|         a   = (FRAC_ONE / 2) - a; | ||||
|     } | ||||
|     v = FRAC_ONE - ((a * a) >> 4); | ||||
|     v = (v ^ neg) - neg; | ||||
| @@ -204,7 +210,7 @@ static void gen_image(int num, int w, int h) | ||||
|     unsigned int seed1; | ||||
|  | ||||
|     if (num == 0) { | ||||
|         for(i=0;i<NB_OBJS;i++) { | ||||
|         for (i = 0; i < NB_OBJS; i++) { | ||||
|             objs[i].x = myrnd(&seed, w); | ||||
|             objs[i].y = myrnd(&seed, h); | ||||
|             objs[i].w = myrnd(&seed, w / 4) + 10; | ||||
| @@ -219,21 +225,21 @@ static void gen_image(int num, int w, int h) | ||||
|     /* test motion estimation */ | ||||
|     dx = int_cos(num * FRAC_ONE / 50) * 35; | ||||
|     dy = int_cos(num * FRAC_ONE / 50 + FRAC_ONE / 10) * 30; | ||||
|     for(y=0;y<h;y++) { | ||||
|         for(x=0;x<w;x++) { | ||||
|     for (y = 0; y < h; y++) { | ||||
|         for (x = 0; x < w; x++) { | ||||
|             x1 = (x << FRAC_BITS) + dx; | ||||
|             y1 = (y << FRAC_BITS) + dy; | ||||
|             r = ((y1 * 7) >> FRAC_BITS) & 0xff; | ||||
|             g = (((x1 + y1) * 9) >> FRAC_BITS) & 0xff; | ||||
|             b = ((x1 * 5) >> FRAC_BITS) & 0xff; | ||||
|             r  =       ((y1  * 7) >> FRAC_BITS) & 0xff; | ||||
|             g  = (((x1 + y1) * 9) >> FRAC_BITS) & 0xff; | ||||
|             b  =  ((x1       * 5) >> FRAC_BITS) & 0xff; | ||||
|             put_pixel(x, y, r, g, b); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     /* then some noise with very high intensity to test saturation */ | ||||
|     seed1 = num; | ||||
|     for(y=0;y<NOISE_W;y++) { | ||||
|         for(x=0;x<NOISE_W;x++) { | ||||
|     for (y = 0; y < NOISE_W; y++) { | ||||
|         for (x = 0; x < NOISE_W; x++) { | ||||
|             r = myrnd(&seed1, 256); | ||||
|             g = myrnd(&seed1, 256); | ||||
|             b = myrnd(&seed1, 256); | ||||
| @@ -242,11 +248,11 @@ static void gen_image(int num, int w, int h) | ||||
|     } | ||||
|  | ||||
|     /* then moving objects */ | ||||
|     for(i=0;i<NB_OBJS;i++) { | ||||
|     for (i = 0; i < NB_OBJS; i++) { | ||||
|         VObj *p = &objs[i]; | ||||
|         seed1 = i; | ||||
|         for(y=0;y<p->h;y++) { | ||||
|             for(x=0;x<p->w;x++) { | ||||
|         for (y = 0; y < p->h; y++) { | ||||
|             for (x = 0; x < p->w; x++) { | ||||
|                 r = p->r; | ||||
|                 g = p->g; | ||||
|                 b = p->b; | ||||
| @@ -277,11 +283,11 @@ int main(int argc, char **argv) | ||||
|     h = DEFAULT_HEIGHT; | ||||
|  | ||||
|     rgb_tab = malloc(w * h * 3); | ||||
|     wrap = w * 3; | ||||
|     width = w; | ||||
|     height = h; | ||||
|     wrap    = w * 3; | ||||
|     width   = w; | ||||
|     height  = h; | ||||
|  | ||||
|     for(i=0;i<DEFAULT_NB_PICT;i++) { | ||||
|     for (i = 0; i < DEFAULT_NB_PICT; i++) { | ||||
|         snprintf(buf, sizeof(buf), "%s%02d.pgm", argv[1], i); | ||||
|         gen_image(i, w, h); | ||||
|         pgmyuv_save(buf, w, h, rgb_tab); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user