#include #include #include #include void main() { struct jpeg_compress_struct cinfo; struct jpeg_error_mgr jerr; FILE *outfile; JSAMPROW line; int i, j; // 一行分のデータを保持するためのメモリ領域を確保する line = (JSAMPROW)malloc( sizeof( JSAMPLE ) * 3 * 256 ); // JPEGオブジェクトの初期化 cinfo.err = jpeg_std_error( &jerr ); jpeg_create_compress( &cinfo ); // ファイルを開く outfile = fopen( "a.jpg", "wb" ); jpeg_stdio_dest( &cinfo, outfile ); // パラメータの設定 cinfo.image_width = 256; cinfo.image_height = 256; cinfo.input_components = 3; cinfo.in_color_space = JCS_RGB; // デフォルト値の設定 jpeg_set_defaults( &cinfo ); // 圧縮の開始 jpeg_start_compress( &cinfo, TRUE ); // 一行ずつ出力する for ( i = 0; i < 256; i++ ) { // 一行分のイメージデータを生成する for ( j = 0; j < 256; j++ ) { line[ j * 3 + 0 ] = i; line[ j * 3 + 1 ] = 0; line[ j * 3 + 2 ] = j; } // 一行出力 jpeg_write_scanlines( &cinfo, &line, 1 ); } // 圧縮を終了する jpeg_finish_compress( &cinfo ); // JPEGオブジェクトを破棄する jpeg_destroy_compress( &cinfo ); // ファイルを閉じる fclose( outfile ); // 一行分のイメージデータを保持するメモリ領域を開放する free( line ); }