Compiling

Top Page
Attachments:
Message as email
+ (text/plain)
Delete this message
Reply to this message
Author: Michael Havens
Date:  
Subject: Compiling
I have decided to venture into new teritory. I downloaded a driver (hopefully)
for my webcam. The tar -xed file contains a bunch of c and header programs. I
need to know what to do. These are the programs that I am talking about:

knoppix@bmike1:~/Downloads/nthr cam/pwc-8.11/2.4.21$ ls
ls
pwc-ctrl.c  pwc-ioctl.h  pwc-uncompress.c  pwc.h        pwc_nala.h
pwc-if.c    pwc-misc.c   pwc-uncompress.h  pwc_kiara.h  pwc_timon.h


One that I find particularly interesting is the pwc-uncompress.c because
(though I am inexperienced) I think that it will uncompress all the other
programs contained with it; however, I am unsure. Could someone teach me what
I need to know and how to run gcc?

--
<:-)~MIKE~(-:>
pss I just read through the code and it seems as if only the .c program starts
another program. So what I am thinking is that I will have to gcc each
individual program. Is this a correct assumption?

ps The text of the 'uncompress' files follow:

/////////////////////////////////////////////////
.h~\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
/* (C) 1999-2003 Nemosoft Unv. ()

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/

/* This file is the bridge between the kernel module and the plugin; it
describes the structures and datatypes used in both modules. Any
significant change should be reflected by increasing the
pwc_decompressor_version major number.
*/
#ifndef PWC_UNCOMPRESS_H
#define PWC_UNCOMPRESS_H

#include <linux/config.h>
#include <linux/list.h>

#include "pwc.h"

#ifdef __cplusplus
extern "C" {
#endif

/* The decompressor structure.
   Every type of decompressor registers itself with the main module.
   When a device is opened, it looks up the correct compressor, and
   uses that when a compressed video mode is requested.
 */
struct pwc_decompressor
{
    int  type;        /* type of camera (645, 680, etc) */
    int  table_size;    /* memory needed */


    void (* init)(int release, void *buffer, void *table);    /* Initialization 
routine; should be called after each set_video_mode */
    void (* exit)(void);    /* Cleanup routine */
    void (* decompress)(struct pwc_coord *image, struct pwc_coord *view, struct 
pwc_coord *offset,
                            void *src, void *dst, int planar,
                        void *table, int bandlength);
    void (* lock)(void);    /* make sure module cannot be unloaded */
    void (* unlock)(void);    /* release lock on module */


    struct list_head pwcd_list;
};



/* Our structure version number. Is set to the version number major */
extern const int pwc_decompressor_version;

/* Adds decompressor to list, based on its 'type' field (which matches the
'type' field in pwc_device; ignores any double requests */
extern void pwc_register_decompressor(struct pwc_decompressor *pwcd);
/* Removes decompressor, based on the type number */
extern void pwc_unregister_decompressor(int type);
/* Returns pointer to decompressor struct, or NULL if it doesn't exist */
extern struct pwc_decompressor *pwc_find_decompressor(int type);

#ifdef CONFIG_USB_PWCX
/* If the decompressor is compiled in, we must call these manually */
extern int usb_pwcx_init(void);
extern void usb_pwcx_exit(void);
#endif

#ifdef __cplusplus
}
#endif

#endif
/////////////////////////////////////////////////
.c~\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
/* Linux driver for Philips webcam
Decompression frontend.
(C) 1999-2003 Nemosoft Unv. ()

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/*
This is where the decompression routines register and unregister
themselves. It also has a decompressor wrapper function.
*/

#include <asm/types.h>

#include "pwc.h"
#include "pwc-uncompress.h"


/* This contains a list of all registered decompressors */
static LIST_HEAD(pwc_decompressor_list);

/* Should the pwc_decompress structure ever change, we increase the
version number so that we don't get nasty surprises, or can
dynamically adjust our structure.
*/
const int pwc_decompressor_version = PWC_MAJOR;

/* Add decompressor to list, ignoring duplicates */
void pwc_register_decompressor(struct pwc_decompressor *pwcd)
{
    if (pwc_find_decompressor(pwcd->type) == NULL) {
        Trace(TRACE_PWCX, "Adding decompressor for model %d.\n", pwcd->type);
        list_add_tail(&pwcd->pwcd_list, &pwc_decompressor_list);
    }
}


/* Remove decompressor from list */
void pwc_unregister_decompressor(int type)
{
    struct pwc_decompressor *find;


    find = pwc_find_decompressor(type);
    if (find != NULL) {
        Trace(TRACE_PWCX, "Removing decompressor for model %d.\n", type);
        list_del(&find->pwcd_list);
    }
}


/* Find decompressor in list */
struct pwc_decompressor *pwc_find_decompressor(int type)
{
    struct list_head *tmp;
    struct pwc_decompressor *pwcd;


    list_for_each(tmp, &pwc_decompressor_list) {
        pwcd  = list_entry(tmp, struct pwc_decompressor, pwcd_list);
        if (pwcd->type == type)
            return pwcd;
    }
    return NULL;
}




int pwc_decompress(struct pwc_device *pdev)
{
    struct pwc_frame_buf *fbuf;
    int n, line, col, stride;
    void *yuv, *image;
    u16 *src;
    u16 *dsty, *dstu, *dstv;


    
    if (pdev == NULL)
        return -EFAULT;
#if defined(__KERNEL__) && defined(PWC_MAGIC)
    if (pdev->magic != PWC_MAGIC) {
        Err("pwc_decompress(): magic failed.\n");
        return -EFAULT;
    }
#endif


    fbuf = pdev->read_frame;
    if (fbuf == NULL)
        return -EFAULT;
    image = pdev->image_ptr[pdev->fill_image];
    if (!image)
        return -EFAULT;


    yuv = fbuf->data + pdev->frame_header_size;  /* Skip header */
    if (pdev->vbandlength == 0) {
        /* Uncompressed mode. We copy the data into the output buffer,
           using the viewport size (which may be larger than the image
           size). Unfortunately we have to do a bit of byte stuffing
           to get the desired output format/size.
         */
            /*
             * We do some byte shuffling here to go from the 
             * native format to YUV420P.
             */
            src = (u16 *)yuv;
            n = pdev->view.x * pdev->view.y;


            /* offset in Y plane */
            stride = pdev->view.x * pdev->offset.y + pdev->offset.x;
            dsty = (u16 *)(image + stride);


            /* offsets in U/V planes */
            stride = pdev->view.x * pdev->offset.y / 4 + pdev->offset.x / 2;
            dstu = (u16 *)(image + n +         stride);
            dstv = (u16 *)(image + n + n / 4 + stride);


            /* increment after each line */
            stride = (pdev->view.x - pdev->image.x) / 2; /* u16 is 2 bytes */


            for (line = 0; line < pdev->image.y; line++) {
                for (col = 0; col < pdev->image.x; col += 4) {
                    *dsty++ = *src++;
                    *dsty++ = *src++;
                    if (line & 1)
                        *dstv++ = *src++;
                    else
                        *dstu++ = *src++;
                }
                dsty += stride;
                if (line & 1)
                    dstv += (stride >> 1);
                else
                    dstu += (stride >> 1);
            }
    }
    else { 
        /* Compressed; the decompressor routines will write the data
           in planar format immediately.
         */
        if (pdev->decompressor)
            pdev->decompressor->decompress(
                &pdev->image, &pdev->view, &pdev->offset,
                yuv, image,
                1,
                pdev->decompress_data, pdev->vbandlength);
        else
            return -ENXIO; /* No such device or address: missing decompressor */
    }
    return 0;
}


/* Make sure these functions are available for the decompressor plugin
both when this code is compiled into the kernel or as as module.
*/

EXPORT_SYMBOL_NOVERS(pwc_decompressor_version);
EXPORT_SYMBOL(pwc_register_decompressor);
EXPORT_SYMBOL(pwc_unregister_decompressor);