23,118
社区成员
发帖
与我相关
我的任务
分享
lenovo@ubuntu:~/test$ make
arm-none-linux-gnueabi-gcc -o luvc_test -L/home/lenovo/work/jpeg/lib luvc_test.c -ljpeg
/home/lenovo/work/arm-2007q3/bin/../lib/gcc/arm-none-linux-gnueabi/4.2.1/../../../../arm-none-linux-gnueabi/bin/ld: skipping incompatible /home/lenovo/work/jpeg/lib/libjpeg.so when searching for -ljpeg
/home/lenovo/work/arm-2007q3/bin/../lib/gcc/arm-none-linux-gnueabi/4.2.1/../../../../arm-none-linux-gnueabi/bin/ld: skipping incompatible /home/lenovo/work/jpeg/lib/libjpeg.a when searching for -ljpeg
/home/lenovo/work/arm-2007q3/bin/../lib/gcc/arm-none-linux-gnueabi/4.2.1/../../../../arm-none-linux-gnueabi/bin/ld: cannot find -ljpeg
collect2: ld returned 1 exit status
make: *** [luvc_test] Error 1
CROSS=arm-none-linux-gnueabi-
all: luvc_test
luvc_test: luvc_test.c
$(CROSS)gcc -o luvc_test -L/home/lenovo/work/jpeg/lib luvc_test.c -ljpeg
clean:
@rm -vf luvc_test *.o *~
#include <stdio.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdint.h>
#include <stdlib.h>
#include <errno.h>
#include <getopt.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <sys/select.h>
#include <sys/time.h>
#include "jpeglib.h"
#include <linux/fb.h>
#include <linux/videodev.h>
#define FB_FILE "/dev/fb0"
typedef struct _fb_v4l
{
int fbfd ;
char *fbp;
struct fb_var_screeninfo vinfo;
struct fb_fix_screeninfo finfo;
}fb_v41;
void jpeg_to_framebuffer(fb_v41 *vd, int width, int height, int xoffset, int yoffset, JSAMPARRAY buffer)
{
int x, y, location;
unsigned short *loca_ptr, data;
unsigned char Red, Green, Blue;
for(y = 0; y < height; y++){
location = xoffset * 2 + (y + yoffset) * vd->finfo.line_length;
loca_ptr = (unsigned short *) (vd->fbp + location);
for(x = 0; x < width; x++){
Red = buffer[y][x * 3];
Green = buffer[y][x * 3 + 1];
Blue = buffer[y][x * 3 + 2];
data = ((Red >> 3) << 11) + ((Green >> 2) << 5) + (Blue >> 3) << 0;//rgb565
*(loca_ptr + x) = data;
}
}
}
void yuv_to_framebuffer(fb_v41 *vd, int width, int height, int xoffset, int yoffset, unsigned short *buffer)
{
int x, y, location;
unsigned short *loca_ptr;
for(y = 0; y < height; y++){
location = xoffset * 2 + (y + yoffset) * vd->finfo.line_length;
loca_ptr = (unsigned short *) (vd->fbp + location);
for(x = 0; x < width; x++){
*(loca_ptr + x) = *buffer++;//rgb565
}
}
}
static inline void yuv_to_rgb16(unsigned char y,
unsigned char u,
unsigned char v,
unsigned char *rgb)
{
register int r,g,b;
int rgb16;
r = (1192 * (y - 16) + 1634 * (v - 128) ) >> 10;
g = (1192 * (y - 16) - 833 * (v - 128) - 400 * (u -128) ) >> 10;
b = (1192 * (y - 16) + 2066 * (u - 128) ) >> 10;
r = r > 255 ? 255 : r < 0 ? 0 : r;
g = g > 255 ? 255 : g < 0 ? 0 : g;
b = b > 255 ? 255 : b < 0 ? 0 : b;
rgb16 = (int)(((r >> 3)<<11) | ((g >> 2) << 5)| ((b >> 3) << 0));
*rgb = (unsigned char)(rgb16 & 0xFF);
rgb++;
*rgb = (unsigned char)((rgb16 & 0xFF00) >> 8);
}
void convert(unsigned char *buf, unsigned char *rgb, int width, int height)
{
int x,y,z=0;
int blocks;
blocks = (width * height) * 2;
for (y = 0; y < blocks; y+=4) {
unsigned char Y1, Y2, U, V;
Y1 = buf[y + 0];
U = buf[y + 1];
Y2 = buf[y + 2];
V = buf[y + 3];
yuv_to_rgb16(Y1, U, V, &rgb[y]);
yuv_to_rgb16(Y2, U, V, &rgb[y + 2]);
}
}