last day (16 days later) » 

5:28 PM
2
A: Reading image data from a JFIF?

user3344003What you are trying to do is not a simple afternoon project. This book explains the process: There is A LOT of code between JPEG compressed data and pixel values. http://www.amazon.com/Compressed-Image-File-Formats-JPEG/dp/0201604434/ref=pd_bxgy_b_img_y First of all, you have to deal with two s...

 
Thank you very much!
 
This is not to discourage you but rather to set your expectations about the scope of the project. When I did what you are going many years ago, people sad not to even try. Just use a library. Then you don't learn anything and JPEG remains a black art.
 
Exactly! I'm glad somebody gets it! Also, I'm probably going to extensively read this: w3.org/Graphics/JPEG/itu-t81.pdf As it would probably guide me through the whole thing.
 
Kinda, sorta. The JPEG standard is not implementable. It lacks key details. It also includes so many ways to to things that it would be impossible to implement. Only sequential and progressive JPEG is commonly used (lossless is used in some 12-bit medical applications). You can ignore large parts of the standard. If I remember, the details on huffman coding are quite good. After learning to read all the different blocks, huffman coding is a good place to start next. That's Annex C. Ignore anything related to Hierarchical and arithmetic coding.
 
So I've already read all the blocks I need to (I think, I've read the SOI: color depth, image height/width, and number of components), so I can just start learning how to decode the huffman codes from the file? @user3344003
 
5:28 PM
You need the DHT and DQT blocks for a full decode. DHT is the huffman table. Annex C explains how to take the data in the DHT block and build a huffman table from that. Book books above show how to huffman decode.
 
I purchased the data compression book you linked! Thank you for all the help, I really needed it! @user3344003
Hey, I've come pretty far (and that first book you linked helped quite a bit), but I still have some questions, can I chat with you? @user3344003
 
Ask away. Also, there is some relatively easy to follow source code at colosseumbuilders.com/sourcecode
 
(I'm going to comment until it lets me start a chat.) So, I've got all the huffman table data, and organized my code much better than how it originally was. I have two arrays, huffCodeCounts[][], which holds the code counts for a table, and huffTables[][], which hold the actual tables. Each array has been filled with the correct data. However, I am a bit confused on what to do next; I know you're supposed to decode the tables, but what does that mean?
I've also made a function for the IDCT, so I've got that out of the way too.
I'm just having a hard time following the book section on the decoding process, and I'm stuck. I really need to get over this hump.
 
You should just use sequential jpeg images for now. Start by calculating the number MCUs needed for each component. That comes from the image size and sampling factors for the components. Next you're going to need to do huffman decoding. You need to be able to read the DHT markers and be able to build the table. If you have the counts, the standard tells you how to build the table from that. Counts gives the length of the huffman code for a value. The table will contain a bit sequence for each value. You're going to need code to read the compressed data stream in bits.
 
That's what I'm starting with. So now, I've got the number of MCUs needed for each component (I'm actually making progress! :D), and I've started the procedure to decode MCUs within a scan. However, when the book reads "Decode Data Unit" within the function, what does that mean? What do I pass to a theoretical function decode()? @user3344003
And I've also figured how large each data unit is, so my only problem is figuring out how to go about decoding each data unit. I know it comprises several functions, but I don't know how to start.
I have the counts and the values from the DHT markers, and have all the value tables with their corresponding index/types. I've read the standard and the book, but I still don't know how to make tables from this data? I see the decoding function in the book, but I don't understand the global variables VALUES[], MINCODE[], MAXCODE[], and FIRSTDATA[]. @user3344003
 
5:28 PM
Mincode and Maxcode are what you use to decode. MinCode [I] is the smallest Huffman Code of length I. MaxCode [i] is the largest huffman code of length I.
 
How do you get a huffman code from counts and values, though? And what are Values[] and Firstdata[]? I'm sorry I'm bombarding you with questions, I have scoured everywhere for good source code that matches my project structure and I haven't found any that isn't in C or matlab. I just really need someone to talk to and walk me through this and tell me the steps I need to take. @user3344003
Okay, I finally figured out how to get the actual code tables. I'm having a little trouble making my CountsToLengths function (I know LENGTHCOUNTS is the counts, but why is it [1..MAXIMUMLENGTH]? I thought counts just had 16 bytes?) I don't understand that, but the rest of it is fine. @user3344003
 
The codes can be up to 16 bits long. So its [1 .. 16]. Sadly, C/C++ do not allow array indices to start at 1.
 
So, say my counts are 0 2 1 3 3 2 4 3 5 5 4 4 0 0 1 125. When I run my function countsToLengths (from the book), I get an out of bounds exception. @user3344003
 
That's quite helpful, but I'm using Algorithm 6.3 on page 71:
}
private void countsToLengths(int[] counts,
int maxLength,
int[] codeLengths) {
int index = 0;
for(int i = 0; i < maxLength; i++) {
for(int j = 0; j < counts[i]; j++) {
codeLengths[index] = i;
index++;
}
}
}
er formatted
private void countsToLengths(int[] counts,
                            int maxLength,
                            int[] codeLengths) {
    int index = 0;
    for(int i = 0; i < maxLength; i++) {
        for(int j = 0; j < counts[i]; j++) {
            codeLengths[index] = i;
            index++;
        }
    }
}
And this is how I get counts[] and maxLength:
        // get codes from 1-16
        System.out.print(" Code Counts: ");
        for(int i = 0; i < 16; i++) {
            this.huffCodeCounts[n][i] = this.data[tOffset+1+i];
            System.out.print(this.huffCodeCounts[n][i] + " ");
            tValueCount += this.data[tOffset+1+i];
        }

        // get max count length
        List c = Arrays.asList(ArrayUtils.toObject(this.huffCodeCounts[n]));
        int maxLength = (int) Collections.max(c);

        // turn code counts to lengths
n is just which table is being processed.
 
 
3 hours later…
8:03 PM
@user3344003
 

  last day (16 days later) »