Example #1
0
static rgb_ptr yuy2_to_rgb24() {
	int newsize = buffer_copy_lenght / BPP_YUY2 * BPP_RGB24;
	rgb_ptr result = malloc(newsize);
	if (result == NULL) {
		printf("FAILED!!");
		fflush(stdout);
	}

	yuyv_to_rgb(buffer_copy, result, wigth, heigth);
	return result;
}
Example #2
0
int yuyv_to_bmp32(const void *yuyv_array, int size, int img_h, int img_w, int socket, int iscolor) {
  BITMAPFILEHEADER bfh;
  BITMAPINFOHEADER bih;
  char Palette [BMP32_PALETTE_SIZE];

  int obs = sizeof(bfh) + sizeof(bih) + BMP32_PALETTE_SIZE + (img_h * img_w * RGB_SIZE);
  char *buf_image = malloc(obs);

  memset(buf_image, 255, obs);
  
  #ifdef DEBUG1
  printf("DEBUG: yuyv_to_bmp32().obs=%d;\n", obs);
  #endif
  
  memset(&bfh, 0, sizeof(bfh));
  bfh.bfType = 0x4D42; 
  bfh.bfSize = 0x00;
  bfh.bfReserved1 = 0;
  bfh.bfReserved2 = 0;
  bfh.bfOffBits = sizeof(bfh) + sizeof(bih) + BMP32_PALETTE_SIZE;
  
  memset(&bih, 0, sizeof(bih));
  bih.biSize = sizeof(bih);
  bih.biWidth = img_w;
  bih.biHeight = img_h;
  bih.biPlanes = 1;
  bih.biBitCount = 24;
  bih.biCompression = 0;
  bih.biSizeImage = 0;
  bih.biXPelsPerMeter = 3780;
  bih.biYPelsPerMeter = 3780;
  bih.biClrUsed = 0;
  bih.biClrImportant = 0;

  memset(Palette, 0, BMP32_PALETTE_SIZE);

  memcpy(buf_image, &bfh, sizeof(bfh));
  memcpy(buf_image + sizeof(bfh), &bih, sizeof(bih));
  memcpy(buf_image + sizeof(bfh) + sizeof(bih), Palette, BMP32_PALETTE_SIZE);
  
  int retval = yuyv_to_rgb(yuyv_array, size, (buf_image + sizeof(bfh) + sizeof(bih) + BMP32_PALETTE_SIZE), img_w, img_h, ((iscolor == 0) ? FLAG_CONV_NOCOLOR : FLAG_CONV_BGR));
  if (retval < 0) {
    return -2;
  }

  int retv = send(socket, buf_image, obs, 0);
  #ifdef DEBUG1
  printf("DEBUG: yuyv_to_bmp32().send(xxx)=%d;\n", retv);
  #endif
  free(buf_image);
  
  return 0;
}
Example #3
0
int yuyv_to_jpeg(const void *yuyv_array, int size, int img_h, int img_w, int socket, int iscolor) {
  struct jpeg_compress_struct 	cinfo;
  struct jpeg_error_mgr 	jerr;
  
  JSAMPROW row_pointer[1];
  int row_stride;
  
  FILE *tmp = fopen("/tmp/camjpeg.tmp", "w+");
  if (tmp == NULL) {
    #ifdef DEBUG
    printf("DEBUG: Cannot open temporary file for write jpeg\n");
    #endif
    return -1;
  }
  
  char rgb_buffer[img_w * img_h * RGB_SIZE];
  int retval = yuyv_to_rgb(yuyv_array, size, (void *)rgb_buffer, img_w, img_h, ((iscolor == 0) ? FLAG_CONV_NOCOLOR : FLAG_CONV_RGB));
  if (retval < 0) {
    return -2;
  }
  
  cinfo.err 			= jpeg_std_error(&jerr);
  jpeg_create_compress(&cinfo);
  jpeg_stdio_dest(&cinfo, tmp);
  
  cinfo.image_width 		= img_w;
  cinfo.image_height 		= img_h;
  cinfo.input_components 	= RGB_SIZE;
  cinfo.in_color_space 		= JCS_RGB;
  
  jpeg_set_defaults(&cinfo);
  jpeg_set_quality(&cinfo, IMAGE_QUALITY, TRUE);
  
  jpeg_start_compress(&cinfo, TRUE);
  
  row_stride = img_w * RGB_SIZE;
  while (cinfo.next_scanline < cinfo.image_height) {
    row_pointer[0] = &rgb_buffer[cinfo.next_scanline * row_stride];
    jpeg_write_scanlines(&cinfo, row_pointer, 1);
  }
  
  jpeg_finish_compress(&cinfo);
  jpeg_destroy_compress(&cinfo);
  
  fflush(tmp);
  fseek(tmp, 0, SEEK_END);
  int sizeOfJPEG = ftell(tmp);
  fseek(tmp, 0, SEEK_SET);
  
  if (sizeOfJPEG <= 0) {
    #ifdef DEBUG
    printf("DEBUG: Null temporary file\n");
    #endif
    return -3;
  }
  
  char *out_buffer = malloc(sizeOfJPEG);
  fread(out_buffer, 1, sizeOfJPEG, tmp);
  
  int retv = send(socket, out_buffer, sizeOfJPEG, 0);
  #ifdef DEBUG1
  printf("DEBUG: yuyv_to_jpeg().send(xxx)=%d;\n", retv);
  #endif
  
  fclose(tmp);
  free(out_buffer);
  return 0;
}
Example #4
0
/* TODO: Write single step conversions where they may actually be useful */
int v4l2_process_image (PyCameraObject* self, const void *image, 
                               unsigned int buffer_size, SDL_Surface* surf)
{

    if (!surf)
        return 0;
        
    SDL_LockSurface (surf);
    
    switch (self->pixelformat) {
        case V4L2_PIX_FMT_RGB24:
            if (buffer_size >= self->size * 3) {
                switch (self->color_out) {
                    case RGB_OUT:
                        rgb24_to_rgb(image, surf->pixels, self->size, surf->format);
                        break;
                    case HSV_OUT:
                        rgb_to_hsv(image, surf->pixels, self->size, V4L2_PIX_FMT_RGB24, surf->format);
                        break;
                    case YUV_OUT:
                        rgb_to_yuv(image, surf->pixels, self->size, V4L2_PIX_FMT_RGB24, surf->format);
                        break;
                }
            } else {
                SDL_UnlockSurface (surf);
                return 0;
            }
            break;
        case V4L2_PIX_FMT_RGB444:
            if (buffer_size >= self->size * 2) {
                switch (self->color_out) {
                    case RGB_OUT:
                        rgb444_to_rgb(image, surf->pixels, self->size, surf->format);
                        break;
                    case HSV_OUT:
                        rgb_to_hsv(image, surf->pixels, self->size, V4L2_PIX_FMT_RGB444, surf->format);
                        break;
                    case YUV_OUT:
                        rgb_to_yuv(image, surf->pixels, self->size, V4L2_PIX_FMT_RGB444, surf->format);
                        break;
                }
            } else {
                SDL_UnlockSurface (surf);
                return 0;
            }
            break;
        case V4L2_PIX_FMT_YUYV:
            if (buffer_size >= self->size * 2) {
                switch (self->color_out) {
                    case YUV_OUT:
                        yuyv_to_yuv(image, surf->pixels, self->size, surf->format);
                        break;
                    case RGB_OUT:
                        yuyv_to_rgb(image, surf->pixels, self->size, surf->format);
                        break;
                    case HSV_OUT:
                        yuyv_to_rgb(image, surf->pixels, self->size, surf->format);
                        rgb_to_hsv(surf->pixels, surf->pixels, self->size, V4L2_PIX_FMT_YUYV, surf->format);
                        break;
                }
            } else {
                SDL_UnlockSurface (surf);
                return 0;
            }
            break;
        case V4L2_PIX_FMT_SBGGR8:
            if (buffer_size >= self->size) {
                switch (self->color_out) {
                    case RGB_OUT:
                        sbggr8_to_rgb(image, surf->pixels, self->width, self->height, surf->format);
                        break;
                    case HSV_OUT:
                        sbggr8_to_rgb(image, surf->pixels, self->width, self->height, surf->format);
                        rgb_to_hsv(surf->pixels, surf->pixels, self->size, V4L2_PIX_FMT_SBGGR8, surf->format);
                        break;
                    case YUV_OUT:
                        sbggr8_to_rgb(image, surf->pixels, self->width, self->height, surf->format);
                        rgb_to_yuv(surf->pixels, surf->pixels, self->size, V4L2_PIX_FMT_SBGGR8, surf->format);
                        break;
                }
            } else {
                SDL_UnlockSurface (surf);
                return 0;
            }
            break;
        case V4L2_PIX_FMT_YUV420:
            if (buffer_size >= (self->size * 3) / 2) {
                switch (self->color_out) {
                    case YUV_OUT:
                        yuv420_to_yuv(image, surf->pixels, self->width, self->height, surf->format);
                        break;
                    case RGB_OUT:
                        yuv420_to_rgb(image, surf->pixels, self->width, self->height, surf->format);
                        break;
                    case HSV_OUT:
                        yuv420_to_rgb(image, surf->pixels, self->width, self->height, surf->format);
                        rgb_to_hsv(surf->pixels, surf->pixels, self->size, V4L2_PIX_FMT_YUV420, surf->format);
                        break;
                }
            } else {
                SDL_UnlockSurface (surf);
                return 0;
            }
            break;
    }
    SDL_UnlockSurface (surf);
    return 1;
}
Example #5
0
 void grey_to_rgb(unsigned char* rgb, unsigned char* grey) {
     init_buffers();
     grey_to_yuyv(yuyv_buffer, grey, w, h);
     yuyv_to_rgb(rgb, yuyv_buffer);
 }
Example #6
0
	void jpeg_to_rgb(unsigned char* rgb, unsigned char* jpeg, const unsigned int jpeg_size) {
		init_buffers();
		jpeg_decode(yuyv_buffer, jpeg, jpeg_size);
		yuyv_to_rgb(rgb, yuyv_buffer);
	}