+ Reply to Thread
Page 2 of 2 FirstFirst 12
Results 11 to 20 of 20

Thread: Help with C# file output compression.

  1. #11
    Wirererer Josef's Avatar
    Join Date
    Dec 2007
    Posts
    159

    Default Re: Help with C# file output compression.

    You'd really want some sort of run-length encoding in order to achieve your goal. Run-length encoding would be like looking ahead at all your pixels for groups that are identical and then saving the color information once, along with a little extra info telling how many times in a row to repeat that color. For large areas of uniform color the space savings can be tremendous, but for random or photograph-quality pictures this method usually does not save any space, and could potentially increase the size.

    Alternatively, if you converted your colors into a binary stream and then broke that into 7-bit lengths and used the ASCII printable characters, you could store 7 bits for every byte of text, giving you nearly ideal usage of space (7:8), but a 256x256 image would still take up 225KB. The best you could hope for is 170x170.
    Last edited by Josef; 01-29-2010 at 02:06 PM.

  2. #12
    Wirererer Josef's Avatar
    Join Date
    Dec 2007
    Posts
    159

    Default Re: Help with C# file output compression.

    Quote Originally Posted by Drunkie View Post
    I'll have to try that next, but my main goal was to make it work universally with any jpeg or bitmap, you just import the pic, select your resolution size, and it makes a compatible E2 file.
    Or how about an E2 that reads JPEGs natively? 100KB of jpeg can go a long way. I might even try my hand at this one day. I've got it mostly figured out already. Would require significant decompression time in the E2 though...

  3. #13
    Developer Matte's Avatar
    Join Date
    Jan 2009
    Location
    Norway
    Posts
    3,109

    Default Re: Help with C# file output compression.

    What about compressing the colors by using one hex digit or one base 32 digit for each component of the pixel?
    "If anybody says he can think about quantum physics without getting giddy, that only shows he has not understood the first thing about them."
    -- Niels Bohr

  4. #14
    Wire Sofaking N00bDud3's Avatar
    Join Date
    Jul 2009
    Location
    Error: Unknown Location
    Posts
    1,252

    Default Re: Help with C# file output compression.

    Maybe you could try saving it as multiple files, like "Image01", "Image02", etc. and then check the list of files for "Image*.txt" and load each of them, then when you read and reach the end of one, jump to the next.



  5. #15
    Ursus maritimus Drunkie's Avatar
    Join Date
    Feb 2009
    Location
    Canada
    Posts
    5,662
    Blog Entries
    1

    Default Re: Help with C# file output compression.

    Okay using hex, I can get pictures up to 112x112, and they end up being 99kb. I'm going to try some of the other methods suggested but I really think this is as good as its gonna get. If I really need a hi-resolution picture I'll have to convert this to use the CPU.
    Here's the quality so far:





    Last edited by Drunkie; 01-30-2010 at 11:37 AM.

  6. #16
    That furred thing Black Phoenix's Avatar
    Join Date
    Feb 2007
    Location
    Kyiv, Ukraine
    Posts
    3,565

    Default Re: Help with C# file output compression.

    Quote Originally Posted by Drunkie View Post
    I'll have to try that next, but my main goal was to make it work universally with any jpeg or bitmap, you just import the pic, select your resolution size, and it makes a compatible E2 file.
    It works very good, you can replace very similar colors with one; generally reducing image quality just a tiny bit, but receiving huge compression. You can have 1296 colors in your picture, and use just TWO letters per every entry! Maybe you can fit even more in there; 1296 colors is already enough for most pictures.
    I'm a wire-crazy person with a tail.

    Take a daily journey into my brain

    D2K5

  7. #17
    Expressionism 2.0 Syranide's Avatar
    Join Date
    Mar 2007
    Location
    Sweden
    Posts
    4,573

    Default Re: Help with C# file output compression.

    It should otherwise be fairly simple to implement a huffman-encoding/decoding (but instead of on bits, on characters... hex even). Should allow you to considerably cut the size of the files. I realize palettes are far easier, but it would perform worse than RAW for "real" images.

  8. #18
    Ursus maritimus Drunkie's Avatar
    Join Date
    Feb 2009
    Location
    Canada
    Posts
    5,662
    Blog Entries
    1

    Default Re: Help with C# file output compression.

    So far I'm stuck on hex along with a separating character ';', which allows at the most, a 120x120 resolution picture and equals 99KB.

    Quote Originally Posted by N00bDud3 View Post
    Maybe you could try saving it as multiple files, like "Image01", "Image02", etc. and then check the list of files for "Image*.txt" and load each of them, then when you read and reach the end of one, jump to the next.
    I'm really against loading multiple files, I don't know, something about it seems redundant.

    Quote Originally Posted by Josef View Post
    You'd really want some sort of run-length encoding in order to achieve your goal. Run-length encoding would be like looking ahead at all your pixels for groups that are identical and then saving the color information once, along with a little extra info telling how many times in a row to repeat that color. For large areas of uniform color the space savings can be tremendous, but for random or photograph-quality pictures this method usually does not save any space, and could potentially increase the size.

    Alternatively, if you converted your colors into a binary stream and then broke that into 7-bit lengths and used the ASCII printable characters, you could store 7 bits for every byte of text, giving you nearly ideal usage of space (7:8), but a 256x256 image would still take up 225KB. The best you could hope for is 170x170.
    I totally understand the run-length coding; finding similar groups of pixels and having something define its amount to reduce repetitiveness. But that wont be very efficient for dynamic pictures. As for your second suggestion, the binary stream part, can you explain to me a bit more about it, I don't understand. Thanks.
    Last edited by Drunkie; 01-29-2010 at 10:00 PM.

  9. #19
    GUN
    GUN is offline
    Wire Sofaking GUN's Avatar
    Join Date
    Jan 2008
    Location
    California
    Posts
    668

    Default Re: Help with C# file output compression.

    use more than one text file? when the e2 is done loading the first file, itl start transferring the data to the screen while it starts to load the next file, its probably not how you would want it, but it works.


    edit; ignore this post, didn't see page 2, was replying to page 1.

    Maybe we're all gonna die, but we're gonna die in *really cool ways*.





  10. #20
    Ursus maritimus Drunkie's Avatar
    Join Date
    Feb 2009
    Location
    Canada
    Posts
    5,662
    Blog Entries
    1

    Default Re: Help with C# file output compression.

    Yeah I think I'm gonna break the files into 64kb segments, its the only way to do it I guess.
    64kb instead of 100, because 100kb upload hangs the server for 2-3 seconds.

+ Reply to Thread
Page 2 of 2 FirstFirst 12

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
proceed-collector
proceed-collector
proceed-collector
proceed-collector
linguistic-parrots
linguistic-parrots
linguistic-parrots
linguistic-parrots