|
18 | 18 | * 3. Changed vpx_norm to be configurable (For low-flash situations) |
19 | 19 | * 4. Removed endian-specific code, and just iterated directly. |
20 | 20 | * |
21 | | - * To Use: |
| 21 | + * For embedded use, you can define VPX_64BIT or VPX_32BIT. |
| 22 | + * |
| 23 | + * Minimal example application: |
| 24 | +
|
| 25 | +#include <stdlib.h> |
| 26 | +#include <stdio.h> |
22 | 27 |
|
23 | 28 | #define VPXCODING_READER |
24 | 29 | #define VPXCODING_WRITER |
| 30 | +#define VPXCODING_NOTABLE |
25 | 31 | #include "vpxcoding.h" |
26 | 32 |
|
27 | | - * For embedded use, you can define VPX_64BIT or VPX_32BIT. |
| 33 | +#define NELEM 1000000 |
| 34 | +
|
| 35 | +int data_to_compress[NELEM]; |
| 36 | +uint8_t compressed_data[NELEM]; |
| 37 | +
|
| 38 | +// Stored as individual 1's and 0's for clarity. |
| 39 | +uint8_t compressed_bitstream[NELEM*16]; |
| 40 | +
|
| 41 | +int main() |
| 42 | +{ |
| 43 | + int i, j, k; |
| 44 | +
|
| 45 | + // Generate a string of 0's and 1's, but mostly 0's |
| 46 | + for( i = 0; i < NELEM; i++ ) |
| 47 | + data_to_compress[i] = ((rand()%12)==0) ? 1 : 0; |
| 48 | +
|
| 49 | + int probability_of_0 = 256 - (int)( 1.0 * 255.0 / 12.0 ); |
| 50 | +
|
| 51 | + vpx_writer w; |
| 52 | + vpx_start_encode( &w, compressed_data, sizeof(compressed_data) ); |
| 53 | + for( i = 0; i < NELEM; i++ ) |
| 54 | + vpx_write( &w, data_to_compress[i], probability_of_0 ); |
| 55 | + vpx_stop_encode( &w ); |
| 56 | +
|
| 57 | + int encode_length = w.pos; |
| 58 | + printf( "Compressed size: %d\n", encode_length ); |
| 59 | +
|
| 60 | + vpx_reader r; |
| 61 | + vpx_reader_init( &r, compressed_data, encode_length, 0, 0 ); |
| 62 | + for( i = 0; i < NELEM; i++ ) |
| 63 | + if( data_to_compress[i] != vpx_read( &r, probability_of_0 ) ) |
| 64 | + printf( "Compression failed\n" ); |
| 65 | + // No need to cleanup. |
| 66 | +
|
| 67 | + printf( "Done\n" ); |
| 68 | +
|
| 69 | + return 0; |
| 70 | +} |
28 | 71 |
|
29 | 72 | */ |
30 | 73 |
|
|
0 commit comments