Пример #1
0
static void
unpack_krnl(const char *path, uint8_t *buf, uint32_t size)
{
	uint32_t ksize;
	char rpath[PATH_MAX];

	ksize = buf[4] | buf[5] << 8 | buf[6] << 16 | buf[7] << 24;
	buf += 8;
	size -= 8;

	if ((ksize + 4) > size)
		fprintf(stderr, "invalid file size (should be %u bytes)\n",
		    ksize);

	snprintf(rpath, sizeof(rpath), "%s-raw", path);
	write_image(rpath, buf, ksize);

	buf += ksize + 4;
	size -= ksize + 4;

	if (size > 0) {
		snprintf(rpath, sizeof(rpath), "%s-symbol", path);
		write_image(rpath, buf, size);
	}
}
Пример #2
0
bool Frame::write(const char* file_path) const
{
    assert(file_path);

    const ImageAttributes image_attributes =
        ImageAttributes::create_default_attributes();

    bool result = write_image(file_path, *impl->m_image, image_attributes);

    if (!impl->m_aov_images->empty())
    {
        const filesystem::path boost_file_path(file_path);
        const filesystem::path directory = boost_file_path.branch_path();
        const string base_file_name = boost_file_path.stem();
        const string extension = boost_file_path.extension();

        for (size_t i = 0; i < impl->m_aov_images->size(); ++i)
        {
            const string aov_file_name =
                base_file_name + "." + impl->m_aov_images->get_name(i) + extension;
            const string aov_file_path = (directory / aov_file_name).string();

            if (!write_image(
                    aov_file_path.c_str(),
                    impl->m_aov_images->get_image(i),
                    image_attributes))
                result = false;
        }
    }

    return result;
}
Пример #3
0
nemo_main()
{
    real frame[N][N];
    image f1;
    imageptr fp1, fp2;	/* or image *fp1 */
    stream instr,outstr;

    if (strcmp(getparam("mode"),"w")==0) {		/* write test */
	printf ("WRITING test (mode=w) foo.dat\n");
	outstr = stropen ("foo.dat","w");

	f1.frame = &frame[0][0];  /* compiler complained when = frame used ???? */
				  /* would be same as fp2->frame = ... */
	fp1 = &f1;		  /* to initialize structures, we need pointer to them */
	ini_matrix (&fp1,N,N);    /* ini_matrix MUST have pointer to pointer to image */
	
	fp2 = NULL;		  /* This is to check dynamic allocation of whole thing */
	ini_matrix (&fp2,N,N);

	write_image (outstr,fp2);
	write_image (outstr,&f1);		/* or fp1 */
	strclose(outstr);
	exit(0);
    } else {
	printf ("READING test (mode<>w) foo.dat\n");
	fp2=NULL;					/* read test */
	instr = stropen ("foo.dat","r");
	while (read_image(instr,&fp2)) {
            printf ("Read image\n");
            printf ("with MapValue(5,5)=%f\n",MapValue(fp2,5,5));
	}
	strclose(instr);
    }
}
Пример #4
0
bool
ImageOutputWrap::write_image_bt (TypeDesc::BASETYPE format, object &data,
                                 stride_t xstride, stride_t ystride,
                                 stride_t zstride)
{
    return write_image (format, data, xstride, ystride, zstride);
}
Пример #5
0
unsigned
ffs_make_fsys_2(FILE *dst_fp, struct file_entry *list, char *mountpoint, char *destname) {
	struct tree_entry	*trp;
	ffs_sort_t			*sort;

	if(mountpoint == NULL) mountpoint = "";

	//
	//	If target endian is unknown, set to little endian
	//

	if (target_endian == -1)
		target_endian = 0;
	
	//
	//	Make sure block size is defined and reasonable (at least 1K)
	//

	if (block_size < 1024)
		mk_flash_exit("Error: block_size not defined or incorrectly defined (>1K), exiting ...\n");

	trp = make_tree(list);

	sort = ffs_entries(trp, mountpoint);

	write_f3s(sort, block_size);

	write_image(dst_fp);

	return 0;
}
Пример #6
0
int main(int argc, char *argv[]) {
    rrimage *data = read_image_with_compress_by_area("/Users/robert/Pictures/square.gif", compress_strategy, 960, 0, 0, 300, 300, ROTATE_90);
    printf("width = %d, height = %d, channels = %d\n", data->width, data->height, data->channels);
    printf("write result is: %d\n", write_image("/Users/robert/Desktop/out.jpg", data));

    return 0;
}
Пример #7
0
bool Frame::archive(
    const char*         directory,
    char**              output_path) const
{
    assert(directory);

    // Construct the name of the image file.
    const string filename =
        "autosave." + get_time_stamp_string() + ".exr";

    // Construct the path to the image file.
    const string file_path = (filesystem::path(directory) / filename).string();

    // Return the path to the image file.
    if (output_path)
        *output_path = duplicate_string(file_path.c_str());

    Image transformed_image(*impl->m_image);
    transform_to_output_color_space(transformed_image);

    return
        write_image(
            file_path.c_str(),
            transformed_image,
            ImageAttributes::create_default_attributes());
}
Пример #8
0
bool Frame::write_aov_images(const char* file_path) const
{
    assert(file_path);

    const ImageAttributes image_attributes =
        ImageAttributes::create_default_attributes();

    bool result = true;

    if (!impl->m_aov_images->empty())
    {
        const filesystem::path boost_file_path(file_path);
        const filesystem::path directory = boost_file_path.parent_path();
        const string base_file_name = boost_file_path.stem().string();
        const string extension = boost_file_path.extension().string();

        for (size_t i = 0; i < impl->m_aov_images->size(); ++i)
        {
            const string aov_name = impl->m_aov_images->get_name(i);
            const string safe_aov_name = make_safe_filename(aov_name);
            const string aov_file_name = base_file_name + "." + safe_aov_name + extension;
            const string aov_file_path = (directory / aov_file_name).string();

            // Note: AOVs are always in the linear color space.
            if (!write_image(
                    aov_file_path.c_str(),
                    impl->m_aov_images->get_image(i),
                    image_attributes))
                result = false;
        }
    }

    return result;
}
Пример #9
0
void nemo_main()
{
  stream  outstr;
  int     nx, ny, nz;  
  int     ix, iy, iz;
  imageptr optr=NULL;        /* pointer to image, needs to be NULL to force new */
  real    tmp, sum = 0.0;

  outstr = stropen(getparam("out"), "w");

  nx = getiparam("nx");
  ny = getiparam("ny");
  nz = getiparam("nz");

  dprintf(0,"Creating image cube (size : %d x %d x %d)\n",nx,ny,nz);

  create_cube(&optr,nx,ny,nz);

  for (iz=0; iz<nz; iz++) {
    for (iy=0; iy<ny; iy++) {
      for (ix=0; ix<nx/2; ix++) {
        CubeValue(optr,ix,iy,iz) = 0.0;
      }
    }
  }

  write_image(outstr, optr);



}
Пример #10
0
void nemo_main ()
{
    setparams();			/* set par's in globals */

    instr = stropen (infile, "r");
    read_image (instr,&iptr);
				/* set some global paramters */
    nx = Nx(iptr);	
    ny = Ny(iptr);
    nz = Nz(iptr);
    xmin = Xmin(iptr);
    ymin = Ymin(iptr);
    zmin = Zmin(iptr);
    dx = Dx(iptr);
    dy = Dy(iptr);
    dz = Dz(iptr);

    if(hasvalue("gauss"))
        make_gauss_beam(getparam("dir"));

    outstr = stropen (outfile,"w");
    if (hasvalue("wiener"))
      wiener();
    else
      smooth_it();
    write_image (outstr,iptr);

    strclose(instr);
    strclose(outstr);
}
Пример #11
0
static void
unpack_android(const char *path, uint8_t *buf, uint32_t size)
{
	uint32_t pgsz, i, iof_pos, isz_pos, ioff, isize, iload;
	char rpath[PATH_MAX];
	char* images[] = { "kernel", "ramdisk", "second" };
	const int num_images = sizeof(images)/sizeof(images[0]);

	printf("\nunpacking Android images\n");

	pgsz = buf[36] | buf[37] << 8 | buf[38] << 16 | buf[39] << 24;

	ioff = pgsz; /* running page offset */
	for (i=0; i<num_images; i++) {
		isz_pos = 8 + 8*i;
		iof_pos = 12 + 8*i;
		isize = (((buf[isz_pos] | buf[isz_pos+1] << 8 |
			   buf[isz_pos+2] << 16 | buf[isz_pos+3] << 24)
			+ pgsz-1) / pgsz) * pgsz;
		iload = (((buf[iof_pos] | buf[iof_pos+1] << 8 |
			   buf[iof_pos+2] << 16 | buf[iof_pos+3] << 24)
			+ pgsz-1) / pgsz) * pgsz;

		snprintf(rpath, sizeof(rpath), "%s-%s.img", path, images[i]);
		printf("%08x-%08x/%08x-%08x %s %d bytes\n",
			iload, iload + isize - 1,
			ioff, ioff + isize - 1,
			rpath, isize);
		write_image(rpath, &buf[ioff], isize);

		ioff += isize;
	}
}
Пример #12
0
int main(int argc, char**argv){
	char * evar = getenv("RELY_SRAND_DATA");
	if(evar != NULL) srand(atoi(evar));
	else srand(0);
	
	if(argc <= 3){
		printf("USAGE: scale FACTOR INPUT OUTPUT\n");
		return 1;
	}
	inst_timer GLOBAL_TIMER = create_timer();
	start_timer(&GLOBAL_TIMER);
	double scale_factor = atof(argv[1]);
	char* in_filename = argv[2];
	char * out_filename = argv[3];
	printf("scale by %f: %s -> %s\n", scale_factor, in_filename, out_filename);

    int* src, * transformed;

	size_t sw, sh, dw, dh;
	printf("read from \"%s\" ...\n", in_filename);
	src = read_image(in_filename, &sw, &sh);
	if(src == NULL){
		fprintf(stderr, ">> Failed to read image %s\n", in_filename);
		exit(1);
	}
	transformed = allocate_transform_image(scale_factor, sw, sh, &dw, &dh);
	scale(scale_factor, src, sw, sh, transformed, dw, dh);
	printf("write to \"%s\" ...\n", out_filename);
	write_image(out_filename, transformed, dw, dh);
	free((void *) src);
	free((void *) transformed);
	end_timer(&GLOBAL_TIMER);
	printf("GLOBAL TIME\n");
	print_timer(&GLOBAL_TIMER);
}
Пример #13
0
static void
unpack_rkfw(const char *path, uint8_t *buf, uint32_t size)
{
	uint32_t ioff, isize;
	char rpath[PATH_MAX];

	printf("VERSION:%d.%d.%d\n", buf[8], buf[7], buf[6]);
	printf("\nunpacking\n");

	ioff = 0;
	isize = buf[4];
	snprintf(rpath, sizeof(rpath), "%s-HEAD", path);
	printf("%08x-%08x %s %d bytes\n", ioff, ioff + isize - 1, rpath, isize);
	write_image(rpath, &buf[ioff], isize);

	ioff = buf[0x19] | buf[0x1a] << 8 | buf[0x1b] << 16 | buf[0x1c] << 24;
	isize = buf[0x1d] | buf[0x1e] << 8 | buf[0x1f] << 16 | buf[0x20] << 24;

	if (memcmp(&buf[ioff], "BOOT", 4) != 0)
		errx(EXIT_FAILURE, "no BOOT signature");

	snprintf(rpath, sizeof(rpath), "%s-BOOT", path);
	printf("%08x-%08x %s %d bytes\n", ioff, ioff + isize - 1, rpath, isize);
	write_image(rpath, &buf[ioff], isize);

	ioff = buf[0x21] | buf[0x22] << 8 | buf[0x23] << 16 | buf[0x24] << 24;
	isize = buf[0x25] | buf[0x26] << 8 | buf[0x27] << 16 | buf[0x28] << 24;

	if (memcmp(&buf[ioff], "RKAF", 4) != 0)
		errx(EXIT_FAILURE, "no RKAF signature");

	printf("%08x-%08x update.img %d bytes\n", ioff, ioff + isize - 1,
	    isize);
	write_image("update.img", &buf[ioff], isize);

	printf("\nunpacking update.img\n");
	printf("================================================================================\n");
	unpack_rkaf("update.img", &buf[ioff], isize);
	printf("================================================================================\n\n");

	if (size - (ioff + isize) != 32)
		errx(EXIT_FAILURE, "invalid MD5 length");

	snprintf(rpath, sizeof(rpath), "%s-MD5", path);
	printf("%08x-%08x %s 32 bytes\n", ioff, ioff + isize - 1, rpath);
	write_image(rpath, &buf[ioff + isize], 32);
}
Пример #14
0
/*!
  \brief Close down the graphics processing. This gets called only at driver
         termination time.
*/
void PNG_Graph_close(void)
{
    write_image();

    if (png.mapped)
	unmap_file();
    else
	G_free(png.grid);
}
Пример #15
0
int
main(int argc, char* argv[])
{
    image* im = read_image(INPUT);
    gaussian_blur(im, SIGMA);
    write_image(OUTPUT, im);
    free_image(im);
    return 0;
}
Пример #16
0
int main(int argc, char *argv[])
{
    static const struct option long_options[] = {
        { "help",        0, 0, 'h' },
        { "version",     0, 0, 'V' },
        { NULL,          0, 0, 0 },
    };
    const char *filename;
    int ch;

    printf("SD image writer, Version %s\n", VERSION);
    progname = argv[0];
    setvbuf(stdout, NULL, _IOLBF, 0);
    setvbuf(stderr, NULL, _IOLBF, 0);
    signal(SIGINT, interrupted);
#ifdef __linux__
    signal(SIGHUP, interrupted);
#endif
    signal(SIGTERM, interrupted);

    while ((ch = getopt_long(argc, argv, "vd:DhV", long_options, 0)) != -1)
    {
        switch (ch) {
        case 'v':
            ++verify_only;
            continue;
        case 'd':
            device_name = optarg;
            continue;
        case 'D':
            ++debug_level;
            continue;
        case 'h':
            break;
        case 'V':
            /* Version already printed above. */
            return 0;
        }
        usage();
    }
    argc -= optind;
    argv += optind;
    if (argc != 1)
        usage();
    filename = argv[0];

    printf("%s\n", copyright);

    if (! device_name)
        device_name = ask_device();

    write_image(filename, device_name, verify_only);

    quit(1);
    return 0;
}
Пример #17
0
void cleanup (image *photo, char **argv)
{
    int rc = write_image (argv [2], photo);
    if (!rc)
    {
        fprintf (stderr, "Unable to write output file %s\n\n", argv [2]);
    }

    clear_image (photo);
}
Пример #18
0
int main( int argc, char * argv[] )
{
	typedef mist::rgb< unsigned char >    pixel_type;
	typedef mist::array2< pixel_type >    color_image_type;
	typedef mist::array2< unsigned char > gray_image_type;
	typedef mist::vector2< double >       vector_type;

	if( argc < 2 )
	{
		std::cerr << "This program requires a path to an input image." << std::endl;
		return( 1 );
	}

	color_image_type orginal_img;
	color_image_type  canny_img;

	if( !read_image( orginal_img, argv[ 1 ] ) )
	{
		std::cerr << "Could not open the image [" << argv[ 1 ] << "]." << std::endl;
		return( 1 );
	}

	// エッジを検出する
	canny( orginal_img, canny_img, 100, 200 );

	// Hough変換により直線のパラメータを求める
	std::vector< std::complex< double > > lines;
	mist::line::hough_transform( canny_img, lines, 100, 1, 3.1415926535897932384626433832795 / 360.0, 200 );

	// 直線を描画する
	double scale = orginal_img.width( ) > orginal_img.height( ) ? orginal_img.width( ) : orginal_img.height( );
	for( size_t i = 0 ; i < lines.size( ) ; i++ )
	{
		double rho = lines[ i ].real( );
		double theta = lines[ i ].imag( );

		vector_type p1( std::cos( theta ) * rho, std::sin( theta ) * rho );
		vector_type p2( p1.x - rho * std::sin( theta ), p1.y + rho * std::cos( theta ) );
		vector_type d = ( p2 - p1 ).unit( );

		p1 -= d * scale;
		p2 += d * scale;

		int x1 = static_cast< int >( p1.x + 0.5 );
		int y1 = static_cast< int >( p1.y + 0.5 );
		int x2 = static_cast< int >( p2.x + 0.5 );
		int y2 = static_cast< int >( p2.y + 0.5 );

		mist::draw_line( orginal_img, x1, y1, x2, y2, mist::colors< pixel_type >::red( ) );
	}

	write_image( orginal_img, "output.png" );

	return( 0 );
}
Пример #19
0
    void color_write_image(matrix<double> &grid, const colormap_func &cmap, const std::string &output_filename, bool write_save) {
        /* modifies argument! */
        scale_grid(grid);
        image_RGB color_image(grid.x(), grid.y());
        grayscale_to_rgb(grid, color_image, cmap);
        if (write_save) {
            std::cout << "saving image" << std::endl;
        }
        write_image(color_image, output_filename);

    }
Пример #20
0
bool Frame::write_main_image(const char* file_path) const
{
    assert(file_path);

    Image transformed_image(*impl->m_image);
    transform_to_output_color_space(transformed_image);

    const ImageAttributes image_attributes =
        ImageAttributes::create_default_attributes();

    return write_image(file_path, transformed_image, image_attributes);
}
Пример #21
0
bool
ImageOutput::copy_image (ImageInput *in)
{
    if (! in) {
        error ("copy_image: no input supplied");
        return false;
    }

    // Make sure the images are compatible in size
    const ImageSpec &inspec (in->spec());
    if (inspec.width != spec().width || inspec.height != spec().height || 
        inspec.depth != spec().depth || inspec.nchannels != spec().nchannels) {
        error ("Could not copy %d x %d x %d channels to %d x %d x %d channels",
               inspec.width, inspec.height, inspec.nchannels,
               spec().width, spec().height, spec().nchannels);
        return false;
    }

    // in most cases plugins don't allow to copy 0x0 images
    // but there are some exceptions (like in FITS plugin)
    // when we want to do this. Because 0x0 means there is no image
    // data in the file, we simply return true so the application thought
    // that everything went right.
    if (! spec().image_bytes())
        return true;

    if (spec().deep) {
        // Special case for ''deep'' images
        DeepData deepdata;
        bool ok = in->read_native_deep_image (deepdata);
        if (ok)
            ok = write_deep_image (deepdata);
        else
            error ("%s", in->geterror());  // copy err from in to out
        return ok;
    }

    // Naive implementation -- read the whole image and write it back out.
    // FIXME -- a smarter implementation would read scanlines or tiles at
    // a time, to minimize mem footprint.
    bool native = supports("channelformats") && inspec.channelformats.size();
    TypeDesc format = native ? TypeDesc::UNKNOWN : inspec.format;
    boost::scoped_array<char> pixels (new char [inspec.image_bytes(native)]);
    bool ok = in->read_image (format, &pixels[0]);
    if (ok)
        ok = write_image (format, &pixels[0]);
    else
        error ("%s", in->geterror());  // copy err from in to out
    return ok;
}
int openmp_2d_validate(const int n, bool write_img)
{
    cpx *in, *buf, *ref;
    setup_seq_2d(&in, &buf, &ref, n);

    openmp_const_geom_2d(FFT_FORWARD, &in, &buf, n);
    if (write_img)
        write_normalized_image("OpenMP", "freq", in, n, true);
    openmp_const_geom_2d(FFT_INVERSE, &in, &buf, n);
    if (write_img)
        write_image("OpenMP", "spat", in, n);

    double diff = diff_seq(in, ref, n);
    free_all(in, buf, ref);
    return diff < RELATIVE_ERROR_MARGIN;
}
Пример #23
0
nemo_main()
{
    imageptr iptr=NULL, optr=NULL;
    string *filename;
    stream instr, outstr;
    int i, j, i0, j0, nfiles;
    int nx, ny, nx1, ny1, ix, iy, n;

    nx = hasvalue("nx") ? getiparam("nx") : 0;
    ny = hasvalue("ny") ? getiparam("ny") : 0;
    
    filename = burststring(getparam("in")," ,\n");
    nfiles = xstrlen(filename,sizeof(string))-1;
    if (nx==0 && ny==0)
      error("Need at least one of nx= or ny=");
    else if (nx==0) {
      nx = nfiles/ny;
      dprintf(0,"nx=%d ny=%d nfiles=%d\n",nx,ny,nfiles);
      if (nfiles % ny) error("nfiles=%d/ny=%d does not divide evenly",nfiles,ny);
    } else if (ny==0) {
      ny = nfiles/nx;
      dprintf(0,"nx=%d ny=%d nfiles=%d\n",nx,ny,nfiles);
      if (nfiles % nx) error("nfiles=%d/nx=%d does not divide evenly",nfiles,nx);
    }

    for (iy=0, n=0; iy<ny; iy++) {
      for (ix=0; ix<nx; ix++, n++) {
	instr = stropen (filename[n],"r");
	read_image (instr,&iptr);               /* read image */
	strclose(instr);                        /* close image file */
	if (n==0) {
	  nx1 = Nx(iptr);
	  ny1 = Ny(iptr);
	  create_image(&optr,nx*nx1,ny*ny1);
	}
	i0 = ix*nx1;
	j0 = iy*ny1;
	for (j=0; j<ny1; j++)
	  for (i=0; i<nx1; i++)
	    MapValue(optr,i+i0,j+j0) = MapValue(iptr,i,j);
	i++;
      }
    }
    outstr = stropen(getparam("out"),"w");
    write_image(outstr,optr);
    strclose(outstr);
}
Пример #24
0
int main(void)
{
    image I;
    int i,j;
    int a,b;
    int d=0;
    float scale, dmax=0, dmin=0;
    pixel* image;

    read_image(&I,"lena.pgm");

    int D[(I.width-2)*(I.height-2)];
    image = I.pixels;
    //fill k matrix
    //fill_k_matrix(&k);
    //create D matrix
    for(b=0; b<I.height-2; b++) {
        for(a=0; a<I.width-2; a++) {
            d=-2 * (image[(b*I.width+a)+(0*I.width+0)] + image[(b*I.width+a)+(0*I.width+1)] + image[(b*I.width+a)+(1*I.width+0)] + image[(b*I.width+a)+(1*I.width+2)] + image[(b*I.width+a)+(2*I.width+1)] + image[(b*I.width+a)+(2*I.width+2)]) + 12 * image[(b*I.width+a)+(1*I.width+1)];
            //printf("%d\n\n\n", d);
            if(d<dmin)dmin=d;
            if(d>dmax)dmax=d;
            D[b*(I.width-2)+a]=d;
            image[b*I.width+a] = d;
            d=0;
        }
    }
    if(((-1)*dmin)>dmax) {
        scale = (-128.0)/dmin;
    } else {
        scale = (128.0-1.0)/dmax;
    }
    printf("%f\n\n\n",dmax);
    printf("%f\n\n\n",dmin);
    printf("%f\n\n\n", scale);
    for(b=0; b<I.height-2; b++) {
        for(a=0; a<I.width-2; a++) {
            //printf("%d\n",(signed int)image[b*I.width+a]);
            image[b*I.width+a] = (image[b*I.width+a])*scale+128;
        }
    }
    write_image(&I,"lena_negative.pgm");
    free_image(&I);

    return(0);
}
Пример #25
0
int
main (int argc, char *argv[])
{
    unsigned char *data;
    int width, height;

    if (argc != 3) {
	fprintf(stderr, "Usage: testrwimg <in> <out>\n");
	return 1;
    }

    data = read_image(argv[1], &width, &height);
    assert(data != NULL);

    write_image(argv[2], width, height, data, 3, width * 3, IMAGE_FORMAT_AUTO);

    return 0;
}
Пример #26
0
main() {
    //変数の宣言
    unsigned char image1[256][256], image2[256][256];
    int i,j,i2,j2,k,l,val;
    //ソーベルフィルタのマスク
    int gh[3][3] = {
        {-1, 0, 1},
        {-2, 0, 2},
        {-1, 0, 1}
    };
    int gv[3][3] = {
        {-1, -2, -1},
        {0, 0, 0},
        {1, 2, 1}
    };
    //処理元の画像を読み込む
    read_image(image1,65536,"lena");
    //画像の全ピクセルに処理をする
    for(i=0; i<256; i++) {
        for(j=0; j<256; j++) {
            //畳込み
            int fx=0;
            int fy=0;
            for(k=-N; k<=N; k++) {
                for(l=-N; l<=N; l++) {
                    //P'(i2,j2)を見る
                    i2=i+k;
                    j2=j+l;
                    //(i2,j2)が範囲内だったら値を足して、fx,fyを求める
                    if(!(i2<0 || i2>255 || j2<0 || j2>255)) {
                        fx+=image1[i2][j2]*gv[k+N][l+N];
                        fy+=image1[i2][j2]*gh[k+N][l+N];
                    }
                }
            }
            //gを求める
            val=sqrt(fx*fx+fy*fy);
            //gが255以上だったら、255にする
            image2[i][j] = (val>255)?255:val;
        }
    }
    //結果を書きこんでおしマイケル
    write_image(image2,65536,"out");
}
Пример #27
0
/****************************************************************************
 * Main
 */
int main(int argc, char** argv)
{
	size_t length;
	unsigned char *data;
	image_t image = {0};
	char* filename;

	if (argc <= 1) {
		fprintf(stderr,
			"unmakelev -- a program for converting levels from\n"
			"             the cavern flying game Wings.\n"
			"\n"
			"Usage: unmakelev <levelfile>\n");
		return 1;
	}
	
	/* Load the file given */
	data = load_file(argv[1], &length);

	if (data == NULL) {
		fprintf(stderr, "Failed to load data.\n");
		return 1;
	}
	
	/* Convert it to an image */
	if (analyze(data, length, &image)) {
		fprintf(stderr, "Analyzing data failed.\n");
		xfree(data);
		return 1;
	}
	xfree(data);

	/* Write the image */
	filename = xmalloc(strlen(argv[1]) + 4 + 1);
	strcpy(filename, argv[1]);
	strcat(filename, ".bmp");
	write_image(&image, filename);

	/* Free image pixels */
	xfree(image.pixels);

	/* All done */
	return 0;
}
Пример #28
0
/*
 * Main entry point.
 */
int main(int argc, char **argv)
{
    PDS_callbacks callbacks;
    PDS_payload payload;

    char *buffer;
    size_t size;

    int ret;

    if(4 != argc)
    {
        usage();
        return EXIT_FAILURE;
    }

	g_image_string = argv[1];

    if(!buffer_from_file(argv[2], &buffer, &size))
    {
        return EXIT_FAILURE;
    }

    memset(&payload, 0, sizeof(PDS_payload));

    PDS_set_error_callback(&callbacks, print_error);
    PDS_set_scalar_callback(&callbacks, parse_scalar);
    PDS_set_attribute_callbacks(&callbacks, parse_attribute_begin, parse_attribute_end);
    PDS_set_pointer_callbacks(&callbacks, parse_pointer_begin, parse_pointer_end);
    PDS_set_set_callbacks(&callbacks, dummy_begin_end, dummy_begin_end);
    PDS_set_sequence_callbacks(&callbacks, dummy_begin_end, dummy_begin_end);
    PDS_set_group_callbacks(&callbacks, group_begin, group_end);
    PDS_set_object_callbacks(&callbacks, object_begin, object_end);

    ret = PDS_parse(&callbacks, buffer, (int)size, &payload);
    if(ret)
    {
        ret = write_image(argv[3], buffer, size, (payload.image_record-1) * payload.record_size, &payload.image);
    }

    free(buffer);
    return ret ? EXIT_SUCCESS : EXIT_FAILURE;
}
Пример #29
0
static void flip_page(struct vo *vo)
{
    struct priv *p = vo->priv;

    (p->frame)++;

    void *t = talloc_new(NULL);
    char *filename = talloc_asprintf(t, "%08d.%s", p->frame,
                                     image_writer_file_ext(p->opts));

    if (p->outdir && strlen(p->outdir))
        filename = mp_path_join(t, bstr0(p->outdir), bstr0(filename));

    MP_INFO(vo, "Saving %s\n", filename);
    write_image(p->current, p->opts, filename, vo->log);

    talloc_free(t);
    mp_image_unrefp(&p->current);
}
Пример #30
0
/* This is for debugging purposes only. */
void
floatmap_write (image_t *img, const char *filename)
{
    unsigned char *data;
    int i;

    g_assert(img->type == IMAGE_FLOATMAP);

    data = g_malloc(3 * img->pixel_width * img->pixel_height);
    for (i = 0; i < img->pixel_width * img->pixel_height; ++i)
    {
	data[i * 3 + 0] = FLOATMAP_VALUE_I(img, i, 0) * 255.0;
	data[i * 3 + 1] = FLOATMAP_VALUE_I(img, i, 1) * 255.0;
	data[i * 3 + 2] = FLOATMAP_VALUE_I(img, i, 2) * 255.0;
    }

    write_image(filename, img->pixel_width, img->pixel_height, data, 3, 3 * img->pixel_width, IMAGE_FORMAT_PNG);

    g_free(data);
}