Mercurial > geeqie
comparison src/image.c @ 398:c4080362d619
image post-processing (rotation and color management) moved to
pixbuf-renderer
author | nadvornik |
---|---|
date | Thu, 17 Apr 2008 17:44:54 +0000 |
parents | 0226daf8c30b |
children | 49c1cbe058ae |
comparison
equal
deleted
inserted
replaced
397:a7be56e84870 | 398:c4080362d619 |
---|---|
34 | 34 |
35 /* define this so that more bytes are read per idle loop on larger images (> 1MB) */ | 35 /* define this so that more bytes are read per idle loop on larger images (> 1MB) */ |
36 #define IMAGE_THROTTLE_LARGER_IMAGES 1 | 36 #define IMAGE_THROTTLE_LARGER_IMAGES 1 |
37 | 37 |
38 /* throttle factor to increase read bytes by (2 is double, 3 is triple, etc.) */ | 38 /* throttle factor to increase read bytes by (2 is double, 3 is triple, etc.) */ |
39 #define IMAGE_THROTTLE_FACTOR 4 | 39 #define IMAGE_THROTTLE_FACTOR 32 |
40 | 40 |
41 /* the file size at which throttling take place */ | 41 /* the file size at which throttling take place */ |
42 #define IMAGE_THROTTLE_THRESHOLD 1048576 | 42 #define IMAGE_THROTTLE_THRESHOLD 1048576 |
43 | 43 |
44 #define IMAGE_AUTO_REFRESH_TIME 3000 | 44 #define IMAGE_AUTO_REFRESH_TIME 3000 |
198 /* | 198 /* |
199 *------------------------------------------------------------------- | 199 *------------------------------------------------------------------- |
200 * rotation, flip, etc. | 200 * rotation, flip, etc. |
201 *------------------------------------------------------------------- | 201 *------------------------------------------------------------------- |
202 */ | 202 */ |
203 | |
204 | |
205 #if 0 | |
203 | 206 |
204 static void image_alter_real(ImageWindow *imd, AlterType type, gint clamp) | 207 static void image_alter_real(ImageWindow *imd, AlterType type, gint clamp) |
205 { | 208 { |
206 PixbufRenderer *pr; | 209 PixbufRenderer *pr; |
207 GdkPixbuf *new = NULL; | 210 GdkPixbuf *new = NULL; |
298 { | 301 { |
299 image_alter_real(imd, imd->delay_alter_type, clamp); | 302 image_alter_real(imd, imd->delay_alter_type, clamp); |
300 } | 303 } |
301 } | 304 } |
302 | 305 |
306 | |
303 static void image_post_process_color_cb(ColorMan *cm, ColorManReturnType type, gpointer data) | 307 static void image_post_process_color_cb(ColorMan *cm, ColorManReturnType type, gpointer data) |
304 { | 308 { |
305 ImageWindow *imd = data; | 309 ImageWindow *imd = data; |
306 | 310 |
307 color_man_free(cm); | 311 color_man_free(cm); |
317 | 321 |
318 image_post_process_alter(imd, FALSE); | 322 image_post_process_alter(imd, FALSE); |
319 | 323 |
320 image_read_ahead_start(imd); | 324 image_read_ahead_start(imd); |
321 } | 325 } |
322 | 326 #endif |
323 static gint image_post_process_color(ImageWindow *imd, gint start_row, ExifData *exif) | 327 |
328 static gint image_post_process_color(ImageWindow *imd, gint start_row, ExifData *exif, gint run_in_bg) | |
324 { | 329 { |
325 ColorMan *cm; | 330 ColorMan *cm; |
326 ColorManProfileType input_type; | 331 ColorManProfileType input_type; |
327 ColorManProfileType screen_type; | 332 ColorManProfileType screen_type; |
328 const gchar *input_file; | 333 const gchar *input_file; |
393 guint data_len; | 398 guint data_len; |
394 if (debug) printf("Found embedded color profile\n"); | 399 if (debug) printf("Found embedded color profile\n"); |
395 | 400 |
396 data = (unsigned char *) exif_item_get_data(item, &data_len); | 401 data = (unsigned char *) exif_item_get_data(item, &data_len); |
397 | 402 |
398 cm = color_man_new_embedded(imd, NULL, | 403 cm = color_man_new_embedded(run_in_bg ? imd : NULL, NULL, |
399 data, data_len, | 404 data, data_len, |
400 screen_type, screen_file, | 405 screen_type, screen_file); |
401 image_post_process_color_cb, imd); | |
402 } | 406 } |
403 else | 407 else |
404 { | 408 { |
405 cm = color_man_new(imd, NULL, | 409 cm = color_man_new(run_in_bg ? imd : NULL, NULL, |
406 input_type, input_file, | 410 input_type, input_file, |
407 screen_type, screen_file, | 411 screen_type, screen_file); |
408 image_post_process_color_cb, imd); | |
409 } | 412 } |
410 | 413 |
411 if (cm) | 414 if (cm) |
412 { | 415 { |
413 if (start_row > 0) | 416 if (start_row > 0) |
415 cm->row = start_row; | 418 cm->row = start_row; |
416 cm->incremental_sync = TRUE; | 419 cm->incremental_sync = TRUE; |
417 } | 420 } |
418 | 421 |
419 imd->cm = (gpointer)cm; | 422 imd->cm = (gpointer)cm; |
423 #if 0 | |
424 if (run_in_bg) color_man_start_bg(imd->cm, image_post_process_color_cb, imd); | |
425 #endif | |
420 return TRUE; | 426 return TRUE; |
421 } | 427 } |
422 | 428 |
423 return FALSE; | 429 return FALSE; |
424 } | 430 } |
425 | 431 |
426 static void image_post_process(ImageWindow *imd, gint clamp) | 432 static void image_post_process(ImageWindow *imd, gint clamp) |
427 { | 433 { |
434 #if 0 | |
428 ExifData *exif = NULL; | 435 ExifData *exif = NULL; |
429 | 436 |
430 if (!image_get_pixbuf(imd)) return; | 437 if (!image_get_pixbuf(imd)) return; |
431 | 438 |
432 if (debug) printf("%s image postprocess: %s\n", get_exec_time(), imd->image_fd->name); | 439 if (debug) printf("%s image postprocess: %s\n", get_exec_time(), imd->image_fd->name); |
434 if (options->image.exif_rotate_enable || | 441 if (options->image.exif_rotate_enable || |
435 (imd->color_profile_enable && imd->color_profile_use_image) ) | 442 (imd->color_profile_enable && imd->color_profile_use_image) ) |
436 { | 443 { |
437 exif = exif_read_fd(imd->image_fd, (imd->color_profile_enable && imd->color_profile_use_image)); | 444 exif = exif_read_fd(imd->image_fd, (imd->color_profile_enable && imd->color_profile_use_image)); |
438 } | 445 } |
439 | |
440 if (options->image.exif_rotate_enable && exif) | 446 if (options->image.exif_rotate_enable && exif) |
441 { | 447 { |
442 gint orientation; | 448 gint orientation; |
443 | 449 |
444 if (exif_get_integer(exif, "Exif.Image.Orientation", &orientation)) | 450 if (exif_get_integer(exif, "Exif.Image.Orientation", &orientation)) |
495 } | 501 } |
496 | 502 |
497 if (rotate) image_state_set(imd, IMAGE_STATE_ROTATE_AUTO); | 503 if (rotate) image_state_set(imd, IMAGE_STATE_ROTATE_AUTO); |
498 } | 504 } |
499 } | 505 } |
500 | |
501 if (imd->color_profile_enable) | 506 if (imd->color_profile_enable) |
502 { | 507 { |
503 if (!image_post_process_color(imd, 0, exif)) | 508 if (!image_post_process_color(imd, 0, exif, TRUE)) |
504 { | 509 { |
505 /* fixme: note error to user */ | 510 /* fixme: note error to user */ |
506 image_state_set(imd, IMAGE_STATE_COLOR_ADJ); | 511 image_state_set(imd, IMAGE_STATE_COLOR_ADJ); |
507 } | 512 } |
508 } | 513 } |
509 | 514 |
515 | |
510 if (!imd->cm) image_post_process_alter(imd, clamp); | 516 if (!imd->cm) image_post_process_alter(imd, clamp); |
511 | 517 |
512 exif_free(exif); | 518 exif_free(exif); |
513 } | 519 #endif |
520 } | |
521 | |
522 static void image_post_process_tile_color_cb(PixbufRenderer *pr, GdkPixbuf **pixbuf, gint x, gint y, gint w, gint h, gpointer data) | |
523 { | |
524 ImageWindow *imd = (ImageWindow *)data; | |
525 if (imd->cm) color_man_correct_region(imd->cm, *pixbuf, x, y, w, h); | |
526 if (imd->desaturate) pixbuf_desaturate_rect(*pixbuf, x, y, w, h); | |
527 | |
528 } | |
529 | |
530 void image_alter(ImageWindow *imd, AlterType type) | |
531 { | |
532 | |
533 const static gint rotate_90[] = {1, 6, 7, 8, 5, 2, 3, 4, 1}; | |
534 const static gint rotate_90_cc[] = {1, 8, 5, 6, 7, 4, 1, 2, 3}; | |
535 const static gint rotate_180[] = {1, 3, 4, 1, 2, 7, 8, 5, 6}; | |
536 const static gint mirror[] = {1, 2, 1, 4, 3, 6, 5, 8, 7}; | |
537 const static gint flip[] = {1, 4, 3, 2, 1, 8, 7, 6, 5}; | |
538 | |
539 | |
540 if (!imd || !imd->pr) return; | |
541 | |
542 if (imd->orientation < 1 || imd->orientation > 8) imd->orientation = 1; | |
543 | |
544 switch (type) | |
545 { | |
546 case ALTER_ROTATE_90: | |
547 imd->orientation = rotate_90[imd->orientation]; | |
548 break; | |
549 case ALTER_ROTATE_90_CC: | |
550 imd->orientation = rotate_90_cc[imd->orientation]; | |
551 break; | |
552 case ALTER_ROTATE_180: | |
553 imd->orientation = rotate_180[imd->orientation]; | |
554 break; | |
555 case ALTER_MIRROR: | |
556 imd->orientation = mirror[imd->orientation]; | |
557 break; | |
558 case ALTER_FLIP: | |
559 imd->orientation = flip[imd->orientation]; | |
560 break; | |
561 case ALTER_DESATURATE: | |
562 imd->desaturate = !imd->desaturate; | |
563 break; | |
564 case ALTER_NONE: | |
565 default: | |
566 return; | |
567 break; | |
568 } | |
569 pixbuf_renderer_set_orientation((PixbufRenderer *)imd->pr, imd->orientation); | |
570 if (imd->cm || imd->desaturate) | |
571 pixbuf_renderer_set_post_process_func((PixbufRenderer *)imd->pr, image_post_process_tile_color_cb, (gpointer) imd, (imd->cm != NULL) ); | |
572 else | |
573 pixbuf_renderer_set_post_process_func((PixbufRenderer *)imd->pr, NULL, NULL, TRUE); | |
574 } | |
575 | |
514 | 576 |
515 /* | 577 /* |
516 *------------------------------------------------------------------- | 578 *------------------------------------------------------------------- |
517 * read ahead (prebuffer) | 579 * read ahead (prebuffer) |
518 *------------------------------------------------------------------- | 580 *------------------------------------------------------------------- |
563 { | 625 { |
564 /* already started ? */ | 626 /* already started ? */ |
565 if (!imd->read_ahead_fd || imd->read_ahead_il || imd->read_ahead_pixbuf) return; | 627 if (!imd->read_ahead_fd || imd->read_ahead_il || imd->read_ahead_pixbuf) return; |
566 | 628 |
567 /* still loading ?, do later */ | 629 /* still loading ?, do later */ |
568 if (imd->il || imd->cm) return; | 630 if (imd->il /*|| imd->cm*/) return; |
569 | 631 |
570 if (debug) printf("%s read ahead started for :%s\n", get_exec_time(), imd->read_ahead_fd->path); | 632 if (debug) printf("%s read ahead started for :%s\n", get_exec_time(), imd->read_ahead_fd->path); |
571 | 633 |
572 imd->read_ahead_il = image_loader_new(imd->read_ahead_fd); | 634 imd->read_ahead_il = image_loader_new(imd->read_ahead_fd); |
573 | 635 |
632 if (imd->prev_color_row >= 0) | 694 if (imd->prev_color_row >= 0) |
633 { | 695 { |
634 ExifData *exif = NULL; | 696 ExifData *exif = NULL; |
635 | 697 |
636 if (imd->color_profile_use_image) exif = exif_read_fd(imd->image_fd, TRUE); | 698 if (imd->color_profile_use_image) exif = exif_read_fd(imd->image_fd, TRUE); |
637 image_post_process_color(imd, imd->prev_color_row, exif); | 699 // image_post_process_color(imd, imd->prev_color_row, exif, TRUE); |
638 exif_free(exif); | 700 exif_free(exif); |
639 } | 701 } |
640 success = TRUE; | 702 success = TRUE; |
641 } | 703 } |
642 else | 704 else |
1201 return pixbuf_renderer_get_pixbuf((PixbufRenderer *)imd->pr); | 1263 return pixbuf_renderer_get_pixbuf((PixbufRenderer *)imd->pr); |
1202 } | 1264 } |
1203 | 1265 |
1204 void image_change_pixbuf(ImageWindow *imd, GdkPixbuf *pixbuf, gdouble zoom) | 1266 void image_change_pixbuf(ImageWindow *imd, GdkPixbuf *pixbuf, gdouble zoom) |
1205 { | 1267 { |
1268 | |
1269 ExifData *exif = NULL; | |
1270 gint orientation; | |
1271 | |
1272 if (options->image.exif_rotate_enable || | |
1273 (imd->color_profile_enable && imd->color_profile_use_image) ) | |
1274 { | |
1275 exif = exif_read_fd(imd->image_fd, (imd->color_profile_enable && imd->color_profile_use_image)); | |
1276 } | |
1277 | |
1278 if (options->image.exif_rotate_enable && exif && exif_get_integer(exif, "Exif.Image.Orientation", &orientation)) | |
1279 imd->orientation = orientation; | |
1280 else | |
1281 imd->orientation = 1; | |
1282 | |
1283 pixbuf_renderer_set_post_process_func((PixbufRenderer *)imd->pr, NULL, NULL, FALSE); | |
1284 if (imd->cm) | |
1285 { | |
1286 color_man_free(imd->cm); | |
1287 imd->cm = NULL; | |
1288 } | |
1289 | |
1206 pixbuf_renderer_set_pixbuf((PixbufRenderer *)imd->pr, pixbuf, zoom); | 1290 pixbuf_renderer_set_pixbuf((PixbufRenderer *)imd->pr, pixbuf, zoom); |
1291 pixbuf_renderer_set_orientation((PixbufRenderer *)imd->pr, imd->orientation); | |
1292 | |
1293 if (imd->color_profile_enable) | |
1294 { | |
1295 if (!image_post_process_color(imd, 0, exif, FALSE)) | |
1296 { | |
1297 /* fixme: note error to user */ | |
1298 // image_state_set(imd, IMAGE_STATE_COLOR_ADJ); | |
1299 } | |
1300 } | |
1301 | |
1302 exif_free(exif); | |
1303 | |
1304 if (imd->cm || imd->desaturate) | |
1305 pixbuf_renderer_set_post_process_func((PixbufRenderer *)imd->pr, image_post_process_tile_color_cb, (gpointer) imd, (imd->cm != NULL) ); | |
1306 | |
1207 image_state_set(imd, IMAGE_STATE_IMAGE); | 1307 image_state_set(imd, IMAGE_STATE_IMAGE); |
1208 } | 1308 } |
1209 | 1309 |
1210 void image_change_from_collection(ImageWindow *imd, CollectionData *cd, CollectInfo *info, gdouble zoom) | 1310 void image_change_from_collection(ImageWindow *imd, CollectionData *cd, CollectInfo *info, gdouble zoom) |
1211 { | 1311 { |
1315 source->prev_fd = NULL; | 1415 source->prev_fd = NULL; |
1316 | 1416 |
1317 imd->completed = source->completed; | 1417 imd->completed = source->completed; |
1318 imd->state = source->state; | 1418 imd->state = source->state; |
1319 source->state = IMAGE_STATE_NONE; | 1419 source->state = IMAGE_STATE_NONE; |
1420 | |
1421 imd->orientation = source->orientation; | |
1422 imd->desaturate = source->desaturate; | |
1320 | 1423 |
1321 pixbuf_renderer_move(PIXBUF_RENDERER(imd->pr), PIXBUF_RENDERER(source->pr)); | 1424 pixbuf_renderer_move(PIXBUF_RENDERER(imd->pr), PIXBUF_RENDERER(source->pr)); |
1425 | |
1426 if (imd->cm || imd->desaturate) | |
1427 pixbuf_renderer_set_post_process_func((PixbufRenderer *)imd->pr, image_post_process_tile_color_cb, (gpointer) imd, (imd->cm != NULL) ); | |
1428 else | |
1429 pixbuf_renderer_set_post_process_func((PixbufRenderer *)imd->pr, NULL, NULL, TRUE); | |
1430 | |
1322 } | 1431 } |
1323 | 1432 |
1324 /* manipulation */ | 1433 /* manipulation */ |
1325 | 1434 |
1326 void image_area_changed(ImageWindow *imd, gint x, gint y, gint width, gint height) | 1435 void image_area_changed(ImageWindow *imd, gint x, gint y, gint width, gint height) |
1355 { | 1464 { |
1356 pixbuf_renderer_set_scroll_center(PIXBUF_RENDERER(imd->pr), x, y); | 1465 pixbuf_renderer_set_scroll_center(PIXBUF_RENDERER(imd->pr), x, y); |
1357 } | 1466 } |
1358 | 1467 |
1359 | 1468 |
1360 | 1469 #if 0 |
1361 void image_alter(ImageWindow *imd, AlterType type) | 1470 void image_alter(ImageWindow *imd, AlterType type) |
1362 { | 1471 { |
1363 if (pixbuf_renderer_get_tiles((PixbufRenderer *)imd->pr)) return; | 1472 if (pixbuf_renderer_get_tiles((PixbufRenderer *)imd->pr)) return; |
1364 | 1473 |
1365 if (imd->il || imd->cm) | 1474 if (imd->il || imd->cm) |
1375 return; | 1484 return; |
1376 } | 1485 } |
1377 | 1486 |
1378 image_alter_real(imd, type, TRUE); | 1487 image_alter_real(imd, type, TRUE); |
1379 } | 1488 } |
1489 #endif | |
1380 | 1490 |
1381 void image_zoom_adjust(ImageWindow *imd, gdouble increment) | 1491 void image_zoom_adjust(ImageWindow *imd, gdouble increment) |
1382 { | 1492 { |
1383 pixbuf_renderer_zoom_adjust((PixbufRenderer *)imd->pr, increment); | 1493 pixbuf_renderer_zoom_adjust((PixbufRenderer *)imd->pr, increment); |
1384 } | 1494 } |
1887 imd->func_tile_request = NULL; | 1997 imd->func_tile_request = NULL; |
1888 imd->func_tile_dispose = NULL; | 1998 imd->func_tile_dispose = NULL; |
1889 | 1999 |
1890 imd->func_button = NULL; | 2000 imd->func_button = NULL; |
1891 imd->func_scroll = NULL; | 2001 imd->func_scroll = NULL; |
2002 | |
2003 imd->orientation = 1; | |
1892 | 2004 |
1893 imd->pr = GTK_WIDGET(pixbuf_renderer_new()); | 2005 imd->pr = GTK_WIDGET(pixbuf_renderer_new()); |
1894 | 2006 |
1895 image_options_set(imd); | 2007 image_options_set(imd); |
1896 | 2008 |