GithubHelp home page GithubHelp logo

pg1003 / brle Goto Github PK

View Code? Open in Web Editor NEW
12.0 1.0 0.0 109 KB

A C++ library to compress or expand binary data using Run-Length Encoding

License: MIT License

Makefile 8.74% C++ 91.26%
rle compression rle-compression-algorithm data-compression run-length-encoding run-length-decoding binary-run-length-encoding brle-utility cpp brle

brle's People

Contributors

pg1003 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

brle's Issues

Does not work in one example

Hello.

I've found an example of data, when encode-decode round trip does not give the identical result. It consists of four bytes: 0x00, 0x00, 0x80, 0x40.

The patch to add this test case is:

diff --git a/tests/test.cpp b/tests/test.cpp
index 078a6d4..bc35c4f 100644
--- a/tests/test.cpp
+++ b/tests/test.cpp
@@ -52,6 +52,7 @@ static void encode_decode_uint8()
     const uint8_t literalszeros[] = { 0x55, 0x00 };
     const uint8_t literalsones[]  = { 0xAA, 0xFF };
     const uint8_t mixed[]         = { 0xAA, 0xAA, 0xAA, 0xAA, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x
FF, 0xAA, 0x00 };
+    const uint8_t weird[]         = { 0x00, 0x00, 0x80, 0x40 };

     assert_true( roundtrip( zeros, 0xFFu ) );
     assert_true( roundtrip( ones ) );
@@ -63,6 +64,7 @@ static void encode_decode_uint8()
     assert_true( roundtrip( literalszeros ) );
     assert_true( roundtrip( literalsones ) );
     assert_true( roundtrip( mixed ) );
+    assert_true( roundtrip( weird ) );
 }

 static void encode_decode_uint16()

The test program then produces this result:

> ./obj/test
check failed! (file tests/test.cpp, line 67): roundtrip( weird )
Total tests: 45, Tests failed: 1

It was possible to fix this with the following change:

diff --git a/src/brle.h b/src/brle.h
index 70f7b83..e4391ba 100644
--- a/src/brle.h
+++ b/src/brle.h
@@ -409,6 +409,10 @@ constexpr auto decode( InputIt input, InputIt last, OutputIt output ) -> OutputI
             bit_count = bit_count - data_bits;
             bits      = in >> ( detail::literal_size - bit_count );
         }
+
+        if( bit_count == 0) {
+            bits = 0;
+        }
     }

     return output;

But I am not completely sure if this is a correct approach.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.