Commit c3d99649 authored by Arnaud Blanchard's avatar Arnaud Blanchard
Browse files

Add management og YUYV

parent 31aeb6bf
...@@ -159,7 +159,7 @@ gboolean update_Y800_image(GtkImage *image, GdkFrameClock *, gpointer pointer_st ...@@ -159,7 +159,7 @@ gboolean update_Y800_image(GtkImage *image, GdkFrameClock *, gpointer pointer_st
values = (uint32_t*)image_buffer; values = (uint32_t*)image_buffer;
if (channel->type=='UIN8') FOR_INV(i, channel->size) values[i]=color_map[channel->uchars[i]]; if (channel->type=='UIN8') FOR_INV(i, channel->size) values[i]=color_map[channel->uchars[i]];
else if (channel->type=='FL32') FOR_INV(i, channel->size/sizeof(float)) values[i]=color_map[CLIP_UCHAR(channel->floats[i]*256-0.5f)]; else if (channel->type=='FL32') FOR_INV(i, channel->size/sizeof(float)) values[i]=color_map[CLIP_UCHAR(channel->floats[i]*256-0.5f)];
else EXIT_ON_ARRAY_ERROR(channel, "Type not amanaged"); else EXIT_ON_ARRAY_ERROR(channel, "Type not managed");
gtk_image_set_from_surface(image, image_surface); gtk_image_set_from_surface(image, image_surface);
gdk_window_get_device_position(gtk_widget_get_window(GTK_WIDGET(image)), pointer_device, &x, &y, NULL); gdk_window_get_device_position(gtk_widget_get_window(GTK_WIDGET(image)), pointer_device, &x, &y, NULL);
...@@ -314,7 +314,7 @@ gboolean update_JPEG_image(GtkImage *image, GdkFrameClock *frame_clock, blc_chan ...@@ -314,7 +314,7 @@ gboolean update_JPEG_image(GtkImage *image, GdkFrameClock *frame_clock, blc_chan
// 4:2:2 // 4:2:2
gboolean update_YUYV_image(GtkImage *image, GdkFrameClock *frame_clock, blc_channel *channel) gboolean update_YUYV_image(GtkImage *image, GdkFrameClock *frame_clock, void*)
{ {
int i, j; int i, j;
uchar *data = (uchar*) channel->data; uchar *data = (uchar*) channel->data;
...@@ -325,6 +325,7 @@ gboolean update_YUYV_image(GtkImage *image, GdkFrameClock *frame_clock, blc_chan ...@@ -325,6 +325,7 @@ gboolean update_YUYV_image(GtkImage *image, GdkFrameClock *frame_clock, blc_chan
pixels = (uint32_t*)image_buffer; pixels = (uint32_t*)image_buffer;
if (blc_command_loop_start()==0) exit(0);
i = 0; i = 0;
while (i != (int) channel->size) while (i != (int) channel->size)
{ {
...@@ -339,6 +340,8 @@ gboolean update_YUYV_image(GtkImage *image, GdkFrameClock *frame_clock, blc_chan ...@@ -339,6 +340,8 @@ gboolean update_YUYV_image(GtkImage *image, GdkFrameClock *frame_clock, blc_chan
pixels[1]=RGBA_from_YUYV[j]; pixels[1]=RGBA_from_YUYV[j];
pixels+=2; pixels+=2;
} }
iterations++;
blc_command_loop_end();
gtk_image_set_from_surface(image, image_surface); gtk_image_set_from_surface(image, image_surface);
...@@ -474,6 +477,33 @@ gboolean update_histogram_cb(GtkImage *image, GdkFrameClock *, gpointer pointer_ ...@@ -474,6 +477,33 @@ gboolean update_histogram_cb(GtkImage *image, GdkFrameClock *, gpointer pointer_
gtk_statusbar_push(GTK_STATUSBAR(pointer_statusbar), 0, text); gtk_statusbar_push(GTK_STATUSBAR(pointer_statusbar), 0, text);
} }
break;
case 'YUYV':
for(i=channel->size-2;i!=-1;i-=2) histogram[channel->uchars[i]]++;
for(i=channel->size-1;i!=-2;i-=4) histogram1[channel->uchars[i]]++;
for(i=channel->size-3;i!=-4;i-=4) histogram2[channel->uchars[i]]++;
FOR_INV(i, 256)
{
max=MAX(histogram[i], max);
max1=MAX(histogram1[i], max1);
max2=MAX(histogram2[i], max2);
}
draw_histogram(histogram_data, 127, histogram, gray_colors, max);
draw_histogram(histogram_data+256*128, 63, histogram1, u_colors, max1);
draw_histogram(histogram_data+256*192, 63, histogram2, v_colors, max2);
if (y>=0 && y<256 && x >=0 && x<256)
{
if (y<128) SPRINTF(text, "Y[%d]=%f.2%%", x, histogram[x]*100*2/(float)channel->size);
else if (y<192) SPRINTF(text, "U[%d]=%.2f%%", x, histogram1[x]*100*4/(float)channel->size);
else SPRINTF(text, "V[%d]=%.2f%%", x, histogram2[x]*100*4/(float)channel->size);
gtk_statusbar_push(GTK_STATUSBAR(pointer_statusbar), 0, text);
}
break; break;
case 'yuv2': case 'yuv2':
for(i=channel->size-1;i!=-1;i-=2) histogram[channel->uchars[i]]++; for(i=channel->size-1;i!=-1;i-=2) histogram[channel->uchars[i]]++;
...@@ -690,7 +720,6 @@ GtkWidget *create_image_display(blc_channel *tmp_channel) ...@@ -690,7 +720,6 @@ GtkWidget *create_image_display(blc_channel *tmp_channel)
char label_text[NAME_MAX + 1]; char label_text[NAME_MAX + 1];
uint32_t type_string, format_string; uint32_t type_string, format_string;
channel=tmp_channel; channel=tmp_channel;
toolbar = gtk_toolbar_new(); toolbar = gtk_toolbar_new();
general_statusbar=gtk_statusbar_new(); general_statusbar=gtk_statusbar_new();
...@@ -739,16 +768,15 @@ GtkWidget *create_image_display(blc_channel *tmp_channel) ...@@ -739,16 +768,15 @@ GtkWidget *create_image_display(blc_channel *tmp_channel)
image_buffer = MANY_ALLOCATIONS(width*height*3, uchar); image_buffer = MANY_ALLOCATIONS(width*height*3, uchar);
pixbuf = gdk_pixbuf_new_from_data( image_buffer, GDK_COLORSPACE_RGB, 0, 8, width, height, width * 3, NULL, NULL); pixbuf = gdk_pixbuf_new_from_data( image_buffer, GDK_COLORSPACE_RGB, 0, 8, width, height, width * 3, NULL, NULL);
image = gtk_image_new_from_pixbuf(pixbuf); image = gtk_image_new_from_pixbuf(pixbuf);
gtk_widget_add_tick_callback(image, (GtkTickCallback) update_JPEG_image, channel, NULL); gtk_widget_add_tick_callback(image, (GtkTickCallback) update_JPEG_image, channel, NULL);*/
case 'YUYV': case 'YUYV':
width=channel->lengths[1]; width=channel->dims[1].length;
height=channel->lengths[2]; height=channel->dims[2].length;
image_buffer = MANY_ALLOCATIONS(width*height * 3, uchar); //In order to be sure that the rowstride will be 'gui.width * 3' image_buffer = MANY_ALLOCATIONS(width*height * 4, uchar); //In order to be sure that the rowstride will be 'gui.width * 3'
pixbuf = gdk_pixbuf_new_from_data(image_buffer, GDK_COLORSPACE_RGB, 0, 8, width, height, width * 3, NULL, NULL); image_surface=cairo_image_surface_create_for_data(image_buffer, CAIRO_FORMAT_RGB24, width, height, width * 4);
image = gtk_image_new_from_pixbuf(pixbuf); image=gtk_image_new_from_surface(image_surface);
pthread_create(&init_table_thread, NULL, create_RGB3_from_YUYV, image); gtk_widget_add_tick_callback(GTK_WIDGET(image), (GtkTickCallback) update_YUYV_image, pointer_statusbar, NULL);
gtk_widget_add_tick_callback(GTK_WIDGET(image), (GtkTickCallback) update_YUYV_image, channel, NULL); break;
break;*/
case 'yuv2':case 'UYVY': case 'yuv2':case 'UYVY':
pthread_create(&init_table_thread, NULL, create_RGBA_from_YUYV, image); pthread_create(&init_table_thread, NULL, create_RGBA_from_YUYV, image);
width=channel->dims[1].length; width=channel->dims[1].length;
...@@ -756,8 +784,6 @@ GtkWidget *create_image_display(blc_channel *tmp_channel) ...@@ -756,8 +784,6 @@ GtkWidget *create_image_display(blc_channel *tmp_channel)
image_buffer = MANY_ALLOCATIONS(width*height * 4, uchar); image_buffer = MANY_ALLOCATIONS(width*height * 4, uchar);
image_surface=cairo_image_surface_create_for_data(image_buffer, CAIRO_FORMAT_RGB24, width, height, width * 4); image_surface=cairo_image_surface_create_for_data(image_buffer, CAIRO_FORMAT_RGB24, width, height, width * 4);
image=gtk_image_new_from_surface(image_surface); image=gtk_image_new_from_surface(image_surface);
// if (interactive_mode) pthread_create(&thread, NULL, refresh_yuv2_cb, image);
//g_timeout_add(0, refresh_yuv2_cb, image); //To be improved
gtk_widget_add_tick_callback(GTK_WIDGET(image), (GtkTickCallback) update_yuv2_image, pointer_statusbar, NULL); gtk_widget_add_tick_callback(GTK_WIDGET(image), (GtkTickCallback) update_yuv2_image, pointer_statusbar, NULL);
break; break;
default:return NULL; default:return NULL;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment