Mercurial > geeqie.yaz
comparison src/pan-view.c @ 30:a310e31fc513
Mon Apr 4 12:07:05 2005 John Ellis <johne@verizon.net>
* pan-view.c: Optimize pixbuf_draw_line, and use pixbuf_set_rect_fill
to draw the background.
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
##### an offical release when making enhancements and translation updates. #####
author | gqview |
---|---|
date | Mon, 04 Apr 2005 16:13:18 +0000 |
parents | 8a8ec4b3e769 |
children | 96ac60a9c0f1 |
comparison
equal
deleted
inserted
replaced
29:8a8ec4b3e769 | 30:a310e31fc513 |
---|---|
482 pp += p_step; | 482 pp += p_step; |
483 } | 483 } |
484 } | 484 } |
485 } | 485 } |
486 | 486 |
487 static gint util_clip_line(gdouble clip_x, gdouble clip_y, gdouble clip_w, gdouble clip_h, | |
488 gdouble x1, gdouble y1, gdouble x2, gdouble y2, | |
489 gdouble *rx1, gdouble *ry1, gdouble *rx2, gdouble *ry2) | |
490 { | |
491 gint flip = FALSE; | |
492 gdouble d; | |
493 | |
494 if (x1 > x2) | |
495 { | |
496 gdouble t; | |
497 | |
498 t = x1; | |
499 x1 = x2; | |
500 x2 = t; | |
501 | |
502 t = y1; | |
503 y1 = y2; | |
504 y2 = t; | |
505 | |
506 flip = TRUE; | |
507 } | |
508 | |
509 if (x2 < clip_x || x1 > clip_x + clip_w) return FALSE; | |
510 | |
511 if (y1 < y2) | |
512 { | |
513 if (y2 < clip_y || y1 > clip_y + clip_h) return FALSE; | |
514 } | |
515 else | |
516 { | |
517 if (y1 < clip_y || y2 > clip_y + clip_h) return FALSE; | |
518 } | |
519 | |
520 #if 0 | |
521 if (x1 >= clip_x && x2 <= clip_x + clip_w) | |
522 { | |
523 if (y1 < y2) | |
524 { | |
525 if (y1 >= clip_y && y2 <= clip_y + clip_h) return TRUE; | |
526 } | |
527 else | |
528 { | |
529 if (y2 >= clip_y && y1 <= clip_y + clip_h) return TRUE; | |
530 } | |
531 } | |
532 #endif | |
533 | |
534 d = x2 - x1; | |
535 if (d > 0.0) | |
536 { | |
537 gdouble slope; | |
538 | |
539 slope = (y2 - y1) / d; | |
540 if (x1 < clip_x) | |
541 { | |
542 y1 = y1 + slope * (clip_x - x1); | |
543 x1 = clip_x; | |
544 } | |
545 if (x2 > clip_x + clip_w) | |
546 { | |
547 y2 = y2 + slope * (clip_x + clip_w - x2); | |
548 x2 = clip_x + clip_w; | |
549 } | |
550 } | |
551 | |
552 if (y1 < y2) | |
553 { | |
554 if (y2 < clip_y || y1 > clip_y + clip_h) return FALSE; | |
555 } | |
556 else | |
557 { | |
558 gdouble t; | |
559 | |
560 if (y1 < clip_y || y2 > clip_y + clip_h) return FALSE; | |
561 | |
562 t = x1; | |
563 x1 = x2; | |
564 x2 = t; | |
565 | |
566 t = y1; | |
567 y1 = y2; | |
568 y2 = t; | |
569 | |
570 flip = !flip; | |
571 } | |
572 | |
573 d = y2 - y1; | |
574 if (d > 0.0) | |
575 { | |
576 gdouble slope; | |
577 | |
578 slope = (x2 - x1) / d; | |
579 if (y1 < clip_y) | |
580 { | |
581 x1 = x1 + slope * (clip_y - y1); | |
582 y1 = clip_y; | |
583 } | |
584 if (y2 > clip_y + clip_h) | |
585 { | |
586 x2 = x2 + slope * (clip_y + clip_h - y2); | |
587 y2 = clip_y + clip_h; | |
588 } | |
589 } | |
590 | |
591 if (flip) | |
592 { | |
593 *rx1 = x2; | |
594 *ry1 = y2; | |
595 *rx2 = x1; | |
596 *ry2 = y1; | |
597 } | |
598 else | |
599 { | |
600 *rx1 = x1; | |
601 *ry1 = y1; | |
602 *rx2 = x2; | |
603 *ry2 = y2; | |
604 } | |
605 | |
606 return TRUE; | |
607 } | |
608 | |
487 static void pixbuf_draw_line(GdkPixbuf *pb, | 609 static void pixbuf_draw_line(GdkPixbuf *pb, |
488 gint clip_x, gint clip_y, gint clip_w, gint clip_h, | 610 gint clip_x, gint clip_y, gint clip_w, gint clip_h, |
489 gint x1, gint y1, gint x2, gint y2, | 611 gint x1, gint y1, gint x2, gint y2, |
490 guint8 r, guint8 g, guint8 b, guint8 a) | 612 guint8 r, guint8 g, guint8 b, guint8 a) |
491 { | 613 { |
492 gint p_alpha; | 614 gint p_alpha; |
493 gint pw, ph, prs; | 615 gint pw, ph, prs; |
494 gint rx, ry, rw, rh; | 616 gint rx, ry, rw, rh; |
495 gint fx1, fy1, fx2, fy2; | 617 gdouble rx1, ry1, rx2, ry2; |
496 guchar *p_pix; | 618 guchar *p_pix; |
497 guchar *pp; | 619 guchar *pp; |
498 gint p_step; | 620 gint p_step; |
499 gint xd, yd; | 621 gdouble slope; |
500 gint xa, ya; | 622 gdouble x, y; |
501 gdouble xstep, ystep; | 623 gint px, py; |
502 gdouble i, j; | 624 gint cx1, cy1, cx2, cy2; |
503 gint n, nt; | |
504 gint x, y; | |
505 | 625 |
506 if (!pb) return; | 626 if (!pb) return; |
507 | 627 |
508 pw = gdk_pixbuf_get_width(pb); | 628 pw = gdk_pixbuf_get_width(pb); |
509 ph = gdk_pixbuf_get_height(pb); | 629 ph = gdk_pixbuf_get_height(pb); |
510 | 630 |
511 if (!util_clip_region(0, 0, pw, ph, | 631 if (!util_clip_region(0, 0, pw, ph, |
512 clip_x, clip_y, clip_w, clip_h, | 632 clip_x, clip_y, clip_w, clip_h, |
513 &rx, &ry, &rw, &rh)) return; | 633 &rx, &ry, &rw, &rh)) return; |
514 | 634 if (!util_clip_line((gdouble)rx, (gdouble)ry, (gdouble)rw, (gdouble)rh, |
515 fx1 = rx; | 635 (gdouble)x1, (gdouble)y1, (gdouble)x2, (gdouble)y2, |
516 fy1 = ry; | 636 &rx1, &ry1, &rx2, &ry2)) return; |
517 fx2 = rx + rw; | 637 |
518 fy2 = ry + rh; | 638 cx1 = rx; |
519 | 639 cy1 = ry; |
520 xd = x2 - x1; | 640 cx2 = rx + rw; |
521 yd = y2 - y1; | 641 cy2 = ry + rh; |
522 xa = abs(xd); | |
523 ya = abs(yd); | |
524 | |
525 if (xa == 0 && ya == 0) return; | |
526 #if 0 | |
527 nt = sqrt(xd * xd + yd * yd); | |
528 #endif | |
529 nt = (xa > ya) ? xa : ya; | |
530 xstep = (double)xd / nt; | |
531 ystep = (double)yd / nt; | |
532 | 642 |
533 p_alpha = gdk_pixbuf_get_has_alpha(pb); | 643 p_alpha = gdk_pixbuf_get_has_alpha(pb); |
534 prs = gdk_pixbuf_get_rowstride(pb); | 644 prs = gdk_pixbuf_get_rowstride(pb); |
535 p_pix = gdk_pixbuf_get_pixels(pb); | 645 p_pix = gdk_pixbuf_get_pixels(pb); |
536 | 646 |
537 p_step = (p_alpha) ? 4 : 3; | 647 p_step = (p_alpha) ? 4 : 3; |
538 | 648 |
539 i = (double)y1; | 649 if (fabs(rx2 - rx1) > fabs(ry2 - ry1)) |
540 j = (double)x1; | 650 { |
541 for (n = 0; n < nt; n++) | 651 if (rx1 > rx2) |
542 { | 652 { |
543 x = (gint)(j + 0.5); | 653 gdouble t; |
544 y = (gint)(i + 0.5); | 654 t = rx1; rx1 = rx2; rx2 = t; |
545 | 655 t = ry1; ry1 = ry2; ry2 = t; |
546 if (x >= fx1 && x < fx2 && | 656 } |
547 y >= fy1 && y < fy2) | 657 |
548 { | 658 slope = rx2 - rx1; |
549 pp = p_pix + y * prs + x * p_step; | 659 if (slope != 0.0) slope = (ry2 - ry1) / slope; |
550 *pp = (r * a + *pp * (256-a)) >> 8; | 660 for (x = rx1; x < rx2; x += 1.0) |
551 pp++; | 661 { |
552 *pp = (g * a + *pp * (256-a)) >> 8; | 662 px = (gint)(x + 0.5); |
553 pp++; | 663 py = (gint)(ry1 + (x - rx1) * slope + 0.5); |
554 *pp = (b * a + *pp * (256-a)) >> 8; | 664 |
555 } | 665 if (px >= cx1 && px < cx2 && py >= cy1 && py < cy2) |
556 i += ystep; | 666 { |
557 j += xstep; | 667 pp = p_pix + py * prs + px * p_step; |
668 *pp = (r * a + *pp * (256-a)) >> 8; | |
669 pp++; | |
670 *pp = (g * a + *pp * (256-a)) >> 8; | |
671 pp++; | |
672 *pp = (b * a + *pp * (256-a)) >> 8; | |
673 } | |
674 } | |
675 } | |
676 else | |
677 { | |
678 if (ry1 > ry2) | |
679 { | |
680 gdouble t; | |
681 t = rx1; rx1 = rx2; rx2 = t; | |
682 t = ry1; ry1 = ry2; ry2 = t; | |
683 } | |
684 | |
685 slope = ry2 - ry1; | |
686 if (slope != 0.0) slope = (rx2 - rx1) / slope; | |
687 for (y = ry1; y < ry2; y += 1.0) | |
688 { | |
689 px = (gint)(rx1 + (y - ry1) * slope + 0.5); | |
690 py = (gint)(y + 0.5); | |
691 | |
692 if (px >= cx1 && px < cx2 && py >= cy1 && py < cy2) | |
693 { | |
694 pp = p_pix + py * prs + px * p_step; | |
695 *pp = (r * a + *pp * (256-a)) >> 8; | |
696 pp++; | |
697 *pp = (g * a + *pp * (256-a)) >> 8; | |
698 pp++; | |
699 *pp = (b * a + *pp * (256-a)) >> 8; | |
700 } | |
701 } | |
558 } | 702 } |
559 } | 703 } |
560 | 704 |
561 static void pixbuf_draw_fade_linear(guchar *p_pix, gint prs, gint p_alpha, | 705 static void pixbuf_draw_fade_linear(guchar *p_pix, gint prs, gint p_alpha, |
562 gint s, gint vertical, gint border, | 706 gint s, gint vertical, gint border, |
2647 PanWindow *pw = data; | 2791 PanWindow *pw = data; |
2648 GList *list; | 2792 GList *list; |
2649 GList *work; | 2793 GList *work; |
2650 gint i; | 2794 gint i; |
2651 | 2795 |
2652 pixbuf_draw_rect_fill(pixbuf, | 2796 pixbuf_set_rect_fill(pixbuf, |
2653 0, 0, width, height, | 2797 0, 0, width, height, |
2654 PAN_BACKGROUND_COLOR, 255); | 2798 PAN_BACKGROUND_COLOR, 255); |
2655 | 2799 |
2656 for (i = (x / PAN_GRID_SIZE) * PAN_GRID_SIZE; i < x + width; i += PAN_GRID_SIZE) | 2800 for (i = (x / PAN_GRID_SIZE) * PAN_GRID_SIZE; i < x + width; i += PAN_GRID_SIZE) |
2657 { | 2801 { |
2658 gint rx, ry, rw, rh; | 2802 gint rx, ry, rw, rh; |
2659 | 2803 |