You win at garrys mod.
I'm speechless...
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:
![]()
![]()
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
You win at garrys mod.
I'm speechless...
Well I'm not! THIS IS AWESOME!
Here you go fine sir, one internet.
o.O
SVN Tutorial
My SVN:Get dropbox and get 250 MB extra space: DropboxCode:http://divranspack.googlecode.com/svn/trunk/%20divranspack/
I can wire anything directly into anything! I'm the Professor!
-Professor Hubert Farnsworth
Mind = blown
![]()
Have you checked HERE first?
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?Decoding at largest known length (0) failed to find Huffman code:0 in table. T:2.8146924848976e+014 TL:43 LastST:0
I can make you hate me with five words:
"I made Balls of Steel".
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
I can make you hate me with five words:
"I made Balls of Steel".
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.
Bookmarks