diff options
Diffstat (limited to 'src/ui/new_contact.c')
-rw-r--r-- | src/ui/new_contact.c | 110 |
1 files changed, 89 insertions, 21 deletions
diff --git a/src/ui/new_contact.c b/src/ui/new_contact.c index 28bc2bf..db40140 100644 --- a/src/ui/new_contact.c +++ b/src/ui/new_contact.c | |||
@@ -68,26 +68,43 @@ handle_id_drawing_area_draw(GtkWidget* drawing_area, | |||
68 | 68 | ||
69 | GdkPixbuf *image = NULL; | 69 | GdkPixbuf *image = NULL; |
70 | 70 | ||
71 | if (handle->image) | 71 | if (!handle->image) |
72 | { | 72 | goto render_image; |
73 | uint w, h; | 73 | |
74 | zbar_image_get_size(handle->image, &w, &h); | 74 | uint w, h; |
75 | 75 | zbar_image_get_size(handle->image, &w, &h); | |
76 | const void* data = zbar_image_get_data(handle->image); | 76 | |
77 | 77 | uint x, y, min_size; | |
78 | image = gdk_pixbuf_new_from_data( | 78 | min_size = (w < h? w : h); |
79 | data, | 79 | x = (w - min_size) / 2; |
80 | GDK_COLORSPACE_RGB, | 80 | y = (h - min_size) / 2; |
81 | FALSE, | 81 | |
82 | 8, | 82 | const void* data = (const void*) ( |
83 | w, | 83 | (const char*) zbar_image_get_data(handle->image) + |
84 | h, | 84 | (x + y * w) * 3 |
85 | w * 3, | 85 | ); |
86 | NULL, | 86 | |
87 | NULL | 87 | image = gdk_pixbuf_new_from_data( |
88 | ); | 88 | data, |
89 | } | 89 | GDK_COLORSPACE_RGB, |
90 | FALSE, | ||
91 | 8, | ||
92 | min_size, | ||
93 | min_size, | ||
94 | w * 3, | ||
95 | NULL, | ||
96 | NULL | ||
97 | ); | ||
90 | 98 | ||
99 | GString *scan_result = (GString*) zbar_image_get_userdata(handle->image); | ||
100 | |||
101 | if (!scan_result) | ||
102 | goto render_image; | ||
103 | |||
104 | gtk_entry_set_text(handle->id_entry, scan_result->str); | ||
105 | g_string_free(scan_result, TRUE); | ||
106 | |||
107 | render_image: | ||
91 | if (!image) | 108 | if (!image) |
92 | return FALSE; | 109 | return FALSE; |
93 | 110 | ||
@@ -143,6 +160,43 @@ idle_video_processing(gpointer user_data) | |||
143 | if (!image) | 160 | if (!image) |
144 | return TRUE; | 161 | return TRUE; |
145 | 162 | ||
163 | GString *scan_result = NULL; | ||
164 | |||
165 | zbar_image_t *y8 = zbar_image_convert( | ||
166 | image, | ||
167 | zbar_fourcc('Y', '8', '0', '0') | ||
168 | ); | ||
169 | |||
170 | if (zbar_scan_image(handle->scanner, y8) <= 0) | ||
171 | goto cleanup_scan; | ||
172 | |||
173 | const zbar_symbol_set_t* set = zbar_image_scanner_get_results( | ||
174 | handle->scanner | ||
175 | ); | ||
176 | |||
177 | const zbar_symbol_t* symbol = zbar_symbol_set_first_symbol(set); | ||
178 | |||
179 | if (!symbol) | ||
180 | goto cleanup_scan; | ||
181 | |||
182 | uint data_len = 0; | ||
183 | const char *data = NULL; | ||
184 | |||
185 | for (; symbol; symbol = zbar_symbol_next(symbol)) | ||
186 | { | ||
187 | if (zbar_symbol_get_count(symbol)) | ||
188 | continue; | ||
189 | |||
190 | data_len = zbar_symbol_get_data_length(symbol); | ||
191 | data = zbar_symbol_get_data(symbol); | ||
192 | } | ||
193 | |||
194 | if ((data_len > 0) && (data)) | ||
195 | scan_result = g_string_new_len(data, data_len); | ||
196 | |||
197 | cleanup_scan: | ||
198 | zbar_image_destroy(y8); | ||
199 | |||
146 | zbar_image_t *rgb = zbar_image_convert( | 200 | zbar_image_t *rgb = zbar_image_convert( |
147 | image, | 201 | image, |
148 | zbar_fourcc('R', 'G', 'B', '3') | 202 | zbar_fourcc('R', 'G', 'B', '3') |
@@ -151,6 +205,8 @@ idle_video_processing(gpointer user_data) | |||
151 | if (!rgb) | 205 | if (!rgb) |
152 | goto cleanup_image; | 206 | goto cleanup_image; |
153 | 207 | ||
208 | zbar_image_set_userdata(rgb, scan_result); | ||
209 | |||
154 | if (handle->image) | 210 | if (handle->image) |
155 | zbar_image_destroy(handle->image); | 211 | zbar_image_destroy(handle->image); |
156 | 212 | ||
@@ -169,12 +225,19 @@ _ui_new_contact_video_thread(void *args) | |||
169 | { | 225 | { |
170 | UI_NEW_CONTACT_Handle *handle = (UI_NEW_CONTACT_Handle*) args; | 226 | UI_NEW_CONTACT_Handle *handle = (UI_NEW_CONTACT_Handle*) args; |
171 | 227 | ||
172 | if (0 != zbar_video_open(handle->video, "/dev/video0")) | 228 | if (0 != zbar_video_open(handle->video, "")) |
173 | return NULL; | 229 | return NULL; |
174 | 230 | ||
175 | if (0 != zbar_video_enable(handle->video, 1)) | 231 | if (0 != zbar_video_enable(handle->video, 1)) |
176 | return NULL; | 232 | return NULL; |
177 | 233 | ||
234 | zbar_image_scanner_set_config( | ||
235 | handle->scanner, | ||
236 | ZBAR_QRCODE, | ||
237 | ZBAR_CFG_ENABLE, | ||
238 | TRUE | ||
239 | ); | ||
240 | |||
178 | handle->idle_processing = g_idle_add(idle_video_processing, handle); | 241 | handle->idle_processing = g_idle_add(idle_video_processing, handle); |
179 | return NULL; | 242 | return NULL; |
180 | } | 243 | } |
@@ -216,7 +279,7 @@ ui_new_contact_dialog_init(MESSENGER_Application *app, | |||
216 | ); | 279 | ); |
217 | 280 | ||
218 | handle->id_entry = GTK_ENTRY( | 281 | handle->id_entry = GTK_ENTRY( |
219 | gtk_builder_get_object(handle->builder, "platform_entry") | 282 | gtk_builder_get_object(handle->builder, "id_entry") |
220 | ); | 283 | ); |
221 | 284 | ||
222 | handle->cancel_button = GTK_BUTTON( | 285 | handle->cancel_button = GTK_BUTTON( |
@@ -263,6 +326,11 @@ ui_new_contact_dialog_cleanup(UI_NEW_CONTACT_Handle *handle) | |||
263 | 326 | ||
264 | g_object_unref(handle->builder); | 327 | g_object_unref(handle->builder); |
265 | 328 | ||
329 | if (handle->image) | ||
330 | zbar_image_destroy(handle->image); | ||
331 | |||
332 | handle->image = NULL; | ||
333 | |||
266 | zbar_image_scanner_destroy(handle->scanner); | 334 | zbar_image_scanner_destroy(handle->scanner); |
267 | zbar_video_destroy(handle->video); | 335 | zbar_video_destroy(handle->video); |
268 | } | 336 | } |