Jump to content

Welcome to Geeks to Go - Register now for FREE

Need help with your computer or device? Want to learn new tech skills? You're in the right place!
Geeks to Go is a friendly community of tech experts who can solve any problem you have. Just create a free account and post your question. Our volunteers will reply quickly and guide you through the steps. Don't let tech troubles stop you. Join Geeks to Go now and get the support you need!

How it Works Create Account
Photo

JFIF Image class - Java


  • Please log in to reply

#76
staticVoid

staticVoid

    Member

  • Topic Starter
  • Member
  • PipPip
  • 94 posts
the while loop is causing an out of bounds exceptions when I try to add the values to HUFFSIZE

would the for loop not be ok - I thought the length of HUFFSIZE and BITS were the same?

Question:

If someone were to ask you to write a program that displays a JPEG image without any resizing functions etc.(Just basic) how long would it take you?

Edited by staticVoid, 14 September 2007 - 11:47 AM.

  • 0

Advertisements


#77
bdlt

bdlt

    Member

  • Member
  • PipPipPip
  • 876 posts
I would be happy to look at the while loop code … please post it.

It would take me several weeks to do any kind of project. My ‘fun’ schedule is limited to a couple of hours on Wed and a couple more on Sun. You, however, are making great progress on your own, with a suggestion or 2 from afar.

Status – you are almost done with the ‘spec’ code. Congrats!

Huffman decoding is all custom code. It is the biggest challenge and the most fun.

I will try to lead you through the huffman steps. If you understand the requirements, then you will be able to write and debug the code. The idea is to teach you how to fish, not do the fishing for you. So far, you are doing the fishing.
  • 0

#78
staticVoid

staticVoid

    Member

  • Topic Starter
  • Member
  • PipPip
  • 94 posts
Ill post the source again so that you can test it:

Attached File  jpg.zip   1.77KB   234 downloads

int K = 0;
					 int I = 1; 
					 int J = 1;


					 while(I <= 16) {

						if(J > BITS[I]) {
						   I++;
						   J = 1;
						}

						else {
						   HUFFSIZE[K] = I;
						   K++;
						   J++;
						}

					 }

					 HUFFSIZE[K] = 0;

  • 0

#79
bdlt

bdlt

    Member

  • Member
  • PipPipPip
  • 876 posts
won't be able to run it while on travel - the travel pc is not mine and is not set up to run java.

looking at the code ... make sure that BITS is filled 1..16, not 0..15(size must be 17)
  • 0

#80
staticVoid

staticVoid

    Member

  • Topic Starter
  • Member
  • PipPip
  • 94 posts
what size should I make the HUFFSIZE array - when I was getting the out of bounds exception the length was 17 but I saw another source code on the web and the size was 257? , It works with 257
  • 0

#81
bdlt

bdlt

    Member

  • Member
  • PipPipPip
  • 876 posts
good job. I believe that 257 is the correct maximum size.

if you want to experiment, try setting the size to the number of values found in the header + 1.

For example, when BITS looks like
0, 2, 1, 3, 3, 2, 4, 3, 5, 5, 4, 4, 0, 0, 1, 125

then the size would be 163(2 + 1 + 3 … + 125 and one more for HUFFSIZE(K)= 0)
  • 0

#82
staticVoid

staticVoid

    Member

  • Topic Starter
  • Member
  • PipPip
  • 94 posts
I understand all the tables now but I think HUFFSIZE is incorrect:

BITS
------

0, 2, 1, 2, 4, 4, 3, 4, 7, 5, 4, 4, 0, 1, 2, 119,
-----------------------




HUFFVAL
-------

 , ☺, ☻, ♥, ◄, ♦, ♣, !, 1, ♠, ↕, A, Q, , a, q, ‼, ", 2, ?,, ¶, B, ?, í, ▒, ┴,
, #, 3, R, ­, §, b, r, Ð,
, ▬, $, 4, ß, %, ±, ↨, ↑, ↓, →, &, ', (, ), *, 5, 6, 7, 8, 9, :, C, D, E, F, G,
H, I, J, S, T, U, V, W, X, Y, Z, c, d, e, f, g, h, i, j, s, t, u, v, w, x, y, z,
 ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ó, ú, ñ, Ñ, ª, º, ¿, ®, ¬
, ▓, │, ┤, Á, Â, À, ©, ╣, ║, ┬, ├, ─, ┼, ã, Ã, ╚, ╔, ╩, Ê, Ë, È, ı, Í, Î, Ï, ┘,
┌, Ô, Ò, õ, Õ, µ, þ, Þ, Ú, Û, ‗, ¾, ¶, §, ÷, ¸, °, ¨, ·,  ,  ,  ,  ,  ,  ,  ,  ,
  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,
,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,
 ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,
  ,  ,  ,  ,  ,  ,
-----------------------


HUFFSIZE
----------

