📄 mjpg.c
字号:
((unsigned char*)data1)[ptr2++] = g; ((unsigned char*)data1)[ptr2++] = b; ((unsigned char*)data1)[ptr2++] = 0; } } } } }else if (image->bits_per_pixel == 24){ if (components == 3){ for(i=0; i<vheight; i++){ ptr2 = i * image->bytes_per_line; for(j=0; j<vwidth; j++){ if (stretched != 0){ ptr = (long)((double)i*rheight/vheight)*rwidth + (long)((double)j*rwidth/vwidth); ptr *= 3; } r = buf[ptr++]; g = buf[ptr++]; b = buf[ptr++]; udat = 0; if (red_shift >= 0){ udat |= (((int)r << red_shift) & red_mask); }else{ udat |= (((int)r >> (-red_shift)) & red_mask); } if (green_shift >= 0){ udat |= (((int)g << green_shift) & green_mask); }else{ udat |= (((int)g >> (-green_shift)) & green_mask); } if (blue_shift >= 0){ udat |= (((int)b << blue_shift) & blue_mask); }else{ udat |= (((int)b >> (-blue_shift)) & blue_mask); } if (msb_flag){ ((unsigned char*)data1)[ptr2++] = (udat & 0xff0000)>>16; ((unsigned char*)data1)[ptr2++] = (udat & 0xff00)>>8; ((unsigned char*)data1)[ptr2++] = (udat & 0xff); }else{ ((unsigned char*)data1)[ptr2++] = (udat & 0xff); ((unsigned char*)data1)[ptr2++] = (udat & 0xff00)>>8; ((unsigned char*)data1)[ptr2++] = (udat & 0xff0000)>>16; } } } }else{ for(i=0; i<vheight; i++){ for(j=0; j<vwidth; j++){ if (stretched != 0){ ptr = (long)((double)i*rheight/vheight)*rwidth + (long)((double)j*rwidth/vwidth); } r = buf[ptr]; g = buf[ptr]; b = buf[ptr++]; if (msb_flag){ ((unsigned char*)data1)[ptr2++] = b; ((unsigned char*)data1)[ptr2++] = g; ((unsigned char*)data1)[ptr2++] = r; }else{ ((unsigned char*)data1)[ptr2++] = r; ((unsigned char*)data1)[ptr2++] = g; ((unsigned char*)data1)[ptr2++] = b; } } } } }else if (image->bits_per_pixel ==16){ if (components == 3){ for(i=0; i<vheight; i++){ for(j=0; j<vwidth; j++){ unsigned int rr = buf[ptr++]; unsigned int gg = buf[ptr++]; unsigned int bb = buf[ptr++]; if (stretched != 0){ ptr = (long)((double)i*rheight/vheight+0.5)*rwidth + (long)((double)j*rwidth/vwidth + 0.5); ptr *= 3; } udat = 0; if (red_shift >= 0){ udat |= (((int)rr << red_shift) & red_mask); }else{ udat |= (((int)rr >> (-red_shift)) & red_mask); } if (green_shift >= 0){ udat |= (((int)gg << green_shift) & green_mask); }else{ udat |= (((int)gg >> (-green_shift)) & green_mask); } if (blue_shift >= 0){ udat |= (((int)bb << blue_shift) & blue_mask); }else{ udat |= (((int)bb >> (-blue_shift)) & blue_mask); } if (msb_flag){ ((unsigned char*)data1)[ptr2++] = (udat >> 8) & 0xff; ((unsigned char*)data1)[ptr2++] = (udat & 0xff); }else{ ((unsigned char*)data1)[ptr2++] = (udat & 0xff); ((unsigned char*)data1)[ptr2++] = (udat & 0xff00)>>8; } } } }else{ for(i=0; i<vheight; i++){ for(j=0; j<vwidth; j++){ if (stretched != 0){ ptr = (long)((double)i*rheight/vheight)*rwidth + (long)((double)j*rwidth/vwidth); } r = buf[ptr]>>3; g = buf[ptr]>>2; b = buf[ptr++]>>3; ((short*)data1)[ptr2++] = r <<11 | g<<5 | b; } } } }else if (image->bits_per_pixel == 8){ /* printf("components=%d\n",components); */ XColor col[5*5*5]; Colormap cm = DefaultColormap(display,DefaultScreen(display)); long k; long cnt=0; long colptr = 0; long rr = 0,gg = 0,bb = 0; long tr1,tg1,tb1; signed char dr1,dg1,db1; for(i=0; i<5; i++){ for(j=0; j<5; j++){ for(k=0; k<5; k++){ if (i != 4){ col[cnt].red = i*64*256; }else{ col[cnt].red = 0xffff; } if (j != 4){ col[cnt].green = j*64*256; }else{ col[cnt].green = 0xffff; } if (k != 4){ col[cnt].blue = k*64*256; }else{ col[cnt].blue = 0xffff; } XAllocColor(display,cm,&(col[cnt])); cnt++; } } } for(i=0; i<vheight; i++){ dr1 = 0; dg1 = 0; db1 = 0; for(j=0; j<vwidth; j++){ if (components == 3){ if (stretched != 0){ ptr = (long)((double)i*rheight/vheight)*rwidth + (long)((double)j*rwidth/vwidth); ptr *= 3; } tr1 = buf[ptr++]; tg1 = buf[ptr++]; tb1 = buf[ptr++]; }else{ ptr = (long)((double)i*rheight/vheight)*rwidth + (long)((double)j*rwidth/vwidth); tr1 = buf[ptr]; tg1 = buf[ptr]; tb1 = buf[ptr++]; } if ((0 < tr1 + dr1) && (tr1 + dr1) < 256){ if ((-32 < dr1) && (dr1 < 32)){ rr = (tr1 + dr1 + 31) & 0x1c0; }else if (dr1 > 31){ rr = (tr1 + 63) & 0x1c0; }else{ rr = tr1 & 0x1c0; } }else if (tr1 + dr1 > 255){ rr = 0x100; }else{ rr = 0; } dr1 += (tr1 - rr); if (0 < tg1 + dg1 &&tg1 + dg1 < 256){ if (-32 < dg1 && dg1 < 32 ){ gg = (tg1 + dg1 + 31) & 0x1c0; }else if (dg1 > 31){ gg = (tg1 + 63) & 0x1c0; }else{ gg = tg1 & 0x1c0; } }else if (tg1 + dg1 > 255){ gg = 0x100; }else{ gg = 0; } dg1 += (tg1 - gg); if (0 < tb1 + db1 && tb1 + db1 < 256){ if (-32 < db1 && db1 < 32){ bb = (tb1 + db1 + 31) & 0x1c0; }else if (db1 > 31){ bb = (tb1 + 63) & 0x1c0; }else{ bb = tb1 & 0x1c0; } }else if (tb1 + db1 > 255){ bb = 0x100; }else{ bb = 0; } db1 += (tb1 - bb); db1 += (tb1 - bb); colptr = (rr>>6)*5*5 + (gg>>6)*5 + (bb>>6); data1[ptr2++] = col[colptr].pixel; } } } image->data = data1; rxvt_free(buf); pix = XCreatePixmap(display,window, vwidth,vheight,display_depth); *pixmap = pix; XPutImage(display,pix,gc,image,0,0,0,0,vwidth,vheight); jpeg_finish_decompress(&jinf); jpeg_destroy_decompress(&jinf); if (image->data != NULL){ rxvt_free(image->data); image->data = NULL; } XDestroyImage(image); fclose(ifile); return 0;}#endif /* USE_JPEG *//*----------------------- end-of-file (C source) -----------------------*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -