a deriver pour afficher les objets. renvoie 1 pour continuer, 0 pour fermer l'application.
226 {
227
228 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
229
231 {
233 reload_program(m_program,
smart_path(
"data/shaders/tonemap.glsl") );
235 }
236
238 {
240 m_index= (m_index -1 + m_textures.size()) % m_textures.size();
241
242 title(m_index);
243 }
244
246 {
248 m_index= (m_index +1 + m_textures.size()) % m_textures.size();
249
250 title(m_index);
251 }
252
253
254 static float last_time= 0;
255
257 {
258 size_t time= timestamp(m_filenames[m_index].c_str());
259 if(time != m_times[m_index])
260 {
261
262 printf(
"reload image '%s'...\n", m_filenames[m_index].c_str());
263
264 Image image= read(m_filenames[m_index].c_str());
265 if(image.size())
266 {
267 m_times[m_index]= time;
268 m_images[m_index]= image;
269
270
271 glBindTexture(GL_TEXTURE_2D, m_textures[m_index]);
272 glTexImage2D(GL_TEXTURE_2D, 0,
273 GL_RGBA32F, image.width(), image.height(), 0,
274 GL_RGBA, GL_FLOAT, image.data());
275
276 glGenerateMipmap(GL_TEXTURE_2D);
277 }
278 }
279
281 }
282
284 {
286 {
288 if(filename && filename[0])
289 {
290
291
292 Image image= read(filename);
293 if(image.size())
294 {
295 m_images.push_back( image );
296 m_filenames.push_back( filename );
297 m_times.push_back( timestamp(filename) );
299
300 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
301 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
302 }
303 }
304
305 printf(
"index %d\n", m_index);
306 for(unsigned i= 0; i < m_filenames.size(); i++)
307 printf(
"images[%d] '%s'\n", i, m_filenames[i].c_str());
308 }
309
312 }
313
314
315 int xmouse, ymouse;
316 unsigned int bmouse= SDL_GetMouseState(&xmouse, &ymouse);
317
318 glBindVertexArray(m_vao);
319 glUseProgram(m_program);
320
321
322 GLuint sampler= 0;
323 if(!m_smooth)
324 sampler= m_sampler_nearest;
325
327 if(m_reference_index == -1)
328 program_use_texture(m_program,
"image_next", 1, m_textures[(m_index +1) % m_textures.size()], sampler);
329 else
331
332
333 if(bmouse & SDL_BUTTON(1))
334 program_uniform(m_program, "split", (int) xmouse);
335 else
336 program_uniform(m_program,
"split", (
int)
window_width() +2);
337
338
339 program_uniform(m_program, "channels", Color(m_red, m_green, m_blue, m_alpha));
340 program_uniform(m_program, "gray", float(m_gray));
341 program_uniform(m_program, "difference", float(m_difference));
342 program_uniform(m_program, "compression", m_compression);
343 program_uniform(m_program, "saturation", m_saturation);
344
345
346 if(bmouse & SDL_BUTTON(3))
347 {
349 if(wheel.y != 0)
350 {
351 m_zoom= m_zoom + float(wheel.y) / 4.f;
352 if(m_zoom < .1f) m_zoom= .1f;
353 if(m_zoom > 10.f) m_zoom= 10.f;
354 }
355 }
356
358 if(bmouse & SDL_BUTTON(3))
359 program_uniform(m_program, "zoom", m_zoom);
360 else
361 program_uniform(m_program, "zoom", 1.f);
362
363
365 {
367 m_graph= (m_graph +1) % 2;
368 }
369
370 program_uniform(m_program, "graph", int(m_graph));
372
373
374 glDrawArrays(GL_TRIANGLES, 0, 3);
375
376
378 {
380
381
382 std::string file= m_filenames[m_index];
383 size_t ext= file.rfind(".");
384 if(ext != std::string::npos)
385 file= file.substr(0, ext) + "-tone.png";
386
387 printf(
"writing '%s'...\n", file.c_str());
389 }
390
392 value(m_widgets, "saturation", m_saturation, 0.f, m_saturation_max*10, m_saturation_step);
393 value(m_widgets, "compression", m_compression, .1f, 10.f, .1f);
394
395 int reset= 0;
396 button(m_widgets,
"reset", reset);
397 if(reset) range(m_images[m_index]);
398
399 int reload= 0;
400 button(m_widgets,
"reload", reload);
401 if(reload)
402 {
403 Image image= read(m_filenames[m_index].c_str());
404 {
405 m_images[m_index]= image;
406 m_times[m_index]= timestamp(m_filenames[m_index].c_str());
407
408
409 glBindTexture(GL_TEXTURE_2D, m_textures[m_index]);
410 glTexImage2D(GL_TEXTURE_2D, 0,
411 GL_RGBA32F, image.width(), image.height(), 0,
412 GL_RGBA, GL_FLOAT, image.data());
413
414 glGenerateMipmap(GL_TEXTURE_2D);
415 }
416 }
417
418 int reference= (m_index == m_reference_index) ? 1 : 0;
419 if(
button(m_widgets,
"reference", reference))
420 {
421 if(reference) m_reference_index= m_index;
422 else m_reference_index= -1;
423 }
424
425 int export_all= 0;
426 button(m_widgets,
"export all", export_all);
427 if(export_all)
428 {
429 #pragma omp parallel for
430 for(unsigned i= 0; i < m_images.size(); i++)
431 {
432 Image image;
433 if(m_gray)
434 image= tone(gray(m_images[i]), m_saturation, m_compression);
435 else
436 image= tone(m_images[i], m_saturation, m_compression);
437
438 char filename[1024];
439 sprintf(filename, "%s-tone.png", m_filenames[i].c_str());
440 printf(
"exporting '%s'...\n", filename);
442 }
443 }
444
446 {
447 int px= xmouse;
449 float x= px / float(
window_width()) * m_images[m_index].width();
450 float y= py / float(
window_height()) * m_images[m_index].height();
451 Color pixel= m_images[m_index](x, y);
452 label(m_widgets, "pixel %d %d: %f %f %f", int(x), int(y), pixel.r, pixel.g, pixel.b);
453 }
454
456 button(m_widgets,
"R", m_red);
457 button(m_widgets,
"G", m_green);
458 button(m_widgets,
"B", m_blue);
459 button(m_widgets,
"A", m_alpha);
460 button(m_widgets,
"gray", m_gray);
461 button(m_widgets,
"smooth", m_smooth);
462
463 if(m_reference_index != -1)
464 button(m_widgets,
"diff to reference", m_difference);
465
467 {
468 static int list= 0;
469 button(m_widgets,
"select image...", list);
470 if(list)
471 {
472 char tmp[1024];
473 for(unsigned i= 0; i < m_filenames.size(); i++)
474 {
476 sprintf(tmp, "[%u] %s", i, m_filenames[i].c_str());
477 select(m_widgets, tmp, i, m_index);
478 }
479 }
480 }
481
482 end(m_widgets);
483
485
487 {
489
490 static int calls= 0;
492 printf(
"screenshot %d...\n", calls);
493 }
494
496 {
498
499 m_filenames.erase(m_filenames.begin() + m_index);
500 m_times.erase(m_times.begin() + m_index);
501 m_images.erase(m_images.begin() + m_index);
502 m_textures.erase(m_textures.begin() + m_index);
503 if(m_reference_index == m_index)
504 m_reference_index= -1;
505
506 if(m_textures.empty())
507 return 0;
508
509 m_index= m_index % int(m_textures.size());
510
511 title(m_index);
512 }
513
514 return 1;
515 }
void begin(Widgets &w)
debut de la description des elements de l'interface graphique.
bool button(Widgets &w, const char *text, int &status)
void clear_drop_events()
desactive drag/drop.
const std::vector< std::string > & drop_events()
drag/drop. recupere tous les fichiers.
int window_height()
renvoie la hauteur de la fenetre de l'application.
void clear_key_state(const SDL_Keycode key)
desactive une touche du clavier.
bool select(Widgets &w, const char *text, const int option, int &status)
int key_state(const SDL_Keycode key)
renvoie l'etat d'une touche du clavier. cf la doc SDL2 pour les codes.
void begin_line(Widgets &w)
place les prochains elements sur une nouvelle ligne.
SDL_MouseWheelEvent wheel_event()
renvoie le dernier evenement. etat de la molette de la souris / glisser sur le pad.
int window_width()
renvoie la largeur de la fenetre de l'application.
float global_time()
renvoie le temps ecoule depuis le lancement de l'application, en millisecondes.
bool write_image(const Image &image, const char *filename, const bool flipY)
enregistre une image au format .png
int screenshot(const char *filename)
enregistre le contenu de la fenetre dans un fichier. doit etre de type .png / .bmp
void program_use_texture(const GLuint program, const char *uniform, const int unit, const GLuint texture, const GLuint sampler)
configure le pipeline et le shader program pour utiliser une texture, et des parametres de filtrage,...