Exemplo n.º 1
0
	//-----------------------------------------------------------------//
	bool jpeg_io::probe(utils::file_io& fin)
	{
		unsigned char sig[2];
		long pos = fin.tell();
		size_t l = fin.read(sig, 1, 2);
		fin.seek(pos, utils::file_io::seek::set);
		if(l == 2) {
			if(sig[0] == 0xff && sig[1] == 0xd8) {
				return true;
			}
		}
		return false;
	}
Exemplo n.º 2
0
	//-----------------------------------------------------------------//
	bool jpeg_io::info(utils::file_io& fin, img::img_info& fo)
	{
		if(!probe(fin)) {
			return false;
		}

		struct jpeg_decompress_struct cinfo;
		struct jpeg_error_mgr errmgr;

		long pos = fin.tell();

		// エラーのハンドリング
		cinfo.err = jpeg_std_error(&errmgr);
		errmgr.error_exit = error_exit_task;

	    // 構造体の初期設定
		jpeg_create_decompress(&cinfo);

		// file_io クラス設定
		fio_jpeg_file_io_src(&cinfo, &fin);

		// ファイルの情報ヘッダの読込み
		error_code_ = 0;
		jpeg_read_header(&cinfo, TRUE);
		fin.seek(pos, utils::file_io::seek::set);

		if(error_code_) {
///			std::endl << "JPEG decode error: 'header'(" << static_cast<int>(error_code_) << ")" << std::endl; 
			jpeg_destroy_decompress(&cinfo);
			return false;
		}

		fo.width = cinfo.output_width;
		fo.height = cinfo.output_height;
		fo.mipmap_level = 0;
		fo.multi_level = 0;
		fo.i_depth = 0;

		if(cinfo.output_components == 4) {
			fo.r_depth = 8;
			fo.g_depth = 8;
			fo.b_depth = 8;
			fo.a_depth = 8;
			fo.grayscale = false;
		} else if(cinfo.output_components == 3) {
			fo.r_depth = 8;
			fo.g_depth = 8;
			fo.b_depth = 8;
			fo.a_depth = 0;
			fo.grayscale = false;
		} else if(cinfo.output_components == 2) {
			fo.r_depth = 8;
			fo.g_depth = 8;
			fo.b_depth = 8;
			fo.a_depth = 8;
			fo.grayscale = true;
		} else if(cinfo.output_components == 1) {
			fo.r_depth = 8;
			fo.g_depth = 8;
			fo.b_depth = 8;
			fo.a_depth = 0;
			fo.grayscale = true;
		} else {
			fo.r_depth = 0;
			fo.g_depth = 0;
			fo.b_depth = 0;
			fo.a_depth = 0;
			fo.grayscale = false;
			return false;
		}

		return true;
	}