Skip to content

Commit 43d75a7

Browse files
committed
Merge remote-tracking branch 'refs/remotes/origin/master'
2 parents 5cf8cd9 + c2e1161 commit 43d75a7

2 files changed

Lines changed: 47 additions & 2 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ You can use [probabilitytree.h](probabilitytree.h) to encode symbols. For insta
110110

111111
![Optimal](https://github.com/user-attachments/assets/d2315457-68a6-460e-aaa2-73ba25c0b0aa)
112112

113+
## TODO
114+
* Make a variant which uses no data if probability is 0 or 255.
113115

114116
## Special Thanks
115117

vpxcoding.h

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,56 @@
1818
* 3. Changed vpx_norm to be configurable (For low-flash situations)
1919
* 4. Removed endian-specific code, and just iterated directly.
2020
*
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>
2227
2328
#define VPXCODING_READER
2429
#define VPXCODING_WRITER
30+
#define VPXCODING_NOTABLE
2531
#include "vpxcoding.h"
2632
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+
}
2871
2972
*/
3073

0 commit comments

Comments
 (0)