[Prev][Next][Index][Thread]

And now..



May I present my version of the "quick and dirty" program to read
from the Quickcam.

It does everything BUT get a good picture.  :-)

--------- cut here ------------

#include <unistd.h>
#include <asm/io.h>
#include <stdio.h>

/*
 * this table is based on data captured from QuickPict via Wine.
 */

int table[]={ 
	0x0b, 0xbb, /* 187 Brightness       */
	0x11, 0xf0, /* 240 X dimension      */
	0x13, 0x50, /* 80 Y/3 (set for 320) */
	0x0d, 0x01, /* 1 ?                  */
	0x0f, 0x07, /* 7 ?                  */
	0x19, 0x68, /* 104 - Contrast       */
	0x1f, 0x64, /* 100 - WhiteBalance   */
	0x07, 0x03, /* 3 Xfermode           */
	0x0, 0x0
};

int quickcam_port = 0x378;
int status;
unsigned int buffer[320*240];

static int reset_quickcam(int port)
{
    outb(0x20, port+2);
    outb(0x75, port);
    status = inb(port);
    outb(0x0b, port+2);
    outb(0x0e, port+2);
}

static int getstatus( int port )
{
    unsigned char status1 = 0, status2 = 1;
    int count1, count2;

    outb(0x06, port+2);

    while ((status1 & 0x0f) != 0x08) {
	status1 = inb(port+1);
	count1++;
    }

    outb(0x0e, port+2);

    while ((status2 & 0x0f) != 0) {
	status2 = inb(port+1);
	count2++;
    }

    fprintf(stderr, "count1 = %d ", count1);
    fprintf(stderr, "count2 = %d ", count2);
    fprintf(stderr, "status1 = 0x%02x ", status1);
    fprintf(stderr, "status2 = 0x%02x ", status2);
    fprintf(stderr, "status = 0x%02x\n",((status1 & 0xF0) | ( status2 >> 4 )));

    return ((status1 & 0xF0 ) | ( status2 >> 4 ));

}

static int sendbyte( int port, int value)
{
   outb(value, port);
   return( getstatus(port) );
}

static int sendcmd( int cmd, int value)
{

    fprintf(stderr, "cmd = 0x%x, value = 0x%x\n", cmd, value);

    if (sendbyte(quickcam_port, cmd) != cmd )
    	return(1);
    if (sendbyte(quickcam_port, value) != value )
    	return(1);

    return 0;
}

static unsigned int getword26( int port )
{
    unsigned char word1, word2;

    outb(0x26, port+2);

#if 0
    word1 = inb(port) >> 1;
    word2 = inb(port+1) >> 3;
#else
    word1 = inb(port);
    word2 = inb(port+1);
#endif

    fprintf(stderr, "word1 = 0x%02x, word2 = 0x%02x, word26 = 0x%04x ", word1, word2, ((word2 << 8)| word1 ));

    return ((word2 << 8) | word1 );

}

static unsigned int getword2f( int port )
{
    unsigned char word1, word2;

    outb(0x2f, port+2);

#if 0
    word1 = inb(port) >> 1;
    word2 = inb(port+1) >> 3;
#else
    word1 = inb(port);
    word2 = inb(port+1);
#endif

    fprintf(stderr, "word1 = 0x%02x, word2 = 0x%02x, word2f = 0x%04x ", word1, word2, ((word2 << 8)| word1 ));

    return ((word2 << 8) | word1 );

}

main()
{
	int count=0;
	unsigned int byte;

	ioperm(0x378, 3, 1);

	reset_quickcam(quickcam_port);
	
	while ( table[count] != 0x0 & table[count+1] != 0 ) {
		sendcmd(table[count], table[count+1]);
		count += 2;
	}

	printf("P2\n320 240\n255\n");

	for ( count = 0; count < 320*240; count++) {
		byte = getword26(quickcam_port) & 0xff;
		printf("%03d ", byte );
		count++;
		byte = getword2f(quickcam_port) & 0xff;
		printf("%03d ", byte );
		fprintf(stderr, "count = %d\n", count );
		if ( ( count % 9 ) == 0 ) {
		   printf("\n");
		   fprintf(stderr, "count = 19!\n");
		}
	}

}

-- 
Thomas Davis			| Internet:	Thomas.Davis@mnscorp.com
Systems Consultant		| Snail Mail:	Suite 528
Midwest Network Solutions Corp.	| 		1941 South 42nd Street
(402) 346-7687			|		Omaha, NE 68105-2939

Follow-Ups: