Commit 0a444df0 authored by Your Name's avatar Your Name
Browse files

Client version c_... of gtk_image

parent adf77fc7
......@@ -4,4 +4,5 @@ cmake_minimum_required(VERSION 2.6)
project(gtk)
subdirs(o_gtk_image)
subdirs(c_gtk_image)
# Set the minimum version of cmake required to build this project
cmake_minimum_required(VERSION 2.6)
project(c_gtk_image)
#This is to be able to debug and recompile automatically the libs (shared_blc). It is slower, you can remove this line and use : ${BLAR_BUILD_DIR}/lib/libblc.dylib instead of shared_blc
find_package(blc_network REQUIRED)
find_package(blc_channel REQUIRED) #For compatibilité with common.h
find_package(blc_image REQUIRED)
find_package(blc_program REQUIRED)
find_package(PkgConfig REQUIRED)
pkg_check_modules(GTK3 REQUIRED gtk+-3.0)
find_package(JPEG REQUIRED)
add_definitions(-Wall ${BL_DEFINITIONS} -std=c++17 -Wno-deprecated-declarations) #device_manager (mouse) is deprecated
include_directories(${GTK3_INCLUDE_DIRS} ${BL_INCLUDE_DIRS} ${JPEG_INCLUDE_DIR} ../include)
link_directories(${GTK3_LIBRARY_DIRS})
add_definitions(${GTK3_CFLAGS_OTHER})
add_executable(c_gtk_image c_gtk_image.cpp ../src/image_display.cpp ../src/histogram.cpp)
target_link_libraries(c_gtk_image ${GTK3_LIBRARIES} ${BL_LIBRARIES} ${JPEG_LIBRARIES} )
#include "common.h"
#include <fcntl.h> // O_RDONLY ...
#include <stdio.h>
#include <gtk/gtk.h>
#include <string.h>
#include <stdint.h> //uint32_t
//#include <jpeglib.h>
#include <sys/mman.h>
#include <errno.h> //errno
#include "blc_core.h"
#include "blc_program.h"
#include "blc_network.h"
#include <thread>
using namespace std;
float min_val, max_val;
const char *channel_name, *fullscreen_option, *keyboard_mode;
GtkWidget *window;
GdkDisplay *main_display;
GdkDevice *pointer_device;
int interactive_mode=0;
GtkApplication *app;
blc_channel mouse_channel;
blc_channel input;
char const *input_name;
int input_terminal;
int mode;
char const *format_string;
uint32_t format;
void ask_fullscreen(){
gtk_window_fullscreen(GTK_WINDOW(window));
}
void ask_quit()
{
g_application_quit(G_APPLICATION(app));
blc_quit();
}
void on_key_press(GtkWidget *widget, GdkEventKey *event){
char key;
if (event->type == GDK_KEY_PRESS){
key=event->keyval;
fwrite(&key, 1, 1, stdout);
fflush(stdout);
}
}
void activate_cb(GApplication *app)
{
GtkWidget *display=nullptr;
GtkWidget *grid;
main_display = gdk_display_get_default ();
GdkDeviceManager *device_manager = gdk_display_get_device_manager (main_display);
pointer_device = gdk_device_manager_get_client_pointer (device_manager);
window=gtk_application_window_new(GTK_APPLICATION(app));
gtk_window_set_title(GTK_WINDOW(window), input.name);
grid=gtk_grid_new();
// for(i=0; input_names[i]; i++){ This is for displaying multiple images
// input=new blc_channel(/*input_names[i]*/ input_name, BLC_CHANNEL_READ);
display=create_image_display(&input);
if (display==NULL) EXIT_ON_CHANNEL_ERROR(&input, "Format not managed.");
gtk_widget_set_hexpand(display, 1);
gtk_widget_set_vexpand(display, 1);
gtk_container_add(GTK_CONTAINER(grid), display);
// }
gtk_container_add(GTK_CONTAINER(window), grid);
gtk_widget_show_all(window);
if (keyboard_mode) g_signal_connect(G_OBJECT(window), "key_press_event", G_CALLBACK (on_key_press), NULL);
}
/** Classical GTK application.
* The first optional argument is the name of the experience. Otherwise all the existing shared memory are used.
* */
int main(int argc, char *argv[])
{
int status=0;
char const *g_debug, *mouse_name, *min_str, *max_str;
blc_program_set_description("Display the content of the blc_channel depending on its type on format");
blc_program_add_option(&keyboard_mode, 'k', "keyboard", nullptr, "Send keyboard input to stdout", nullptr);
blc_program_add_option(&min_str, 'm', "min", "FL32", "minimal value", nullptr);
blc_program_add_option(&max_str, 'M', "max", "FL32", "maximal value", nullptr);
blc_program_add_option(&fullscreen_option, 'F', "fullscreen", nullptr, "Set the window in fullscreen", nullptr);
blc_program_add_option(&g_debug, 'g', "g-fatal-warnings", nullptr, "Debug gtk.", nullptr);
blc_program_init(&argc, &argv, ask_quit);
blc_command_forward_blc_channels();
blc_array_tcp4_client input_client(&input, "127.0.0.1", "31440");
input.allocate();
fprintf(stderr, "Connecté\n");
min_val=0;
if (input.type=='UIN8') max_val=256;
if (input.type=='INT8'){
min_val=-128;
max_val=128;
}
if (input.type=='FL32' && input.format=='Y800'){
if (min_str) SSCANF(1, min_str, "%f", &min_val);
else min_val=0;
if (max_str) SSCANF(1, max_str, "%f", &max_val);
else max_val=1;
}else if (min_str || max_str) EXIT_ON_ARRAY_ERROR(&input, "Min (-m) and max (-M) have only effect for type FL32 format Y800");
thread input_thread([&input_client](){
while(1) input_client.read_data();
});
gtk_disable_setlocale();
gtk_init(&argc, &argv);
app = gtk_application_new(nullptr, G_APPLICATION_FLAGS_NONE);
g_signal_connect (app, "activate", G_CALLBACK (activate_cb), nullptr);
status = g_application_run(G_APPLICATION(app), 0, nullptr);
g_object_unref(app);
return EXIT_SUCCESS;
}
......@@ -5,7 +5,7 @@
#include <blc_channel.h>
extern float min, max;
extern float min_val, max_val;
extern blc_channel *channel;
extern GtkWidget *legend;
......
......@@ -14,10 +14,10 @@ pkg_check_modules(GTK3 REQUIRED gtk+-3.0)
find_package(JPEG REQUIRED)
add_definitions(-Wall ${BL_DEFINITIONS} -Wno-deprecated-declarations) #device_manager (mouse) is deprecated
include_directories(${GTK3_INCLUDE_DIRS} ${BL_INCLUDE_DIRS} ${JPEG_INCLUDE_DIR})
include_directories(${GTK3_INCLUDE_DIRS} ${BL_INCLUDE_DIRS} ${JPEG_INCLUDE_DIR} ../include)
link_directories(${GTK3_LIBRARY_DIRS})
add_definitions(${GTK3_CFLAGS_OTHER})
add_executable(o_gtk_image src/o_gtk_image.cpp src/image_display.cpp src/histogram.cpp)
add_executable(o_gtk_image o_gtk_image.cpp ../src/image_display.cpp ../src/histogram.cpp)
target_link_libraries(o_gtk_image ${GTK3_LIBRARIES} ${BL_LIBRARIES} ${JPEG_LIBRARIES} )
......
......@@ -10,7 +10,7 @@
#include <errno.h> //errno
#include "blc_core.h"
#include "blc_program.h"
float min, max;
float min_val, max_val;
const char *channel_name, *fullscreen_option, *keyboard_mode;
GtkWidget *window;
......@@ -104,18 +104,18 @@ int main(int argc, char *argv[])
input.open(input_name, mode);
min=0;
if (input.type=='UIN8') max=256;
min_val=0;
if (input.type=='UIN8') max_val=256;
if (input.type=='INT8'){
min=-128;
max=128;
min_val=-128;
max_val=128;
}
if (input.type=='FL32' && input.format=='Y800'){
if (min_str) SSCANF(1, min_str, "%f", &min);
else min=0;
if (max_str) SSCANF(1, max_str, "%f", &max);
else max=1;
if (min_str) SSCANF(1, min_str, "%f", &min_val);
else min_val=0;
if (max_str) SSCANF(1, max_str, "%f", &max_val);
else max_val=1;
}else if (min_str || max_str) EXIT_ON_ARRAY_ERROR(&input, "Min (-m) and max (-M) have only effect for type FL32 format Y800");
gtk_disable_setlocale();
......
......@@ -63,7 +63,7 @@ static gboolean update_histogram_cb(GtkImage *image, GdkFrameClock *, gpointer p
}
break;
case 'FL32':
FOR(i, channel->total_length) histogram[(int)CLIP_UCHAR(((channel->floats[i]-min)/(max-min)*256+0.5))]++;
FOR(i, channel->total_length) histogram[(int)CLIP_UCHAR(((channel->floats[i]-min_val)/(max_val-min_val)*256+0.5))]++;
FOR(i, 256) hist_max=MAX(histogram[i], hist_max);
FOR(i, 256)
{
......@@ -73,7 +73,7 @@ static gboolean update_histogram_cb(GtkImage *image, GdkFrameClock *, gpointer p
}
if (y>=0 && y<256 && x >=0 && x<256)
{
SPRINTF(text, "Y[%f]=%f.2%%", x*(max-min-0.5)/256+min, histogram[x]*100/(float)channel->total_length);
SPRINTF(text, "Y[%f]=%f.2%%", x*(max_val-min_val-0.5)/256+min_val, histogram[x]*100/(float)channel->total_length);
gtk_statusbar_push(GTK_STATUSBAR(pointer_statusbar), 0, text);
}
break;
......@@ -189,10 +189,10 @@ void histogram_cb(GtkToolButton *toolbutton, gpointer pointer_statusbar )
gtk_container_add(GTK_CONTAINER(histogram), histogram_scrolled_window);
gtk_container_add(GTK_CONTAINER(histogram), legend_box);
SPRINTF(text, "%f", min);
SPRINTF(text, "%f", min_val);
label=gtk_label_new(text);
gtk_box_pack_start(GTK_BOX(legend_box), label, FALSE, FALSE, 0);
SPRINTF(text, "%f", max);
SPRINTF(text, "%f", max_val);
label=gtk_label_new(text);
gtk_box_pack_end(GTK_BOX(legend_box), label, FALSE, FALSE, 0);
......
......@@ -168,14 +168,14 @@ gboolean update_Y800_image(GtkImage *image, GdkFrameClock *, gpointer pointer_st
uint32_t *values;
char text[64];
gain=1/(max-min);
gain=1/(max_val-min_val);
if (blc_command_loop_start()){
values = (uint32_t*)image_buffer;
if (channel->type=='UIN8')
FOR(i, channel->size) values[i]=color_map[channel->uchars[i]];
else if (channel->type=='FL32')
FOR(i, channel->total_length) values[i]=color_map[CLIP_UCHAR((channel->floats[i]-min)*256*gain-0.5f)];
FOR(i, channel->total_length) values[i]=color_map[CLIP_UCHAR((channel->floats[i]-min_val)*256*gain-0.5f)];
else EXIT_ON_ARRAY_ERROR(channel, "Type not managed");
gtk_image_set_from_surface(image, image_surface);
......
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