Update of /cvsroot/artoolkit/artoolkit/lib/SRC/VideoLinuxV4L
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13693
Modified Files:
video.c Makefile.in
Added Files:
jpegtorgb.h ccvt_i386.S ccvt_c.c ccvt.h
Log Message:
Linux video driver updates and patches.
--- NEW FILE: ccvt.h ---
/*
(C) 2000 Nemosoft Unv. nem...@sm...
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
*/
#ifndef CCVT_H
#define CCVT_H
#ifdef __cplusplus
extern "C" {
#endif
/* Colour ConVerT: going from one colour space to another
Format descriptions:
420i = "4:2:0 interlaced"
YYYY UU YYYY UU even lines
YYYY VV YYYY VV odd lines
U/V data is subsampled by 2 both in horizontal
and vertical directions, and intermixed with the Y values.
420p = "4:2:0 planar"
YYYYYYYY N lines
UUUU N/2 lines
VVVV N/2 lines
U/V is again subsampled, but all the Ys, Us and Vs are placed
together in separate buffers. The buffers may be placed in
one piece of contiguous memory though, with Y buffer first,
followed by U, followed by V.
yuyv = "4:2:2 interlaced"
YUYV YUYV YUYV ... N lines
The U/V data is subsampled by 2 in horizontal direction only.
bgr24 = 3 bytes per pixel, in the order Blue Green Red (whoever came up
with that idea...)
rgb24 = 3 bytes per pixel, in the order Red Green Blue (which is sensible)
rgb32 = 4 bytes per pixel, in the order Red Green Blue Alpha, with
Alpha really being a filler byte (0)
bgr32 = last but not least, 4 bytes per pixel, in the order Blue Green Red
Alpha, Alpha again a filler byte (0)
*/
/* Functions in ccvt_i386.S/ccvt_c.c */
/* 4:2:0 YUV interlaced to RGB/BGR */
void ccvt_420i_bgr24(int width, int height, void *src, void *dst);
void ccvt_420i_rgb24(int width, int height, void *src, void *dst);
void ccvt_420i_bgr32(int width, int height, void *src, void *dst);
void ccvt_420i_rgb32(int width, int height, void *src, void *dst);
/* 4:2:2 YUYV interlaced to RGB/BGR */
void ccvt_yuyv_rgb32(int width, int height, void *src, void *dst);
void ccvt_yuyv_bgr32(int width, int height, void *src, void *dst);
/* 4:2:0 YUV planar to RGB/BGR */
void ccvt_420p_rgb32(int width, int height, void *srcy, void *srcu, void *srcv, void *dst);
void ccvt_420p_bgr32(int width, int height, void *srcy, void *srcu, void *srcv, void *dst);
void ccvt_420p_rgb24(int width, int height, void *srcy, void *srcu, void *srcv, void *dst);
void ccvt_420p_bgr24(int width, int height, void *srcy, void *srcu, void *srcv, void *dst);
/* RGB/BGR to 4:2:0 YUV interlaced */
/* RGB/BGR to 4:2:0 YUV planar */
void ccvt_rgb24_420p(int width, int height, void *src, void *dsty, void *dstu, void *dstv);
void ccvt_bgr24_420p(int width, int height, void *src, void *dsty, void *dstu, void *dstv);
/* Go from 420i to other yuv formats */
void ccvt_420i_420p(int width, int height, void *src, void *dsty, void *dstu, void *dstv);
void ccvt_420i_yuyv(int width, int height, void *src, void *dst);
#ifdef __cplusplus
}
#endif
#endif
--- NEW FILE: ccvt_c.c ---
/*
Colour conversion routines (RGB <-> YUV) in plain C
(C) 2000 Nemosoft Unv. nem...@sm...
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
*/
#include "ccvt.h"
#define PUSH_RGB24 1
#define PUSH_BGR24 2
#define PUSH_RGB32 3
#define PUSH_BGR32 4
/* This is a really simplistic approach. Speedups are welcomed. */
static void ccvt_420i(int width, int height, unsigned char *src, unsigned char *dst, int push)
{
int line, col, linewidth;
int y, u, v, yy, vr, ug, vg, ub;
int r, g, b;
unsigned char *py, *pu, *pv;
linewidth = width + (width >> 1);
py = src;
pu = py + 4;
pv = pu + linewidth;
y = *py++;
yy = y << 8;
u = *pu - 128;
ug = 88 * u;
ub = 454 * u;
v = *pv - 128;
vg = 183 * v;
vr = 359 * v;
/* The biggest problem is the interlaced data, and the fact that odd
add even lines have V and U data, resp.
*/
for (line = 0; line < height; line++) {
for (col = 0; col < width; col++) {
r = (yy + vr) >> 8;
g = (yy - ug - vg) >> 8;
b = (yy + ub ) >> 8;
switch(push) {
case PUSH_RGB24:
*dst++ = r;
*dst++ = g;
*dst++ = b;
break;
case PUSH_BGR24:
*dst++ = b;
*dst++ = g;
*dst++ = r;
break;
case PUSH_RGB32:
*dst++ = r;
*dst++ = g;
*dst++ = b;
*dst++ = 0;
break;
case PUSH_BGR32:
*dst++ = b;
*dst++ = g;
*dst++ = r;
*dst++ = 0;
break;
}
y = *py++;
yy = y << 8;
if ((col & 3) == 3)
py += 2; // skip u/v
if (col & 1) {
if ((col & 3) == 3) {
pu += 4; // skip y
pv += 4;
}
else {
pu++;
pv++;
}
u = *pu - 128;
ug = 88 * u;
ub = 454 * u;
v = *pv - 128;
vg = 183 * v;
vr = 359 * v;
}
} /* ..for col */
if (line & 1) { // odd line: go to next band
pu += linewidth;
pv += linewidth;
}
else { // rewind u/v pointers
pu -= linewidth;
pv -= linewidth;
}
} /* ..for line */
}
void ccvt_420i_rgb24(int width, int height, void *src, void *dst)
{
ccvt_420i(width, height, (unsigned char *)src, (unsigned char *)dst, PUSH_RGB24);
}
void ccvt_420i_bgr24(int width, int height, void *src, void *dst)
{
ccvt_420i(width, height, (unsigned char *)src, (unsigned char *)dst, PUSH_BGR24);
}
void ccvt_420i_rgb32(int width, int height, void *src, void *dst)
{
ccvt_420i(width, height, (unsigned char *)src, (unsigned char *)dst, PUSH_RGB32);
}
void ccvt_420i_bgr32(int width, int height, void *src, void *dst)
{
ccvt_420i(width, height, (unsigned char *)src, (unsigned char *)dst, PUSH_BGR32);
}
void ccvt_420i_420p(int width, int height, void *src, void *dsty, void *dstu, void *dstv)
{
short *s, *dy, *du, *dv;
int line, col;
s = (short *)src;
dy = (short *)dsty;
du = (short *)dstu;
dv = (short *)dstv;
for (line = 0; line < height; line++) {
for (col = 0; col < width; col += 4) {
*dy++ = *s++;
*dy++ = *s++;
if (line & 1)
*dv++ = *s++;
else
*du++ = *s++;
} /* ..for col */
} /* ..for line */
}
void ccvt_420i_yuyv(int width, int height, void *src, void *dst)
{
int line, col, linewidth;
unsigned char *py, *pu, *pv, *d;
linewidth = width + (width >> 1);
py = (unsigned char *)src;
pu = src + 4;
pv = pu + linewidth;
d = (unsigned char *)dst;
for (line = 0; line < height; line++) {
for (col = 0; col < width; col += 4) {
/* four pixels in one go */
*d++ = *py++;
*d++ = *pu++;
*d++ = *py++;
*d++ = *pv++;
*d++ = *py++;
*d++ = *pu++;
*d++ = *py++;
*d++ = *pv++;
py += 2;
pu += 4;
pv += 4;
} /* ..for col */
if (line & 1) { // odd line: go to next band
pu += linewidth;
pv += linewidth;
}
else { // rewind u/v pointers
pu -= linewidth;
pv -= linewidth;
}
} /* ..for line */
}
Index: video.c
===================================================================
RCS file: /cvsroot/artoolkit/artoolkit/lib/SRC/VideoLinuxV4L/video.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -d -r1.1.1.1 -r1.2
*** video.c 4 Nov 2004 08:51:50 -0000 1.1.1.1
--- video.c 22 Nov 2004 02:32:40 -0000 1.2
***************
*** 4,8 ****
Hirokazu Kato ( ka...@sy... )
*
! * Revision: 5.2 Date: 2000/08/25
*/
#include <sys/ioctl.h>
--- 4,16 ----
Hirokazu Kato ( ka...@sy... )
*
! * Revision: 5.3 Date: 2004/11/18
! * Rev Date Who Changes
! * 5.3 2004-11-18 RG -adding patch done by Uwe Woessner for YUV support on V4L.
! * (Thanks a lot for this contribution !!)
! * -modify default video options
! * (no overhead if define externally)
! * -adding full V4L options support
! * -adding eyetoy support
! *
*/
#include <sys/ioctl.h>
***************
*** 20,23 ****
--- 28,35 ----
#include <AR/ar.h>
#include <AR/video.h>
+ #include "ccvt.h"
+ #ifdef USE_EYETOY
+ #include "jpegtorgb.h"
+ #endif
#define MAXCHANNEL 10
***************
*** 94,113 ****
printf("ARVideo may be configured using one or more of the following options,\n");
printf("separated by a space:\n\n");
printf(" -width=N\n");
printf(" specifies expected width of image.\n");
printf(" -height=N\n");
printf(" specifies expected height of image.\n");
! printf(" -contrast=N\n");
! printf(" specifies contrast. (0.0 <-> 1.0)\n");
printf(" -brightness=N\n");
printf(" specifies brightness. (0.0 <-> 1.0)\n");
printf(" -color=N\n");
! printf(" specifies color. (0.0 <-> 1.0)\n");
! printf(" -channel=N\n");
! printf(" specifies source channel.\n");
! printf(" -dev=filepath\n");
! printf(" specifies device file.\n");
printf(" -mode=[PAL|NTSC|SECAM]\n");
! printf(" specifies TV signal mode.\n");
printf("\n");
--- 106,136 ----
printf("ARVideo may be configured using one or more of the following options,\n");
printf("separated by a space:\n\n");
+ printf("DEVICE CONTROLS:\n");
+ printf(" -dev=filepath\n");
+ printf(" specifies device file.\n");
+ printf(" -channel=N\n");
+ printf(" specifies source channel.\n");
printf(" -width=N\n");
printf(" specifies expected width of image.\n");
printf(" -height=N\n");
printf(" specifies expected height of image.\n");
! printf(" -palette=[RGB|YUV420P]\n");
! printf(" specifies the camera palette (WARNING:all are not supported on each camera !!).\n");
! printf("IMAGE CONTROLS (WARNING: every options are not supported by all camera !!):\n");
printf(" -brightness=N\n");
printf(" specifies brightness. (0.0 <-> 1.0)\n");
+ printf(" -contrast=N\n");
+ printf(" specifies contrast. (0.0 <-> 1.0)\n");
+ printf(" -saturation=N\n");
+ printf(" specifies saturation (color). (0.0 <-> 1.0) (for color camera only)\n");
+ printf(" -hue=N\n");
+ printf(" specifies hue. (0.0 <-> 1.0) (for color camera only)\n");
+ printf(" -whiteness=N\n");
+ printf(" specifies whiteness. (0.0 <-> 1.0) (REMARK: gamma for some drivers, otherwise for greyscale camera only)\n");
printf(" -color=N\n");
! printf(" specifies saturation (color). (0.0 <-> 1.0) (REMARK: obsolete !! use saturation control)\n\n");
! printf("OPTION CONTROLS:\n");
printf(" -mode=[PAL|NTSC|SECAM]\n");
! printf(" specifies TV signal mode (for tv/capture card).\n");
printf("\n");
***************
*** 126,137 ****
arMalloc( vid, AR2VideoParamT, 1 );
strcpy( vid->dev, DEFAULT_VIDEO_DEVICE );
vid->width = DEFAULT_VIDEO_WIDTH;
vid->height = DEFAULT_VIDEO_HEIGHT;
! vid->channel = DEFAULT_VIDEO_CHANNEL;
vid->mode = DEFAULT_VIDEO_MODE;
vid->debug = 0;
! vid->contrast = 0.5;
! vid->brightness = 0.5;
! vid->color = 0.5;
a = config;
--- 149,168 ----
arMalloc( vid, AR2VideoParamT, 1 );
strcpy( vid->dev, DEFAULT_VIDEO_DEVICE );
+ vid->channel = DEFAULT_VIDEO_CHANNEL;
vid->width = DEFAULT_VIDEO_WIDTH;
vid->height = DEFAULT_VIDEO_HEIGHT;
! #if defined(AR_PIX_FORMAT_BGRA)
! vid->palette = VIDEO_PALETTE_RGB32; /* palette format */
! #elif defined(AR_PIX_FORMAT_BGR) || defined(AR_PIX_FORMAT_RGB)
! vid->palette = VIDEO_PALETTE_RGB24; /* palette format */
! #endif
! vid->contrast = -1.;
! vid->brightness = -1.;
! vid->saturation = -1.;
! vid->hue = -1.;
! vid->whiteness = -1.;
vid->mode = DEFAULT_VIDEO_MODE;
vid->debug = 0;
! vid->videoBuffer=NULL;
a = config;
***************
*** 140,145 ****
while( *a == ' ' || *a == '\t' ) a++;
if( *a == '\0' ) break;
!
! if( strncmp( a, "-width=", 7 ) == 0 ) {
sscanf( a, "%s", line );
if( sscanf( &line[7], "%d", &vid->width ) == 0 ) {
--- 171,191 ----
while( *a == ' ' || *a == '\t' ) a++;
if( *a == '\0' ) break;
! if( strncmp( a, "-dev=", 5 ) == 0 ) {
! sscanf( a, "%s", line );
! if( sscanf( &line[5], "%s", vid->dev ) == 0 ) {
! ar2VideoDispOption();
! free( vid );
! return 0;
! }
! }
! else if( strncmp( a, "-channel=", 9 ) == 0 ) {
! sscanf( a, "%s", line );
! if( sscanf( &line[9], "%d", &vid->channel ) == 0 ) {
! ar2VideoDispOption();
! free( vid );
! return 0;
! }
! }
! else if( strncmp( a, "-width=", 7 ) == 0 ) {
sscanf( a, "%s", line );
if( sscanf( &line[7], "%d", &vid->width ) == 0 ) {
***************
*** 157,160 ****
--- 203,218 ----
}
}
+ else if( strncmp( a, "-palette=", 9 ) == 0 ) {
+ if( strncmp( &a[9], "RGB", 3) == 0 ) {
+ #if defined(AR_PIX_FORMAT_BGRA)
+ vid->palette = VIDEO_PALETTE_RGB32; /* palette format */
+ #elif defined(AR_PIX_FORMAT_BGR)|| defined(AR_PIX_FORMAT_RGB)
+ vid->palette = VIDEO_PALETTE_RGB24; /* palette format */
+ #endif
+ }
+ else if( strncmp( &a[9], "YUV420P", 7 ) == 0 ) {
+ vid->palette = VIDEO_PALETTE_YUV420P;
+ }
+ }
else if( strncmp( a, "-contrast=", 10 ) == 0 ) {
sscanf( a, "%s", line );
***************
*** 173,187 ****
}
}
! else if( strncmp( a, "-color=", 7 ) == 0 ) {
sscanf( a, "%s", line );
! if( sscanf( &line[7], "%lf", &vid->color ) == 0 ) {
ar2VideoDispOption();
free( vid );
return 0;
}
! }
! else if( strncmp( a, "-channel=", 9 ) == 0 ) {
sscanf( a, "%s", line );
! if( sscanf( &line[9], "%d", &vid->channel ) == 0 ) {
ar2VideoDispOption();
free( vid );
--- 231,253 ----
}
}
! else if( strncmp( a, "-saturation=", 12 ) == 0 ) {
sscanf( a, "%s", line );
! if( sscanf( &line[12], "%lf", &vid->saturation ) == 0 ) {
ar2VideoDispOption();
free( vid );
return 0;
}
! }
! else if( strncmp( a, "-hue=", 5 ) == 0 ) {
sscanf( a, "%s", line );
! if( sscanf( &line[5], "%lf", &vid->hue ) == 0 ) {
! ar2VideoDispOption();
! free( vid );
! return 0;
! }
! }
! else if( strncmp( a, "-whiteness=", 11 ) == 0 ) {
! sscanf( a, "%s", line );
! if( sscanf( &line[11], "%lf", &vid->whiteness ) == 0 ) {
ar2VideoDispOption();
free( vid );
***************
*** 189,195 ****
}
}
! else if( strncmp( a, "-dev=", 5 ) == 0 ) {
sscanf( a, "%s", line );
! if( sscanf( &line[5], "%s", vid->dev ) == 0 ) {
ar2VideoDispOption();
free( vid );
--- 255,261 ----
}
}
! else if( strncmp( a, "-color=", 7 ) == 0 ) {
sscanf( a, "%s", line );
! if( sscanf( &line[7], "%lf", &vid->saturation ) == 0 ) {
ar2VideoDispOption();
free( vid );
***************
*** 220,224 ****
}
! vid->fd = open(vid->dev, O_RDWR);
if(vid->fd < 0){
printf("video device (%s) open failed\n",vid->dev);
--- 286,290 ----
}
! vid->fd = open(vid->dev, O_RDWR);// O_RDONLY ?
if(vid->fd < 0){
printf("video device (%s) open failed\n",vid->dev);
***************
*** 299,319 ****
}
/* set video picture */
! vp.brightness = 32767 * 2.0 * vid->brightness;
! vp.hue = 32767;
! vp.colour = 32767 * 2.0 * vid->color;
! vp.contrast = 32767 * 2.0 * vid->contrast;
! vp.whiteness = 32767;
! vp.depth = 24; /* color depth */
! #if defined(AR_PIX_FORMAT_BGRA)
! vp.palette = VIDEO_PALETTE_RGB32; /* palette format */
! #elif defined(AR_PIX_FORMAT_BGR)
! vp.palette = VIDEO_PALETTE_RGB24; /* palette format */
! #endif
if(ioctl(vid->fd, VIDIOCSPICT, &vp)) {
! printf("error: setting palette\n");
free( vid );
return 0;
}
/* get mmap info */
--- 365,422 ----
}
+ if(ioctl(vid->fd, VIDIOCGPICT, &vp)) {
+ printf("error: getting palette\n");
+ free( vid );
+ return 0;
+ }
+
+ if( vid->debug ) {
+ printf("=== debug info ===\n");
+ printf(" vp.brightness= %d\n",vp.brightness);
+ printf(" vp.hue = %d\n",vp.hue);
+ printf(" vp.colour = %d\n",vp.colour);
+ printf(" vp.contrast = %d\n",vp.contrast);
+ printf(" vp.whiteness = %d\n",vp.whiteness);
+ printf(" vp.depth = %d\n",vp.depth);
+ printf(" vp.palette = %d\n",vp.palette);
+ }
+
/* set video picture */
! if ((vid->brightness+1.)>0.001)
! vp.brightness = 32767 * 2.0 *vid->brightness;
! if ((vid->contrast+1.)>0.001)
! vp.contrast = 32767 * 2.0 *vid->contrast;
! if ((vid->hue+1.)>0.001)
! vp.hue = 32767 * 2.0 *vid->hue;
! if ((vid->whiteness+1.)>0.001)
! vp.whiteness = 32767 * 2.0 *vid->whiteness;
! if ((vid->saturation+1.)>0.001)
! vp.colour = 32767 * 2.0 *vid->saturation;
! vp.depth = 24;
! vp.palette = vid->palette;
!
if(ioctl(vid->fd, VIDIOCSPICT, &vp)) {
! printf("error: setting configuration !! bad palette mode..\n TIPS:try other palette mode (or with new failure contact ARToolKit Developer)\n");
free( vid );
return 0;
}
+ if (vid->palette==VIDEO_PALETTE_YUV420P)
+ arMalloc( vid->videoBuffer, ARUint8, vid->width*vid->height*3 );
+
+ if( vid->debug ) {
+ if(ioctl(vid->fd, VIDIOCGPICT, &vp)) {
+ printf("error: getting palette\n");
+ free( vid );
+ return 0;
+ }
+ printf("=== debug info ===\n");
+ printf(" vp.brightness= %d\n",vp.brightness);
+ printf(" vp.hue = %d\n",vp.hue);
+ printf(" vp.colour = %d\n",vp.colour);
+ printf(" vp.contrast = %d\n",vp.contrast);
+ printf(" vp.whiteness = %d\n",vp.whiteness);
+ printf(" vp.depth = %d\n",vp.depth);
+ printf(" vp.palette = %d\n",vp.palette);
+ }
/* get mmap info */
***************
*** 348,359 ****
vid->vmm.width = vid->width;
vid->vmm.height = vid->height;
! #if defined(AR_PIX_FORMAT_BGRA)
! vid->vmm.format = VIDEO_PALETTE_RGB32;
! #elif defined(AR_PIX_FORMAT_BGR)
! vid->vmm.format = VIDEO_PALETTE_RGB24;
! #endif
vid->video_cont_num = -1;
return vid;
}
--- 451,461 ----
vid->vmm.width = vid->width;
vid->vmm.height = vid->height;
! vid->vmm.format= vid->palette;
vid->video_cont_num = -1;
+ #ifdef USE_EYETOY
+ JPEGToRGBInit(vid->width,vid->height);
+ #endif
return vid;
}
***************
*** 365,368 ****
--- 467,472 ----
}
close(vid->fd);
+ if(vid->videoBuffer!=NULL)
+ free(vid->videoBuffer);
free( vid );
***************
*** 422,425 ****
--- 526,531 ----
ARUint8 *ar2VideoGetImage( AR2VideoParamT *vid )
{
+ ARUint8 *buf;
+
if(vid->video_cont_num < 0){
printf("arVideoCapStart has never been called.\n");
***************
*** 434,440 ****
if(vid->video_cont_num == 0)
! return (vid->map + vid->vm.offsets[1]);
else
! return (vid->map + vid->vm.offsets[0]);
}
--- 540,561 ----
if(vid->video_cont_num == 0)
! buf=(vid->map + vid->vm.offsets[1]);
else
! buf=(vid->map + vid->vm.offsets[0]);
!
! if(vid->palette == VIDEO_PALETTE_YUV420P)
! {
!
! ccvt_420p_bgr24(vid->width, vid->height, buf, buf+(vid->width*vid->height),
! buf+(vid->width*vid->height)+(vid->width*vid->height)/4,
! vid->videoBuffer);
! return vid->videoBuffer;
! }
! #ifdef USE_EYETOY
! buf=JPEGToRGB(buf,vid->width, vid->height);
! #endif
!
! return buf;
!
}
Index: Makefile.in
===================================================================
RCS file: /cvsroot/artoolkit/artoolkit/lib/SRC/VideoLinuxV4L/Makefile.in,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -d -r1.1.1.1 -r1.2
*** Makefile.in 4 Nov 2004 08:51:49 -0000 1.1.1.1
--- Makefile.in 22 Nov 2004 02:32:40 -0000 1.2
***************
*** 22,26 ****
# compilation control
#
! LIBOBJS= ${LIB}(video.o)
all: ${LIBOBJS}
--- 22,26 ----
# compilation control
#
! LIBOBJS= ${LIB}(video.o) ${LIB}(ccvt_i386.o)
all: ${LIBOBJS}
***************
*** 33,36 ****
--- 33,42 ----
rm -f $*.o
+ .S.a:
+ ${CC} -c ${CFLAG} $<
+ ${AR} ${ARFLAGS} $@ $*.o
+ rm -f $*.o
+
+
clean:
rm -f *.o
--- NEW FILE: ccvt_i386.S ---
/*
Colour conversion routines (RGB <-> YUV) in x86 assembly
(C) 2000 Nemosoft Unv. nem...@sm...
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.
[...1194 lines suppressed...]
pop %eax # y3y2y1y0
# Second half
shr $8, %eax # __y3y2y1
shr $8, %ax # __y3__y2
and $0xff00ff00, %edx # v1__u1__
or %edx, %eax # v1y3u1y2
stosl
loop 1b
decl Height # height--
jnz 0b
# Done
9: pop %edi
pop %esi
pop %ebx
leave
ret
--- NEW FILE: jpegtorgb.h ---
/* JPEG To RGB interface --Raphael Grasset - 04/07/16 - 2004 Hitlab NZ. All Rights reserved--
This file define simple routine functions for converting a JPEG image to RGB format.
It use is ONLY for EyeToy Camera.
WARNING : It use a static image area : at each call of conversion, the new
image is copying on the same memory area (limited dynamic allocation mamagement).
So be careful when you manipulating the pointer on the image !!
USAGE :
Based on libjpeg (providing hardware decompression), you need just add few things on your code:
#include "jpegtorgb.h" //this file
int xsiwe=640;//video image format
int ysize=480;//video image format
....
JPEGToRGBInit(xsize,ysize); //init function with image size in parameters
....
ARUint8* decompressed_image=JPEGToRGB(video_image,xsize,ysize); //converting function (converted image return)
don't be care with ARUint8, equivalent to an unsigned char format.
*/
#include "jpeglib.h"
#include "jerror.h"
#include <setjmp.h>
/*---------------- Direct Input Functions for libjpeg --------------*/
/* we overload the interface for open a jpeg file : the libjpeg
file is limited for only FILE* input. Since we have a JPEG image
in memory we need a new interface for libjpeg. For these we overload
differents functions.
I have modified the code for jpeg_stdio_src, and providing
new functions name EyeToy_XXX (XXX template
Need to be optimized, cleaned.
*/
#define JFREAD(file,buf,sizeofbuf) \
((size_t) fread((void *) (buf), (size_t) 1, (size_t) (sizeofbuf), (file)))
/* Expanded data source object for stdio input */
typedef struct {
struct jpeg_source_mgr pub; /* public fields */
unsigned char* image;
int image_size;
JOCTET * buffer; /* start of buffer */
boolean start_of_file; /* have we gotten any data yet? */
} my_source_mgr;
typedef my_source_mgr * my_src_ptr;
#define INPUT_BUF_SIZE 4096 /* choose an efficiently fread'able size */
/*
* Initialize source --- called by jpeg_read_header
* before any data is actually read.
*/
METHODDEF(void)
EyeToy_init_source (j_decompress_ptr cinfo)
{
my_src_ptr src = (my_src_ptr) cinfo->src;
/* We reset the empty-input-file flag for each image,
* but we don't clear the input buffer.
* This is correct behavior for reading a series of images from one source.
*/
src->start_of_file = TRUE;
}
/*
* Fill the input buffer --- called whenever buffer is emptied.
*
* In typical applications, this should read fresh data into the buffer
* (ignoring the current state of next_input_byte & bytes_in_buffer),
* reset the pointer & count to the start of the buffer, and return TRUE
* indicating that the buffer has been reloaded. It is not necessary to
* fill the buffer entirely, only to obtain at least one more byte.
*
* There is no such thing as an EOF return. If the end of the file has been
* reached, the routine has a choice of ERREXIT() or inserting fake data into
* the buffer. In most cases, generating a warning message and inserting a
* fake EOI marker is the best course of action --- this will allow the
* decompressor to output however much of the image is there. However,
* the resulting error message is misleading if the real problem is an empty
* input file, so we handle that case specially.
*
* In applications that need to be able to suspend compression due to input
* not being available yet, a FALSE return indicates that no more data can be
* obtained right now, but more may be forthcoming later. In this situation,
* the decompressor will return to its caller (with an indication of the
* number of scanlines it has read, if any). The application should resume
* decompression after it has loaded more data into the input buffer. Note
* that there are substantial restrictions on the use of suspension --- see
* the documentation.
*
* When suspending, the decompressor will back up to a convenient restart point
* (typically the start of the current MCU). next_input_byte & bytes_in_buffer
* indicate where the restart point will be if the current call returns FALSE.
* Data beyond this point must be rescanned after resumption, so move it to
* the front of the buffer rather than discarding it.
*/
METHODDEF(boolean)
EyeToy_fill_input_buffer (j_decompress_ptr cinfo)
{
my_src_ptr src = (my_src_ptr) cinfo->src;
src->pub.next_input_byte = src->image;
src->pub.bytes_in_buffer = src->image_size;
src->start_of_file = FALSE;
return TRUE;
}
/*
* Skip data --- used to skip over a potentially large amount of
* uninteresting data (such as an APPn marker).
*
* Writers of suspendable-input applications must note that skip_input_data
* is not granted the right to give a suspension return. If the skip extends
* beyond the data currently in the buffer, the buffer can be marked empty so
* that the next read will cause a fill_input_buffer call that can suspend.
* Arranging for additional bytes to be discarded before reloading the input
* buffer is the application writer's problem.
*/
METHODDEF(void)
EyeToy_skip_input_data (j_decompress_ptr cinfo, long num_bytes)
{
my_src_ptr src = (my_src_ptr) cinfo->src;
/* Just a dumb implementation for now. Could use fseek() except
* it doesn't work on pipes. Not clear that being smart is worth
* any trouble anyway --- large skips are infrequent.
*/
if (num_bytes > 0) {
while (num_bytes > (long) src->pub.bytes_in_buffer) {
num_bytes -= (long) src->pub.bytes_in_buffer;
(void) EyeToy_fill_input_buffer(cinfo);
/* note we assume that fill_input_buffer will never return FALSE,
* so suspension need not be handled.
*/
}
src->pub.next_input_byte += (size_t) num_bytes;
src->pub.bytes_in_buffer -= (size_t) num_bytes;
}
}
/*
* An additional method that can be provided by data source modules is the
* resync_to_restart method for error recovery in the presence of RST markers.
* For the moment, this source module just uses the default resync method
* provided by the JPEG library. That method assumes that no backtracking
* is possible.
*/
/*
* Terminate source --- called by jpeg_finish_decompress
* after all data has been read. Often a no-op.
*
* NB: *not* called by jpeg_abort or jpeg_destroy; surrounding
* application must deal with any cleanup that should happen even
* for error exit.
*/
METHODDEF(void)
EyeToy_term_source (j_decompress_ptr cinfo)
{
/* no work necessary here */
}
/*
The new jpeg access function : directly read the memory
buffer instead of a FILE* input. Since all the image
is in memory we put all the buffer in one pass.
*/
GLOBAL(void)
EyeToy_jpeg_stdio_src(j_decompress_ptr cinfo,unsigned char *image,int count)
{
my_src_ptr src;
/* The source object and input buffer are made permanent so that a series
* of JPEG images can be read from the same file by calling jpeg_stdio_src
* only before the first one. (If we discarded the buffer at the end of
* one image, we'd likely lose the start of the next one.)
* This makes it unsafe to use this manager and a different source
* manager serially with the same JPEG object. Caveat programmer.
*/
if (cinfo->src == NULL) { /* first time for this JPEG object? */
cinfo->src = (struct jpeg_source_mgr *)(*cinfo->mem->alloc_small)((j_common_ptr) cinfo, JPOOL_PERMANENT,
sizeof(my_source_mgr));
src = (my_src_ptr) cinfo->src;
src->buffer = (JOCTET *)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT, INPUT_BUF_SIZE * sizeof(JOCTET));
}
src = (my_src_ptr) cinfo->src;
src->pub.init_source = EyeToy_init_source;
src->pub.fill_input_buffer = EyeToy_fill_input_buffer;
src->pub.skip_input_data = EyeToy_skip_input_data;
src->pub.resync_to_restart = jpeg_resync_to_restart; /* use default method */
src->pub.term_source = EyeToy_term_source;
src->image=image;
src->image_size=count;
src->pub.bytes_in_buffer = 0; /* forces fill_input_buffer on first read */
src->pub.next_input_byte = NULL; /* until buffer loaded */
}
static ARUint8* TransfertBufferImage;
/*---------------- Main Functions --------------*/
void JPEGToRGBInit(int xsize,int ysize)
{
TransfertBufferImage = malloc(xsize*ysize*3);
}
ARUint8* JPEGToRGB(ARUint8* image, int xsize,int ysize)
{
int image_height=xsize; /* Number of rows in image */
int image_width=ysize; /* Number of columns in image */
struct jpeg_error_mgr jerr;
struct jpeg_decompress_struct cinfo;
JSAMPROW row_pointer[1]; /* pointer to JSAMPLE row[s] */
int row_stride; /* physical row width in output buffer */
int crows=0;
cinfo.err = jpeg_std_error(&jerr);
jpeg_create_decompress(&cinfo);
ssize_t count;
count=(image[0]+image[1]*65536)/8;
EyeToy_jpeg_stdio_src(&cinfo,image+2,count);
(void) jpeg_read_header(&cinfo, TRUE);
(void) jpeg_start_decompress(&cinfo);
row_stride = cinfo.output_width * cinfo.output_components;
/* Make a one-row-high sample array that will go away when done with image */
while (cinfo.output_scanline < cinfo.output_height)
{
row_pointer[0] = & TransfertBufferImage[crows * row_stride];
(void) jpeg_read_scanlines(&cinfo, row_pointer, 1);
crows++;
}
(void) jpeg_finish_decompress(&cinfo);
jpeg_destroy_decompress(&cinfo);
return TransfertBufferImage;
}
|