#include #include #include #include void main() { struct jpeg_decompress_struct cinfo; struct jpeg_error_mgr jerr; FILE *infile; JSAMPARRAY img; int i, j; int width; int height; // JPEGオブジェクトの初期化 cinfo.err = jpeg_std_error( &jerr ); jpeg_create_decompress( &cinfo ); // ファイルを開く infile = fopen( "a.jpg", "rb" ); jpeg_stdio_src( &cinfo, infile ); // ヘッダの読み込み jpeg_read_header( &cinfo, TRUE ); // 展開の開始 jpeg_start_decompress( &cinfo ); // 幅と高さの取得 width = cinfo.output_width; height = cinfo.output_height; // イメージを保持するメモリ領域の確保と初期化 img = (JSAMPARRAY)malloc( sizeof( JSAMPROW ) * height ); for ( i = 0; i < height; i++ ) { img[i] = (JSAMPROW)calloc( sizeof( JSAMPLE ), 3 * width ); } // 全イメージデータを取得 while( cinfo.output_scanline < cinfo.output_height ) { jpeg_read_scanlines( &cinfo, img + cinfo.output_scanline, cinfo.output_height - cinfo.output_scanline ); } // 展開の終了 jpeg_finish_decompress( &cinfo ); // JPEGオブジェクトの破棄 jpeg_destroy_decompress( &cinfo ); // ファイルを閉じる fclose( infile ); // HTML化して出力 printf( "\n" ); for ( i = 0; i < height; i++ ){ printf( "\n" ); for ( j = 0; j < width; j++ ) { // 1ます分のデータを出力 printf( "\n", img[i][j * 3 + 0 ], img[i][j * 3 + 1 ], img[i][j * 3 + 2 ] ); } printf( "\n" ); } printf( "
 
\n" ); // イメージデータを保持するメモリ領域を開放 for ( i = 0; i < height; i++ ) free( img[i] ); free( img ); }