Esempio n. 1
0
int
process (char const *srcfn)
{
	int fd;
	char *rc;
	u_char *data;
	size_t data_length;
	struct stat fs;
	u_int height, width;
	
	fd = open(srcfn,  O_RDONLY);
	if (fd == -1)
	{
		perror("ERROR: Can't open the file for reading");
		return 1;
	}
	
	fstat(fd, &fs);
	
	data_length = fs.st_size;
	
	data = mmap(0, data_length, PROT_READ, MAP_SHARED, fd, 0);
	
	
	rc = try_jpeg(data, data_length, &width, &height);
	if (rc == RC_OK)
	{
		printf("%dx%d\n", width, height);
		return 0;
	}
	if (rc != RC_NEXT)
	{
		fprintf(stderr, "ERROR: %s\n", rc);
	}
	
	rc = try_png(data, data_length, &width, &height);
	if (rc == RC_OK)
	{
		printf("%dx%d\n", width, height);
		return 0;
	}
	if (rc != RC_NEXT)
	{
		fprintf(stderr, "ERROR: %s\n", rc);
	}
	
	
	fprintf(stderr, "ERROR: File format is neither jpeg nor png.\n");
	
	return 6;
}
Esempio n. 2
0
int decode2RGBA (FILE* srcFILE, char const* cache_dir, Image* image) {
    // methods

    // check FILE open status
    if(!srcFILE) {
        LOGD("srcFILE is null");
        return 0;
    }

    if(try_jpeg(srcFILE, cache_dir, image)) {
        LOGD("jpeg success");
        return 1;
    }

    if (try_png(srcFILE, image)) {
        LOGD("png success");
        return 1;
    }

    return 0;
}