タイトルの通り、libjpeg-turboでJPEGファイルを読もうとしています。自宅の Mac でこのコードを試してみましたが、うまくいきましたが、今は Windows を使用しておりEmpty input file
、呼び出し時にエラーが発生しjpeg_read_header
ます。fseek/ftell を実行して、ファイルが空でないことを確認しました。取得したサイズは、期待どおりのサイズです。
私の最初の考えは、ファイルをバイナリ モードで開いていない可能性があるということでした。そのため、_setmode を使用してそれも試しましたが、役に立たなかったようです。参照用の私のコードは次のとおりです。
int decodeJpegFile(char* filename)
{
FILE *file = fopen(filename, "rb");
if (file == NULL)
{
return NULL;
}
_setmode(_fileno(file), _O_BINARY);
fseek(file, 0L, SEEK_END);
int sz = ftell(file);
fseek(file, 0L, SEEK_SET);
struct jpeg_decompress_struct info; //for our jpeg info
struct jpeg_error_mgr err; //the error handler
info.err = jpeg_std_error(&err);
jpeg_create_decompress(&info); //fills info structure
jpeg_stdio_src(&info, file);
jpeg_read_header(&info, true); // ****This is where it fails*****
jpeg_start_decompress(&info);
int w = info.output_width;
int h = info.output_height;
int numChannels = info.num_components; // 3 = RGB, 4 = RGBA
unsigned long dataSize = w * h * numChannels;
unsigned char *data = (unsigned char *)malloc(dataSize);
unsigned char* rowptr;
while (info.output_scanline < h)
{
rowptr = data + info.output_scanline * w * numChannels;
jpeg_read_scanlines(&info, &rowptr, 1);
}
jpeg_finish_decompress(&info);
fclose(file);
FILE* outfile = fopen("outFile.raw", "wb");
size_t data_out = fwrite(data, dataSize, sizeof(unsigned char), outfile);
}`
どんな助けでも大歓迎です!