+ Reply to Thread
Page 1 of 5 123 ... LastLast
Results 1 to 10 of 43

Thread: JPEG Image Decoder (E2)

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

    Lightbulb JPEG Image Decoder (E2)

    After seeing the Images Painter (link) posted a few weeks ago, I was inspired to try and top it. I had already explored the JPEG compression scheme in my other post (link) so putting those fundamentals into a working JPEG decoder seemed like the next step.

    After a few days of exploring the JPEG file format using a hex editor and an incredibly useful tool called JPEG Snoop, I created an E2 that can load and decode real JPEG files to a digital screen.

    Some limitations exist. It can only decode baseline-encoded JPEGs, not progressive-encoded. It is limited to images under 100KB due to the E2 file load restrictions. There is no hard-coded resolution limit to the source image, but the digital screen will max out at 512x512. If you compress a large JPEG enough to be under 100KB, it will load and scale to the screen size properly, though in practice resizing the image in an external program such as Irfanview first so that it's at most 512 pixels per side is better since it will decode faster and look nicer too (I did not implement any smart downsizing).

    It will handle 2x2 chroma subsampling as well as non-subsampled JPEGs. I spent a lot of time optimizing the image generation stage for Ops, resulting in up to a 3x increase in draw speed from my first working prototype. The Ops it uses is self-limiting and adjustable from 1000 to 75000, and defaults to 5000 to be friendly on quotas. You can change the value on the fly using chat commands.

    Here are some sample images I've decoded:

    JPEG Image Decoder (E2)-.jpg JPEG Image Decoder (E2)-.jpg JPEG Image Decoder (E2)-.jpg

    Here's a video showing it decoding the Facepunch logo. The JPEG file was saved from a 256x256 pixel PNG source image with Quality 100 and is 35KB. I set the Ops in this example to 25000 so the decode would only take 47 seconds. At its normal speed (5000 Ops) this file takes about 4 minutes to decode:




    Usage:

    Download the zip file and extract the contents to your Garrysmod\data folder. It contains the Adv. Dupe file, the expression and some sample images (logo.jpg and logosmall.jpg), along with a batchfile script and hex editor that's needed to convert the binary JPEGs into text file data readable by the fileLoad function.

    To add your own custom JPEG images, save them to your Garrysmod\data\e2files folder and then run the batchfile _jpegfix.bat. This will create a .txt file slightly larger than the original image, so to ensure it loads successfully make sure your source image is about 98KB or less.

    Spawn the Adv. Dupe file and then control the image generation using chat commands:
    !load (filename): You can include the original .jpg extension, the .txt extension, or omit the extension altogether
    !stop: Abort the image generation in any stage after the initial file load
    !redo: Reload the last file name and process the image again
    !ops ####: Set the MaxOps limit to a desired value, between 1000 and 75000
    !ops: Display the current MaxOps limit (default is 5000)
    !debug #: Set the debugging level from 0 to 3 (0=stage change notifications only, 1=some debugging info, 2=Quantization & Huffman tables, 3=Detailed block analysis)
    !debug: Display the current debugging level (default is 0)


    Zip File:

    jpeg decoder.zip
    Last edited by Josef; 05-25-2010 at 07:11 PM. Reason: updated attachment

  2. #2
    I think I think too much -HP-'s Avatar
    Join Date
    Feb 2009
    Location
    Behind you with a very sharp knife.
    Posts
    2,466

    Default Re: JPEG Image Decoder (E2)

    You win at garrys mod.
    I'm speechless...

  3. #3
    Wire Sofaking ktccd's Avatar
    Join Date
    Sep 2009
    Posts
    751

    Default Re: JPEG Image Decoder (E2)

    Well I'm not! THIS IS AWESOME!

    Here you go fine sir, one internet.

  4. #4
    No u Divran's Avatar
    Join Date
    Jul 2008
    Location
    Sweden
    Posts
    4,582

    Default Re: JPEG Image Decoder (E2)

    o.O
    SVN Tutorial
    My SVN:
    Code:
    http://divranspack.googlecode.com/svn/trunk/%20divranspack/
    Get dropbox and get 250 MB extra space: Dropbox

  5. #5
    Master of Mars Magos Mechanicus's Avatar
    Join Date
    May 2008
    Posts
    852

    Default Re: JPEG Image Decoder (E2)

    I can wire anything directly into anything! I'm the Professor!
    -Professor Hubert Farnsworth

  6. #6
    Wire Sofaking vexx21322's Avatar
    Join Date
    Dec 2008
    Location
    Co, united states
    Posts
    424

    Default Re: JPEG Image Decoder (E2)

    Mind = blown

    Have you checked HERE first?

  7. #7
    Wire Amateur Moglizorz's Avatar
    Join Date
    Sep 2008
    Posts
    92

    Default Re: JPEG Image Decoder (E2)

    I seem to get the same error whenever I use a jpg that I saved with photoshop;
    Decoding at largest known length (0) failed to find Huffman code:0 in table. T:2.8146924848976e+014 TL:43 LastST:0
    I've tried Baseline Standard, and optimised. Tried max and lower qualities, and tried with and without the profile option, yet the same error. Any ideas?
    I can make you hate me with five words:
    "I made Balls of Steel".

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

    Default Re: JPEG Image Decoder (E2)

    I'm amazed o.o

    Very nice!
    "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

  9. #9
    Wire Amateur Moglizorz's Avatar
    Join Date
    Sep 2008
    Posts
    92

    Default Re: JPEG Image Decoder (E2)

    Quote Originally Posted by Moglizorz View Post
    I seem to get the same error whenever I use a jpg that I saved with photoshop;

    I've tried Baseline Standard, and optimised. Tried max and lower qualities, and tried with and without the profile option, yet the same error. Any ideas?
    A little workaround to my problem; in photoshop do merge your layers and rasterize them, then do control+A to highlight all. Open up Paint, paste, save as jpeg.
    I can make you hate me with five words:
    "I made Balls of Steel".

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

    Default Re: JPEG Image Decoder (E2)

    I never said it was perfect . That error indicates that not all the Huffman tables were decoded properly. It's possible that Photoshop optimized the image too much by putting them where they weren't expected. Try doing "Save for web", or like you already suggested, copy the image into another editing program and resave it.

+ Reply to Thread
Page 1 of 5 123 ... LastLast

Tags for this Thread

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