0

I want to read data from a .jpg file (header, DCT information, Huffman table, quantization table, ...)

I tried this piece of code but I'm not sure if it's correct (in fact I don't know what to get!)

byte[] my = new byte[5];
    try 
    {
        RandomAccessFile file = new RandomAccessFile("001.jpg", "rw");
        file.read(my, 0, 5);
        for(int i = 0; i < my.length; i++)
            System.out.printf("%s\n", my[i]);

    } 
    catch (IOException e) 
    {

    }

This code just prints some number (it's supposed to be beginning of the image)

tvkanters
  • 3,519
  • 4
  • 29
  • 45
Branky
  • 373
  • 8
  • 23
  • There are standard JPEG libraries for all languages/platforms. Have you tried one? Look at http://docs.oracle.com/javase/tutorial/2d/images/index.html and http://stackoverflow.com/q/603283/10468 and http://stackoverflow.com/q/8310680/10468 – DarenW Mar 22 '14 at 16:27
  • cause I want to manipulate pixel info, can't use libraries – Branky Mar 22 '14 at 16:41
  • That code is supposed to print the first 5 bytes of the file and that's exactly what it does. I'm not sure what your problem with it is. – Boann Mar 22 '14 at 16:42
  • @Boann what are these bytes? – Branky Mar 22 '14 at 16:48
  • @Branky I've no idea. Read a document which describes the JPEG format and it will tell you. – Boann Mar 22 '14 at 16:57

1 Answers1

2

There is a lot of work between reading a "JPEG file" and getting to the pixel data.

If you are really interested, I suggest starting with one of the many JPEG dump programs that are out there to learn about the structure of the the JPEG stream. A JPEG stream consists of a sequence of markers.

The compressed data is in the scans. In progressive JPEG, multiple scans have to be combined.

The basis sequence of decoding is run-length/huffman, DCT, sampling, conversion to RGB.

That's a lot of code to get to that point.

user3344003
  • 20,574
  • 3
  • 26
  • 62
  • can u suggest a simple program as u mentioned? – Branky Mar 23 '14 at 06:41
  • https://en.wikipedia.org/wiki/JPEG https://en.wikipedia.org/wiki/JPEG_File_Interchange_Format http://www.fileformat.info/format/jpeg/egff.htm http://www.w3.org/Graphics/JPEG/jfif3.pdf – jwenting Jul 02 '15 at 10:46