2, 3, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 10
, 10, 10, 10, 10, 11, 11, 11, 11, 12, 12, 12, 12, 14, 15, 15, 16, 16, 16, 16, 16
, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16
, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16
, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16
, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16
, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16
, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 0, 0, 0, 0, 0, 0, 0, 0
, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
, 0, 0, 0, 0, 0, 0, 0,
-----------------------

should it not be:

2, 2, 3, 4, 4, 5, 5, 5, 5, and so on?

Im missing a value at the beginning
  • 0

#83
staticVoid

staticVoid

    Member

  • Topic Starter
  • Member
  • PipPip
  • 94 posts
Sorry , I was displaying the table starting at 1.

BITS
------

0, 2, 1, 2, 4, 4, 3, 4, 7, 5, 4, 4, 0, 1, 2, 119,
-----------------------




HUFFVAL
-------

 , ☺, ☻, ♥, ◄, ♦, ♣, !, 1, ♠, ↕, A, Q, , a, q, ‼, ", 2, ?,, ¶, B, ?, í, ▒, ┴,
, #, 3, R, ­, §, b, r, Ð,
, ▬, $, 4, ß, %, ±, ↨, ↑, ↓, →, &, ', (, ), *, 5, 6, 7, 8, 9, :, C, D, E, F, G,
H, I, J, S, T, U, V, W, X, Y, Z, c, d, e, f, g, h, i, j, s, t, u, v, w, x, y, z,
 ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ó, ú, ñ, Ñ, ª, º, ¿, ®, ¬
, ▓, │, ┤, Á, Â, À, ©, ╣, ║, ┬, ├, ─, ┼, ã, Ã, ╚, ╔, ╩, Ê, Ë, È, ı, Í, Î, Ï, ┘,
┌, Ô, Ò, õ, Õ, µ, þ, Þ, Ú, Û, ‗, ¾, ¶, §, ÷, ¸, °, ¨, ·,  ,  ,  ,  ,  ,  ,  ,  ,
  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,
,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,
 ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,
  ,  ,  ,  ,  ,  ,
-----------------------


HUFFSIZE
----------

2, 2, 3, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9,
 10, 10, 10, 10, 10, 11, 11, 11, 11, 12, 12, 12, 12, 14, 15, 15, 16, 16, 16, 16,
 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 0, 0, 0, 0, 0, 0, 0
, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
, 0, 0, 0, 0, 0, 0, 0, 0,
-----------------------

Edited by staticVoid, 17 September 2007 - 06:01 AM.

  • 0

#84
staticVoid

staticVoid

    Member

  • Topic Starter
  • Member
  • PipPip
  • 94 posts
I attempted to fill HUFFCODE using:

K = 0;
						int CODE = 0;
						int SI   = HUFFSIZE[0];

						while(true) {
						   HUFFCODE[K] = CODE;
						   CODE = CODE + 1;
						   K = K + 1;
						   if(HUFFSIZE[K] == SI) {
						   }
						   else {
							   if(HUFFSIZE[K] == 0) {
								  break;
							   }
							   else {
								  while(HUFFSIZE[K] != SI) {
									 CODE = CODE << 1;
									 SI = SI + 1;
								  }
							   }
						   }

						}


and heres the result:

BITS
------

0, 2, 1, 2, 4, 4, 3, 4, 7, 5, 4, 4, 0, 1, 2, 119,
-----------------------




HUFFVAL
-------

 , ☺, ☻, ♥, ◄, ♦, ♣, !, 1, ♠, ↕, A, Q, , a, q, ‼, ", 2, ?,, ¶, B, ?, í, ▒, ┴,
, #, 3, R, ­, §, b, r, Ð,
, ▬, $, 4, ß, %, ±, ↨, ↑, ↓, →, &, ', (, ), *, 5, 6, 7, 8, 9, :, C, D, E, F, G,
H, I, J, S, T, U, V, W, X, Y, Z, c, d, e, f, g, h, i, j, s, t, u, v, w, x, y, z,
 ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ó, ú, ñ, Ñ, ª, º, ¿, ®, ¬
, ▓, │, ┤, Á, Â, À, ©, ╣, ║, ┬, ├, ─, ┼, ã, Ã, ╚, ╔, ╩, Ê, Ë, È, ı, Í, Î, Ï, ┘,
┌, Ô, Ò, õ, Õ, µ, þ, Þ, Ú, Û, ‗, ¾, ¶, §, ÷, ¸, °, ¨, ·,  ,  ,  ,  ,  ,  ,  ,  ,
  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,
,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,
 ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,
  ,  ,  ,  ,  ,  ,
-----------------------


HUFFSIZE
----------

2, 2, 3, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9,
 10, 10, 10, 10, 10, 11, 11, 11, 11, 12, 12, 12, 12, 14, 15, 15, 16, 16, 16, 16,
 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 0, 0, 0, 0, 0, 0, 0
, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
, 0, 0, 0, 0, 0, 0, 0, 0,
-----------------------

HUFFCODE
-----------------
0, 1, 4, 10, 11, 24, 25, 26, 27, 56, 57, 58, 59, 120, 121, 122, 246, 247, 248, 2
49, 500, 501, 502, 503, 504, 505, 506, 1014, 1015, 1016, 1017, 1018, 2038, 2039,
 2040, 2041, 4084, 4085, 4086, 4087, 16352, 32706, 32707, 65416, 65417, 65418, 6
5419, 65420, 65421, 65422, 65423, 65424, 65425, 65426, 65427, 65428, 65429, 6543
0, 65431, 65432, 65433, 65434, 65435, 65436, 65437, 65438, 65439, 65440, 65441,
65442, 65443, 65444, 65445, 65446, 65447, 65448, 65449, 65450, 65451, 65452, 654
53, 65454, 65455, 65456, 65457, 65458, 65459, 65460, 65461, 65462, 65463, 65464,
 65465, 65466, 65467, 65468, 65469, 65470, 65471, 65472, 65473, 65474, 65475, 65
476, 65477, 65478, 65479, 65480, 65481, 65482, 65483, 65484, 65485, 65486, 65487
, 65488, 65489, 65490, 65491, 65492, 65493, 65494, 65495, 65496, 65497, 65498, 6
5499, 65500, 65501, 65502, 65503, 65504, 65505, 65506, 65507, 65508, 65509, 6551
0, 65511, 65512, 65513, 65514, 65515, 65516, 65517, 65518, 65519, 65520, 65521,
65522, 65523, 65524, 65525, 65526, 65527, 65528, 65529, 65530, 65531, 65532, 655
33, 65534, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
------------------------------------

Does that look right?

Edited by staticVoid, 17 September 2007 - 11:10 AM.

  • 0

#85
bdlt

bdlt

    Member

  • Member
  • PipPipPip
  • 876 posts
I will take a look at your code Wed, and if time allows, will do some hand calculations.

for debug purposes, you might consider adding code to displays bits. For example, HUFFVAL is meaningless as shown.
  • 0

Advertisements


#86
staticVoid

staticVoid

    Member

  • Topic Starter
  • Member
  • PipPip
  • 94 posts
I thought HUFFVAL was the characters you were to repace the codes with?
  • 0

#87
bdlt

bdlt

    Member

  • Member
  • PipPipPip
  • 876 posts
think of HUFFVAL as a lookup table.

HUFFVAL is filled from the header as bytes(for decoding).

think of the values as integers, not characters. Typically they are referenced in hex, but feel free to continue to display them as integers(not characters).

this may not be very clear now. eventually, you will create code to 'link' each HUFFVAL to a bit pattern. the bit pattern(s) are used for encryption and decryption. HUFFVAL is an intermediate set of values used by huffman encryption and decryption. the only place we see HUFFVAL in the image file is in the header. HUFFVAL and BITS can vary from image to image. they are defined by the 'encryptor' prior to encryption. the 'encryptor' places BITS and HUFFVAL in the header to let the 'decryptor' know how to unravel the image compression.
  • 0

#88
bdlt

bdlt

    Member

  • Member
  • PipPipPip
  • 876 posts
reply to post 84:

the HUFFCODE lines of code look good. the HUFFCODE values look legitimate. they are most likely correct, but we will find out for sure when parsing begins.

you might consider a minor tweak to the code. the if-else HUFFSIZE[K] == SI can be replaced with an if( HUFFSIZE[K] != SI ). the code will run as is ... the if of if-else does nothing.

here's why HUFFCODE values look legitimate:
the first two values 0,1 can be represented by 2 bits(00, 01). BITS[2] tells us that there are 2 2-bit codes in this table.
similarly, BITS[3] = 1, so we expect one code with a length of 3 bits. the next HUFFCODE is 4 which can be represented by 3 bits as 100.
BITS[4] = 2, which tells us that there are two codes that are 4 bits in length. HUFFCODES 10, 11 can be shown as 1010 and 1011.
jumping to 16352 - it can be shown as a 14 bit code
32706 & 32707 can be shown as 15 bit numbers.
I will let you count the 16 bit codes - there should be 129 16-bit codes.

*****************************************************

the HUFFCODE values need to be converted to a bit representation to be useful later on.
0 = 00
1 = 01
4 = 100
10 = 1010
11 = 1011
and so on
  • 0

#89
staticVoid

staticVoid

    Member

  • Topic Starter
  • Member
  • PipPip
  • 94 posts
I think I understand.

what data type will I use to store the bit represetation?

Edited by staticVoid, 23 September 2007 - 03:53 PM.

  • 0

#90
staticVoid

staticVoid

    Member

  • Topic Starter
  • Member
  • PipPip
  • 94 posts
The way I plan to decode is by getting the image data from the file in a bit representation then replacing every HUFFCODE that I find in the bitstream with the corresponding HUFFVALUE.
Is there anything else I need to do before doing this?
I'm going to treat the huffman stage totally separate from the rest of the decoding process.
  • 0






Similar Topics

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP