예제 #1
0
inline
point2< std::ptrdiff_t > tiff_read_dimensions( const String& filename )
{
    image_read_info< tiff_tag > info = read_image_info( filename
                                       , tiff_tag()
                                                      );

    return point2< std::ptrdiff_t >( info._width
                                     , info._height
                                   );
}
예제 #2
0
inline
point2< std::ptrdiff_t > bmp_read_dimensions( const String& filename )
{
    typedef typename get_reader_backend< String
                                       , bmp_tag
                                       >::type backend_t;

    backend_t backend = read_image_info( filename
                                       , bmp_tag()
                                       );

    return point2< std::ptrdiff_t >( backend._info._width
                                   , backend._info._height
                                   );
}
예제 #3
0
inline
typename get_reader_backend< String
                           , FormatTag
                           >::type
read_image_info( const String&    file_name
               , const FormatTag&
               , typename enable_if< mpl::and_< is_format_tag< FormatTag >
                                              , detail::is_supported_path_spec< String >
                                              >
                                   >::type* /* ptr */ = 0
               )
{
    return read_image_info( file_name
                          , image_read_settings< FormatTag >()
                          );
}
예제 #4
0
inline 
image_read_info<FormatTag>  
read_image_info( const String&    file_name
               , const FormatTag& tag
               , typename enable_if< typename mpl::and_< typename is_format_tag< FormatTag >::type
                                                       , typename detail::is_supported_path_spec< String >::type
                                                       >::type
                                   >::type* ptr = 0
               )
{
    detail::file_stream_device< FormatTag > reader( detail::convert_to_string( file_name )
                                                  , detail::file_stream_device< FormatTag >::read_tag()
                                                  );

    return read_image_info( reader
                          , tag    );
}
예제 #5
0
inline
typename get_reader_backend< Device
                           , FormatTag
                           >::type
read_image_info( Device&          file
               , const FormatTag&
               , typename enable_if< mpl::and_< detail::is_adaptable_input_device< FormatTag
                                                                                 , Device
                                                                                 >
                                              , is_format_tag< FormatTag >
                                              >
                                   >::type* /* ptr */ = 0
               )
{
    return read_image_info( file
                          , image_read_settings< FormatTag >()
                          );
}
예제 #6
0
inline point_t tiff_read_dimensions(String const& filename)
{
    using backend_t = typename get_reader_backend<String, tiff_tag>::type;
    backend_t backend = read_image_info(filename, tiff_tag());
    return { backend._info._width, backend._info._height };
}
예제 #7
0
static int write2emmc(int pkg_fd, int img_count, int retry_count, enum swan_image_type *skip_types, size_t skip_img_count)
{
	int ret;
	int img_fd;
	u32 tmp_crc32;
	struct swan_image_info img_info;

	while (img_count) {
		int retry;

		ret = read_image_info(pkg_fd, &img_info);
		if (ret < 0) {
			pr_err_info("read_image_info");
			return ret;
		}

		if (array_has_element(img_info.type, (int *) skip_types, skip_img_count)) {
			ret = lseek(pkg_fd, img_info.length, SEEK_CUR);
			if (ret < 0) {
				pr_err_info("lseek");
				return ret;
			}

			pr_warn_info("skipping image \"%s\" ...", swan_image_type_tostring(img_info.type));
			continue;
		}

		img_fd = open_dest_device(&img_info);
		if (img_fd < 0) {
			pr_err_info("open_dest_device");
			return ret;
		}

		retry = retry_count;

		while (retry--) {
			off_t pkg_pointer_bak;

			ret = get_file_pointer(pkg_fd, &pkg_pointer_bak);
			if (ret < 0) {
				pr_err_info("can't backup file pointer");
				goto out_close_img;
			}

			ret = read_simple_image(pkg_fd, img_fd, img_info.length, img_info.offset);
			if (ret < 0) {
				pr_err_info("get_image");
				goto out_close_img;
			}

			ret = lseek(img_fd, img_info.offset, SEEK_SET);
			if (ret < 0) {
				pr_err_info("lseek");
				goto out_close_img;
			}

			fsync(img_fd);

			println("check image crc32 checksum");

			tmp_crc32 = 0;

			ret = ffile_ncrc32(img_fd, img_info.length, &tmp_crc32);
			if (ret < 0) {
				pr_err_info("ffile_ncrc32");
				goto out_close_img;
			}

			println("img_crc32 = 0x%08x, tmp_crc32 = 0x%08x", img_info.crc32, tmp_crc32);

			if (img_info.crc32 ^ tmp_crc32) {
				pr_err_info("image crc32 checksum is not match, retry = %d", retry);
			} else {
				pr_green_info("image crc32 checksum is match");
				break;
			}

			ret = lseek(pkg_fd, pkg_pointer_bak, SEEK_SET);
			if (ret < 0) {
				pr_err_info("recovery package file pointer");
				goto out_close_img;
			}
		}

		if (retry < 0) {
			ret = -EIO;
			goto out_close_img;
		}

		close(img_fd);
		img_count--;
	}

	return 0;

out_close_img:
	close(img_fd);

	return ret;
}
예제 #8
0
int unpack(const char *pkg_name, const char *dir_name)
{
	int ret;
	int pkg_fd;
	int img_fd;
	struct swan_file_info file_info;
	struct swan_package_info pkg_info;
	struct swan_image_info img_info;
	char tmp_path[1024];

	pr_std_info("unpack upgrade file \"%s\" -> \"%s\"", pkg_name, dir_name);

	ret = swan_check_md5sum(pkg_name);
	if (ret < 0) {
		pr_err_info("swan_check_md5sum");
		return ret;
	}

	pkg_fd = open(pkg_name, O_RDONLY | O_BINARY);
	if (pkg_fd < 0) {
		pr_err_info("open file \"%s\"", pkg_name);
		return -1;
	}

	ret = cavan_mkdir(dir_name);
	if (ret < 0) {
		pr_err_info("cavan_mkdir");
		goto out_close_pkg;
	}

	text_path_cat(tmp_path, sizeof(tmp_path), dir_name, HEADER_BIN_NAME);
	ret = read_upgrade_program(pkg_fd, &file_info, tmp_path);
	if (ret < 0) {
		pr_err_info("get_upgrade_program");
		goto out_close_pkg;
	}

	ret = read_resource_image(pkg_fd, &pkg_info, dir_name, 0, 0);
	if (ret < 0) {
		pr_err_info("get_resource_image");
		goto out_close_pkg;
	}

	while (pkg_info.image_count) {
		ret = read_image_info(pkg_fd, &img_info);
		if (ret < 0) {
			pr_err_info("read_image_info");
			goto out_close_pkg;
		}

		text_path_cat(tmp_path, sizeof(tmp_path), dir_name, img_info.filename);
		img_fd = open(tmp_path, O_WRONLY | O_CREAT | O_SYNC | O_TRUNC | O_BINARY, 0777);
		if (img_fd < 0) {
			pr_err_info("open");
			goto out_close_pkg;
		}

		ret = read_simple_image(pkg_fd, img_fd, img_info.length, 0);
		if (ret < 0) {
			pr_err_info("get_image");
			goto out_close_img;
		}

		close(img_fd);
		pkg_info.image_count--;
	}

	println_green("Decompression upgrade package \"%s\" to \"%s\" is ok", pkg_name, dir_name);

	ret = 0;
	goto out_close_pkg;

out_close_img:
	close(img_fd);
out_close_pkg:
	close(pkg_fd);

	if (ret < 0) {
		rmdir(dir_name);
	}

	return ret;
}