📄 spcaview.c
字号:
break;
case SDLK_b: messcallback->updobright=1; break;
case SDLK_n: messcallback->updobright=2; break;
case SDLK_l: messcallback->sleepon=1; break;
case SDLK_c: messcallback->sleepon=2; break;
case SDLK_UP: if(messcallback->y -1 > 0) messcallback->y--; keypressed = SDLK_UP ;
run = 2; break;
case SDLK_DOWN: if(messcallback->y +1 < 256) messcallback->y++; keypressed = SDLK_DOWN;
run = 2; break;
case SDLK_RIGHT: if(messcallback->x -1 > 0) messcallback->x--; keypressed = SDLK_RIGHT;
run = 2; break;
case SDLK_LEFT: if(messcallback->x +1 < 256) messcallback->x++; keypressed = SDLK_LEFT;
run = 2; break;
case SDLK_SPACE: run = 0; break;
case SDLK_q: quit =0; break; } break;
case SDL_QUIT: quit = 0; break; } } //end Poll event break;
case 0: if (SDL_WaitEvent (&sdlevent) == 1)
{ switch (sdlevent.type)
{ case SDL_KEYDOWN: switch (sdlevent.key.keysym.sym)
{ case SDLK_s: //getPicture(buf,jpegsize); break;
case SDLK_SPACE: run = 1; break;
case SDLK_q: quit =0; break; } break;
case SDL_QUIT: quit = 0; break; } } //end wait event break;
case 2:
{ if (SDL_PollEvent (&sdlevent) == 1)
{ switch (sdlevent.type)
{ case SDL_KEYDOWN: keypressed = 0; run = 1; break; } //end event type poll 2 } switch (keypressed)
{ case SDLK_UP: if(messcallback->y -1 > 0) messcallback->y--; break; case SDLK_DOWN: if(messcallback->y +1 < 256) messcallback->y++; break; case SDLK_RIGHT: if(messcallback->x -1 > 0) messcallback->x--; break; case SDLK_LEFT: if(messcallback->x +1 < 256) messcallback->x++; break; default: break; } } // end case 2 break; } }while(quit);error: if(picture)
{ free(picture); picture = NULL; } close_sock(sock_client); free(buf); free(messcallback); free(headerframe); SDL_Quit (); return 0;}Uint32 GetVideoBpp (void){ const SDL_VideoInfo *info; info = SDL_GetVideoInfo(); printf( "Current display: %d bits-per-pixel\n",info->vfmt->BitsPerPixel);return info->vfmt->BitsPerPixel;}#define ADDRESSE(x,y,w) (((y)*(w))+(x))void resize16 (unsigned char *dst,unsigned char *src, int Wd,int Hd,int Ws,int Hs) { int rx,ry; int xscale,yscale; int x,y; Myrgb24 pixel; Myrgb16 *output =(Myrgb16*) dst ; Myrgb24 *input = (Myrgb24*) src ; xscale = (Ws << 16)/Wd; yscale = (Hs << 16)/ Hd; for (y = 0; y < Hd; y++){ for (x = 0; x < Wd; x++){ rx = x*xscale >> 16; ry = y*yscale >> 16; output->blue = input[ADDRESSE((int)rx,(int)ry,Ws)].blue >> 3; output->green = input[ADDRESSE((int)rx,(int)ry,Ws)].green >> 2; output->red = input[ADDRESSE((int)rx,(int)ry,Ws)].red >> 3; output++ ; } } }void resize (unsigned char *dst,unsigned char *src, int Wd,int Hd,int Ws,int Hs) { int rx,ry; int xscale,yscale; int x,y; Myrgb24 pixel; Myrgb24 *output =(Myrgb24*) dst ; Myrgb24 *input = (Myrgb24*) src ; xscale = (Ws << 16)/Wd; yscale = (Hs << 16)/ Hd; for (y = 0; y < Hd; y++){ for (x = 0; x < Wd; x++){ rx = x*xscale >> 16; ry = y*yscale >> 16; memcpy(output++,&input[ADDRESSE((int)rx,(int)ry,Ws)],sizeof(Myrgb24)); } } }/* refresh_screen input all palette to RGB24 -> RGB565 */static voidrefresh_screen (unsigned char *src, unsigned char *pict, int format, int width, int height,int owidth ,int oheight, int size, int autobright){ unsigned int *lpix; unsigned short *pix; int i; int intwidth = width; int intheight = height;unsigned char *dst = NULL;/* in case VIDEO_PALETTE_RAW_JPEG nothing todo */ if( format == VIDEO_PALETTE_RAW_JPEG) return ; /* for some strange reason tiny_jpegdecode need 1 macroblok line more ?? */ dst = (unsigned char *)malloc (width*(height+8)*3); switch (format) { case VIDEO_PALETTE_JPEG:{ //libjpeg_decode (dst, src, size, width, height); jpeg_decode (&dst, src, &intwidth, &intheight); } break; case VIDEO_PALETTE_YUV420P:{ // uncompressed data yuv420P decoder in module // equalize (src, width, height, 0); YUV420toRGB ((unsigned char *) src, (unsigned char *) dst, width, height, 0, 0); } break; case VIDEO_PALETTE_RGB565: pix = (unsigned short *) src; for (i = 0; i < ((width*height*3) - 3); i += 3) { dst[i] = (*pix & 0x001F) << 3; dst[i + 1] = (*pix & 0x07E0) >> 3; dst[i + 2] = (*pix & 0xF800) >> 8; pix++; } break; case VIDEO_PALETTE_RGB32: lpix = (unsigned int *) src; for (i = 0; i < ((width*height*3) - 3); i += 3) { dst[i] = (*lpix & 0x000000FF); dst[i + 1] = (*lpix & 0x0000FF00) >> 8; dst[i + 2] = (*lpix & 0x00FF0000) >> 16; lpix++; } break; case VIDEO_PALETTE_RGB24:{ // uncompressed data. rgb decoder in module simple copy for display. memcpy (dst, src, size); } break; default: break; }if (autobright) totmean = get_pic_mean( width, height, dst, 0, 0, 0, width, height );/* rezize16 input rgb24 output rgb565 */resize16 (pict,dst,owidth,oheight,width,height) ; free(dst);}static int isSpcaChip (const char *BridgeName){ int i = -1; int size =0; //size = strlen(BridgeName)-1; /* Spca506 return more with channel video, cut it */ //if (size > 10) size = 8; /* return Bridge otherwhise -1 */ for (i=0; i < MAX_BRIDGE ;i++){ size=strlen(Blist[i].name); if(strncmp(BridgeName,Blist[i].name,size) == 0) { printf("Bridge find %s number %d\n",Blist[i].name,i); break; } } return i;}static int getStreamId (const char * BridgeName){ int i = -1; int match = -1;/* return Stream_id otherwhise -1 */ if((match=isSpcaChip(BridgeName)) < 0){ printf("Not an Spca5xx Camera !!\n"); return match; } switch (match) { case BRIDGE_SPCA505: case BRIDGE_SPCA506: i= YYUV; break; case BRIDGE_SPCA501: i = YUYV; break; case BRIDGE_SPCA508: i = YUVY; break; case BRIDGE_SPCA504: case BRIDGE_SPCA500: case BRIDGE_SPCA504B: case BRIDGE_SPCA533: case BRIDGE_SPCA504C: case BRIDGE_SPCA536: case BRIDGE_ZR364XX: case BRIDGE_ZC3XX: case BRIDGE_CX11646: case BRIDGE_SN9CXXX: case BRIDGE_MR97311: i = JPEG; break; case BRIDGE_ETOMS: case BRIDGE_SONIX: case BRIDGE_SPCA561: case BRIDGE_TV8532: i = GBRG; break; default: i = -1; printf("Unable to find a StreamId !!\n"); break; }return i; } static int probeSize (const char *BridgeName, int *width, int *height){ int bridge = -1; int i; unsigned int intwidth; unsigned int intheight; unsigned int intformat; int match =0;/* return 1->ok otherwhise -1 */ if ((bridge= isSpcaChip(BridgeName)) < 0) { printf ("Cannot Probe Size !! maybe not an Spca5xx Camera\n"); return -1; } for (i=0; (unsigned int)(GET_EXT_MODES(bridge)[i][0]);i++){ intwidth = GET_EXT_MODES(bridge)[i][0]; intheight = GET_EXT_MODES(bridge)[i][1]; intformat = (GET_EXT_MODES(bridge)[i][2] & 0xF0) >> 4; if ((intwidth== *width) && (intheight == *height)){ match = 1; } else { match = 0; } printf("Available Resolutions width %d heigth %d %s %c\n", intwidth,intheight,(intformat)?"decoded":"native", (match)?'*':' '); }}/* * get_pic_mean: Calculate the mean value of the pixels in an image. * This routine is used for adjusting the values of * the pixels to reasonable brightness. * * Arguments: width, height = Dimensions of the picture * buffer = Buffer to picture. * is_rgb = 1 if the picture is rgb, else 0 * start{x,y}, end{x,y} = Region to calculate the * mean of. This MUST be valid before * being passed in! * * Return values: Returns the average of all the components if rgb, else * the average whiteness of each pixel if B&W */static int get_pic_mean( int width, int height, const unsigned char *buffer, int is_rgb,int startx, int starty, int endx, int endy ){ double rtotal = 0, gtotal = 0, btotal = 0; int minrow, mincol, maxrow, maxcol, r, c; double bwtotal = 0, area; int rmean, gmean, bmean; const unsigned char *cp; minrow = starty; mincol = startx; maxrow = endy; maxcol = endx; area = (maxcol-mincol) * (maxrow-minrow); c = mincol; if( is_rgb ){ for( r=minrow; r < maxrow; r++ ){ cp = buffer + (r*width+c)*3; for( c=mincol; c < maxcol; c++ ) { rtotal += *cp++; gtotal += *cp++; btotal += *cp++; } } rmean = rtotal / area; gmean = gtotal / area; bmean = btotal / area; return (double)rmean * .299 + (double)gmean * .587 + (double)bmean * .114; } else { for( r=minrow; r < maxrow; r++ ){ cp = buffer + (r*width+c)*1; for( c=mincol; c < maxcol; c++ ) { bwtotal += *cp++; } } return (int)(bwtotal / area); }}static int clip_to(int x, int low, int high){ if(x<low) return low; else if (x>high) return high; else return x;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -