これまで検索機能を使ってやってきたので、これは私の最初の投稿です。しかし今、私は次の問題で丸一日を無駄にしました:
12 ビット (16 ビットとして書き込まれる) グレースケール ビデオを記録し、バイナリ ストリーム ファイル (ヘッダーなどなし) に直接書き込みました。
ここでのタスクは、ファイルを読み取り、すべてのフレームを 16 ビット pgm として出力することです。
次の抜粋は、私が試したことを示しています。出力は有効な pgm ですが、「ホワイト ノイズ」が含まれています。
...
imageBufferShort = new short[imageWidth*imageHeight* sizeof(short)];
...
streamFileHandle.read(reinterpret_cast<char*>(imageBufferShort),2*imageWidth*imageHeight); //double amount because 8bit chars!
// As .read only takes chars, I thought, that I just read the double amount of char-bytes and when it is interpreted as short (=16bit) everything is ok?!?
...now the pgm output:
std::ofstream f_hnd(fileName,std::ios_base::out |std::ios_base::binary |std::ios_base::trunc);
// write simple header
f_hnd.write("P5\n",3);
f_hnd << imageWidth << " " << imageHeight << "\n4095\n"; //4095 should tell the pgm to use 2 bytes for each pixel
f_hnd.write(reinterpret_cast<char*>(imageBufferShort),2*imageWidth*imageHeight);
f_hnd.close();
繰り返しますが、ファイルは生成されて表示可能ですが、ゴミが含まれています。最初の推測は大丈夫ですか?2つの「文字」を読み取り、それらを1つの「短い」として処理しますか? また、すべての行の後に空白を入れますが、これは何も変わらないので、この短いコードを投稿することにしました。
助けてくれてありがとう!