Note that there are some explanatory texts on larger screens.

plurals
  1. PORLE: encode by two symbols
    text
    copied!<p>I've created RLE encoding function, which encodes sequences like "A1A1B7B7B7B7" to such strings: "#A12#B74".</p> <pre><code> void encode(const char *input_path, const char *output_path) { // Begin of SBDLib::SBIMask::encode std::fstream input(input_path, std::ios_base::in | std::ios_base::binary); std::fstream output(output_path, std::ios_base::out | std::ios_base::binary); int size = 0; // Set size variable input.seekg(0, std::ios::end); // Move to EOF size = input.tellg(); // Tell position input.seekg(0); // Move to the beginning int i = 1; // Create encoding counter int counter = 0; // Create color counter int cbyte1, cbyte2; // Create current color bytes int pbyte1 = 0x0; int pbyte2 = 0x0; // Create previous color bytes while (((cbyte1 = input.get()) != EOF &amp;&amp; (cbyte2 = input.get()) != EOF) || input.tellg() &gt;= size) { // Begin of while // If current bytes are not equal to previous bytes // or cursor is at the end of the input file, write // binary data to file; don't do it if previous bytes // were not set from 0x0 to any other integer. if (((cbyte1 != pbyte1 || cbyte2 != pbyte2) || (input.tellg() == size)) &amp;&amp; (pbyte1 != 0x0 &amp;&amp; pbyte2 != 0x0)) { // Begin of main if output &lt;&lt; SEPARATOR; // Write separator to file output.write(reinterpret_cast&lt;const char*&gt;(&amp;pbyte1), 1); output.write(reinterpret_cast&lt;const char*&gt;(&amp;pbyte2), 1); output &lt;&lt; std::hex &lt;&lt; counter; // Write separator, bytes and count counter = 1; // Reset counter } // End of main if else counter++; // Increment counter pbyte1 = cbyte1; pbyte2 = cbyte2; // Set previous bytes } // End of main while } // End of encode </code></pre> <p>However, function is not as fast as I need. This is the second version of function, I've already improved it to make it faster, but it is still too slow. Do you have any ideas how to improve? I'm lack of ideas.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload