Image-Sane

 view release on metacpan or  search on metacpan

Sane.xs  view on Meta::CPAN

       		SV* sv = get_sv("Image::Sane::DEBUG", FALSE);
               	if (SvTRUE(sv)) printf("Closing SANE_Handle %p\n", (void *) handle);
		sane_close(handle);

void
sane__open(name)
		SANE_String_Const	name
	INIT:
		SANE_Status		status;
                SANE_Handle		h;
        PPCODE:
        	status = sane_open(name, &h);
		SV* sv = get_sv("Image::Sane::DEBUG", FALSE);
		if (SvTRUE(sv)) printf("sane_open returned SANE_Handle %p\n", (void *) h);
                PUSHMARK(sp);
	        XPUSHs(sv_2mortal(newSViv(status)));
                if (!status)
	                XPUSHs(sv_2mortal(newSViv(PTR2IV(h))));
                PUTBACK;

void
sane_get_option_descriptor (h, n)
		SANE_Handle	h
		SANE_Int	n
	INIT:
		const SANE_Option_Descriptor *	opt;
               	HV* chv = (HV*) sv_2mortal((SV*) newHV());
               	AV* cav = (AV*) sv_2mortal((SV*) newAV());
               	HV* hv = (HV*) sv_2mortal((SV*) newHV());
                int i;
        PPCODE:
       		SV* sv = get_sv("Image::Sane::DEBUG", FALSE);
               	if (SvTRUE(sv)) printf("Getting option description %d from SANE_Handle %p\n", n, (void *) h);
		opt = sane_get_option_descriptor (h, n);
                if (!opt) croak("Error getting sane_get_option_descriptor");
		if (opt->name != NULL) {
			hv_store(hv, "name", 4, newSVpv(opt->name, 0), 0);
		}
		if (opt->title != NULL) {
			hv_store(hv, "title", 5, newSVpv(opt->title, 0), 0);
		}

Sane.xs  view on Meta::CPAN

                PUTBACK;

void
sane__get_option (h, n)
		SANE_Handle	h
		SANE_Int	n
	INIT:
		SANE_Status	status;
		void *		value;
		const SANE_Option_Descriptor *	opt;
        PPCODE:
       		SV* sv = get_sv("Image::Sane::DEBUG", FALSE);
               	if (SvTRUE(sv)) printf("Getting option %d from SANE_Handle %p\n", n, (void *) h);
		opt = sane_get_option_descriptor (h, n);
                if (!opt) croak("Error getting sane_get_option_descriptor");
                if ( opt->size == 0 ) {
                        XSRETURN_UNDEF;
                        return;
                }
		value = malloc (opt->size);
		if (!value) croak("Error allocating memory");

Sane.xs  view on Meta::CPAN

                PUTBACK;
		free (value);

void
sane__set_auto (h, n)
		SANE_Handle	h
		SANE_Int	n
	INIT:
		SANE_Status	status;
		SANE_Int	info = 0;
        PPCODE:
       		SV* sv = get_sv("Image::Sane::DEBUG", FALSE);
               	if (SvTRUE(sv)) printf("Setting option %d to automatic on SANE_Handle %p\n", n, (void *) h);
		status = sane_control_option (h, n, SANE_ACTION_SET_AUTO, 0, &info);
                PUSHMARK(sp);
	        XPUSHs(sv_2mortal(newSViv(status)));
                XPUSHs(sv_2mortal(newSViv(info)));
                PUTBACK;

void
sane__set_option (h, n, value)

Sane.xs  view on Meta::CPAN

		SANE_Status	status;
		SANE_Int	info = 0;
		void *		valuep = &info; /* dummy assignment to avoid warning */
		const SANE_Option_Descriptor *	opt;
		SANE_Bool	b;
		SANE_Fixed      fixed;
		int		i, vector_length = 0;
		SV **		svp;
		SANE_Word *	vector;
		char *		string;
        PPCODE:
       		SV* sv = get_sv("Image::Sane::DEBUG", FALSE);
               	if (SvTRUE(sv)) printf("Setting option %d on SANE_Handle %p\n", n, (void *) h);
		opt = sane_get_option_descriptor (h, n);
                if (!opt) croak("Error getting sane_get_option_descriptor");
		switch (opt->type) {
			case SANE_TYPE_BOOL:
				b = (SANE_Bool)SvIV(value);
				valuep = &b;
				break;
			case SANE_TYPE_INT:

Sane.xs  view on Meta::CPAN

        OUTPUT:
                RETVAL

void
sane__get_parameters (handle)
		SANE_Handle		handle
	INIT:
		SANE_Status		status;
		SANE_Parameters		params;
               	HV* hv = (HV*) sv_2mortal((SV*) newHV());
        PPCODE:
       		SV* sv = get_sv("Image::Sane::DEBUG", FALSE);
               	if (SvTRUE(sv)) printf("Getting parameters for SANE_Handle %p\n", (void *) handle);
		status = sane_get_parameters (handle, &params);
                PUSHMARK(sp);
	        XPUSHs(sv_2mortal(newSViv(status)));
                if (!status) {
			hv_store(hv, "format", 6, newSViv(params.format), 0);
			hv_store(hv, "last_frame", 10, newSViv(params.last_frame), 0);
			hv_store(hv, "bytes_per_line", 14, newSViv(params.bytes_per_line), 0);
			hv_store(hv, "pixels_per_line", 15, newSViv(params.pixels_per_line), 0);

Sane.xs  view on Meta::CPAN

                PUTBACK;

void
sane__read (handle, max_length)
		SANE_Handle	handle
		SANE_Int	max_length
	INIT:
		SANE_Status	status;
                SANE_Byte *	data;
                SANE_Int	length;
        PPCODE:
		data = malloc (max_length);
		status = sane_read (handle, data, max_length, &length);
                PUSHMARK(sp);
	        XPUSHs(sv_2mortal(newSViv(status)));
                if (!status) {
                        XPUSHs(sv_2mortal(newSVpvn((const char *) data, length)));
			XPUSHs(sv_2mortal(newSViv(length)));
                }
                PUTBACK;
                free (data);

Sane.xs  view on Meta::CPAN

                PUSHMARK(sp);
	        XPUSHs(sv_2mortal(newSViv(status)));
                PUTBACK;

void
sane__get_select_fd (handle)
		SANE_Handle	handle
	INIT:
		SANE_Status	status;
		SANE_Int	fd;
        PPCODE:
       		SV* sv = get_sv("Image::Sane::DEBUG", FALSE);
               	if (SvTRUE(sv)) printf("Getting file handle of SANE_Handle %p\n", (void *) handle);
		status = sane_get_select_fd (handle, &fd);
                PUSHMARK(sp);
	        XPUSHs(sv_2mortal(newSViv(status)));
                if (!status)
	                XPUSHs(sv_2mortal(newSViv(fd)));
                PUTBACK;


Sane.xs  view on Meta::CPAN

	newCONSTSUB(stash, "SANE_NAME_CAL_LAMP_DEN", newSVpv(SANE_NAME_CAL_LAMP_DEN, 0));
	newCONSTSUB(stash, "SANE_NAME_SCAN_LAMP_DEN", newSVpv(SANE_NAME_SCAN_LAMP_DEN, 0));
	newCONSTSUB(stash, "SANE_NAME_SELECT_LAMP_DENSITY", newSVpv(SANE_NAME_SELECT_LAMP_DENSITY, 0));
	newCONSTSUB(stash, "SANE_NAME_LAMP_OFF_AT_EXIT", newSVpv(SANE_NAME_LAMP_OFF_AT_EXIT, 0));

void
sane__init ()
	INIT:
		SANE_Status		status;
                SANE_Int		version_code;
	PPCODE:
                call_pv("Image::Sane::_exit", G_VOID|G_NOARGS);
       	        SV* sv = get_sv("Image::Sane::DEBUG", FALSE);
               	if (SvTRUE(sv)) printf("Running sane_init\n");
		status = sane_init(&version_code, NULL);
                PUSHMARK(sp);
	        XPUSHs(sv_2mortal(newSViv(status)));
                if (!status)
	                XPUSHs(sv_2mortal(newSViv(version_code)));
                PUTBACK;

Sane.xs  view on Meta::CPAN

 # 
 # 		printf ("Returned %s and %s\n\n", POPs, POPs);
 # 
 # 		PUTBACK;
 # 		FREETMPS;
 # 		LEAVE;

void
sane__get_version (version_code)
                SANE_Int	version_code
        PPCODE:
                PUSHMARK(sp);
		XPUSHs(sv_2mortal(newSViv(SANE_VERSION_MAJOR (version_code))));
		XPUSHs(sv_2mortal(newSViv(SANE_VERSION_MINOR (version_code))));
		XPUSHs(sv_2mortal(newSViv(SANE_VERSION_BUILD (version_code))));
                PUTBACK;

void
sane__get_devices (local=SANE_FALSE)
		SANE_Bool	local
	INIT:
		SANE_Status	status;
                int i;
                const SANE_Device **	device_list;
        PPCODE:
       		SV* sv = get_sv("Image::Sane::DEBUG", FALSE);
               	if (SvTRUE(sv)) printf("Running sane_get_devices\n");
                status = sane_get_devices (&device_list, local);
                PUSHMARK(sp);
	        XPUSHs(sv_2mortal(newSViv(status)));
                if (!status) {
			for (i = 0; device_list[i]; ++i) {
        	        	HV* hv = (HV*) sv_2mortal((SV*) newHV());
				hv_store(hv, "name", 4, newSVpv(device_list[i]->name, 0), 0);
				hv_store(hv, "vendor", 6, newSVpv(device_list[i]->vendor, 0), 0);



( run in 0.769 second using v1.01-cache-2.11-cpan-5511b514fd6 )