0

したがって、演習として、ファイルから JFIF (JPEG) データを読み取っています (すでにこれを行っているライブラリがあることは知っていますが、それらを探しているわけではありません)。画像ファイルのサイズ、色深度、寸法は既に取得しています。ただし、実際の画像データを取得する方法がよくわかりません。16 進エディターでデータを調べましたが、それを実際の画像と比較しても、どこにも行きません。誰かがこれを開始するための優れたリソースを持っている場合 (おそらく困難で啓発的なプロセスであることはわかっていますが、それが私がそれを行っている理由です)、それは素晴らしいことです。

コンテキストのためだけに、これまでの私のコード:

// check header data, assign header data to important fields

        // Start Of Image (SOI) must be FFD8 and the next marker must be FF
        if(!(this.data[0] == (byte) 0xFF && this.data[1] == (byte) 0xD8
                && this.data[2] == (byte) 0xFF))
            this.isValid = false;

        // check if file is not valid
        if(!isValid) 
            log.log(Level.SEVERE, 
                    String.format("ERROR: File %s is not registered as a JFIF!\n", this.filename), 
                    new IllegalArgumentException());

        // If the next values are correct, then the data stream starts at SOI
        // If not, the data stream is raw
        this.isRawDataStream = !(this.data[3] == (byte) 0xE0
                && this.data[6]  == (byte) 0x4A
                && this.data[7]  == (byte) 0x46
                && this.data[8]  == (byte) 0x49
                && this.data[9]  == (byte) 0x46
                && this.data[10] == (byte) 0x00);

        // Read until SOF0 marker (0xC0)
        int i = 11;
        while(this.data[i] != (byte) 0xC0) {
            i++;
        }
        System.out.println("SOF0 marker at offset " + i);

        // Skip two bytes, next byte is the color depth
        this.colorDepth = this.data[i+3];

        // Next two bytes are the image height
        String h = String.format("%02X", this.data[i+4]) + String.format("%02X", this.data[i+5]);
        this.height = hexStringToInt(h);
        System.out.println("Height: " + this.height);

        // Next two bytes are the image width
        String w = String.format("%02X", this.data[i+6]) + String.format("%02X", this.data[i+7]); 
        this.width = hexStringToInt(w);
        System.out.println("Width: " + this.width);

        System.out.println("Color depth: " + this.colorDepth);
        // load pixels into an image
        this.image = new BufferedImage(this.width,
                                       this.height, 
                                       BufferedImage.TYPE_INT_RGB);

次に、各ピクセルを取得して画像に送信する必要があります。各ピクセルとそれぞれの RGB データを取得するにはどうすればよいですか?

4

1 に答える 1

4

あなたがやろうとしていることは、単純な午後のプロジェクトではありません。この本はそのプロセスを説明しています: JPEG 圧縮データとピクセル値の間にはたくさんのコードがあります。

http://www.amazon.com/Compressed-Image-File-Formats-JPEG/dp/0201604434/ref=pd_bxgy_b_img_y

まず、2 つの別個の、しかし関連する圧縮方法を処理する必要があります: シーケンシャルとプログレッシブです。

ビットデータを読み取るときは、

  1. ハフマンデコード
  2. ランレングスデコード
  3. 逆量子化
  4. リスト項目
  5. 逆離散コサイン変換
  6. アップサンプル
  7. YCbCr から RGB への変換

これは、シーケンシャルの単純なケースです。

このフォーラムで説明されているすべての手順を取得することはできません。

私もお勧めします

http://www.amazon.com/dp/1558514341/ref=rdr_ext_tmb

于 2014-10-09T15:39:44.973 に答える