~ubuntu-branches/ubuntu/lucid/blender/lucid

« back to all changes in this revision

Viewing changes to source/blender/imbuf/intern/scaling.c

  • Committer: Bazaar Package Importer
  • Author(s): Chris Coulson
  • Date: 2009-08-06 22:32:19 UTC
  • mfrom: (1.2.10 upstream)
  • Revision ID: james.westby@ubuntu.com-20090806223219-8z4eej1u8levu4pz
Tags: 2.49a+dfsg-0ubuntu1
* Merge from debian unstable, remaining changes:
  - debian/control: Build-depend on python-2.6 rather than python-2.5.
  - debian/misc/*.desktop: Add Spanish translation to .desktop 
    files.
  - debian/pyversions: 2.6.
  - debian/rules: Clean *.o of source/blender/python/api2_2x/
* New upstream release (LP: #382153).
* Refreshed patches:
  - 01_sanitize_sys.patch
  - 02_tmp_in_HOME
  - 10_use_systemwide_ftgl
  - 70_portability_platform_detection
* Removed patches merged upstream:
  - 30_fix_python_syntax_warning
  - 90_ubuntu_ffmpeg_52_changes

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
 * ***** END GPL LICENSE BLOCK *****
27
27
 * allocimbuf.c
28
28
 *
29
 
 * $Id: scaling.c 16153 2008-08-17 17:22:10Z genscher $
 
29
 * $Id: scaling.c 20257 2009-05-18 10:34:26Z ton $
30
30
 */
31
31
 
32
32
#include "BLI_blenlib.h"
299
299
        if (ibuf1->rect==NULL && ibuf1->rect_float==NULL) return (0);
300
300
 
301
301
        do_rect= (ibuf1->rect != NULL);
302
 
        do_float= (ibuf1->rect_float != NULL);
303
302
 
304
303
        if (ibuf1->x <= 1) return(IMB_half_y(ibuf1));
305
304
        if (ibuf1->y <= 1) return(IMB_half_x(ibuf1));
312
311
        p1 = (uchar *) ibuf1->rect;
313
312
        dest=(uchar *) ibuf2->rect;
314
313
 
 
314
        do_float= (ibuf1->rect_float != NULL && ibuf2->rect_float != NULL);
 
315
 
315
316
        for(y=ibuf2->y;y>0;y--){
316
317
                if (do_rect) p2 = p1 + (ibuf1->x << 2);
317
318
                if (do_float) p2f = p1f + (ibuf1->x << 2);
595
596
        y_counter = 65536;
596
597
        for (y_src = 0; y_src < src_height; y_src++) {
597
598
                unsigned char* line = src + y_src * 4 * src_width;
598
 
                uintptr_t weight1y = 65536 - (y_dst & 0xffff);
599
 
                uintptr_t weight2y = 65536 - weight1y;
 
599
                uintptr_t weight1y = 65535 - (y_dst & 0xffff);
 
600
                uintptr_t weight2y = 65535 - weight1y;
600
601
                x_dst = 0;
601
602
                for (x_src = 0; x_src < src_width; x_src++) {
602
 
                        uintptr_t weight1x = 65536 - (x_dst & 0xffff);
603
 
                        uintptr_t weight2x = 65536 - weight1x;
 
603
                        uintptr_t weight1x = 65535 - (x_dst & 0xffff);
 
604
                        uintptr_t weight2x = 65535 - weight1x;
604
605
 
605
606
                        uintptr_t x = x_dst >> 16;
606
607
 
608
609
 
609
610
                        w = (weight1y * weight1x) >> 16;
610
611
 
611
 
                        dst_line1[x].r += (line[0] * w) >> 16;
612
 
                        dst_line1[x].g += (line[1] * w) >> 16;
613
 
                        dst_line1[x].b += (line[2] * w) >> 16;
614
 
                        dst_line1[x].a += (line[3] * w) >> 16;
 
612
                        /* ensure correct rounding, without this you get ugly banding, or too low color values (ton) */
 
613
                        dst_line1[x].r += (line[0] * w + 32767) >> 16;
 
614
                        dst_line1[x].g += (line[1] * w + 32767) >> 16;
 
615
                        dst_line1[x].b += (line[2] * w + 32767) >> 16;
 
616
                        dst_line1[x].a += (line[3] * w + 32767) >> 16;
615
617
                        dst_line1[x].weight += w;
616
618
 
617
619
                        w = (weight2y * weight1x) >> 16;
618
620
 
619
 
                        dst_line2[x].r += (line[0] * w) >> 16;
620
 
                        dst_line2[x].g += (line[1] * w) >> 16;
621
 
                        dst_line2[x].b += (line[2] * w) >> 16;
622
 
                        dst_line2[x].a += (line[3] * w) >> 16;
 
621
                        dst_line2[x].r += (line[0] * w + 32767) >> 16;
 
622
                        dst_line2[x].g += (line[1] * w + 32767) >> 16;
 
623
                        dst_line2[x].b += (line[2] * w + 32767) >> 16;
 
624
                        dst_line2[x].a += (line[3] * w + 32767) >> 16;
623
625
                        dst_line2[x].weight += w;
624
626
 
625
627
                        w = (weight1y * weight2x) >> 16;
626
628
 
627
 
                        dst_line1[x+1].r += (line[0] * w) >> 16;
628
 
                        dst_line1[x+1].g += (line[1] * w) >> 16;
629
 
                        dst_line1[x+1].b += (line[2] * w) >> 16;
630
 
                        dst_line1[x+1].a += (line[3] * w) >> 16;
 
629
                        dst_line1[x+1].r += (line[0] * w + 32767) >> 16;
 
630
                        dst_line1[x+1].g += (line[1] * w + 32767) >> 16;
 
631
                        dst_line1[x+1].b += (line[2] * w + 32767) >> 16;
 
632
                        dst_line1[x+1].a += (line[3] * w + 32767) >> 16;
631
633
                        dst_line1[x+1].weight += w;
632
634
 
633
635
                        w = (weight2y * weight2x) >> 16;
634
636
 
635
 
                        dst_line2[x+1].r += (line[0] * w) >> 16;
636
 
                        dst_line2[x+1].g += (line[1] * w) >> 16;
637
 
                        dst_line2[x+1].b += (line[2] * w) >> 16;
638
 
                        dst_line2[x+1].a += (line[3] * w) >> 16;
 
637
                        dst_line2[x+1].r += (line[0] * w + 32767) >> 16;
 
638
                        dst_line2[x+1].g += (line[1] * w + 32767) >> 16;
 
639
                        dst_line2[x+1].b += (line[2] * w + 32767) >> 16;
 
640
                        dst_line2[x+1].a += (line[3] * w + 32767) >> 16;
639
641
                        dst_line2[x+1].weight += w;
640
642
 
641
643
                        x_dst += dx_dst;
645
647
                y_dst += dy_dst;
646
648
                y_counter -= dy_dst;
647
649
                if (y_counter < 0) {
 
650
                        int val;
648
651
                        uintptr_t x;
649
652
                        struct scale_outpix_byte * temp;
650
653
 
651
654
                        y_counter += 65536;
652
655
                        
653
656
                        for (x=0; x < dst_width; x++) {
654
 
                                uintptr_t f = 0x80000000UL
655
 
                                        / dst_line1[x].weight;
656
 
                                *dst++ = (dst_line1[x].r * f) >> 15;
657
 
                                *dst++ = (dst_line1[x].g * f) >> 15;
658
 
                                *dst++ = (dst_line1[x].b * f) >> 15;
659
 
                                *dst++ = (dst_line1[x].a * f) >> 15;
 
657
                                uintptr_t f =  0x80000000UL / dst_line1[x].weight;
 
658
                                *dst++ = (val= (dst_line1[x].r * f) >> 15) > 255 ? 255: val;
 
659
                                *dst++ = (val= (dst_line1[x].g * f) >> 15) > 255 ? 255: val;
 
660
                                *dst++ = (val= (dst_line1[x].b * f) >> 15) > 255 ? 255: val;
 
661
                                *dst++ = (val= (dst_line1[x].a * f) >> 15) > 255 ? 255: val;
660
662
                        }
661
663
                        memset(dst_line1, 0, dst_width *
662
664
                               sizeof(struct scale_outpix_byte));
666
668
                }
667
669
        }
668
670
        if (dst - dst_begin < dst_width * dst_height * 4) {
 
671
                int val;
669
672
                uintptr_t x;
670
673
                for (x = 0; x < dst_width; x++) {
671
674
                        uintptr_t f = 0x80000000UL / dst_line1[x].weight;
672
 
                        *dst++ = (dst_line1[x].r * f) >> 15;
673
 
                        *dst++ = (dst_line1[x].g * f) >> 15;
674
 
                        *dst++ = (dst_line1[x].b * f) >> 15;
675
 
                        *dst++ = (dst_line1[x].a * f) >> 15;
 
675
                        *dst++ = (val= (dst_line1[x].r * f) >> 15) > 255 ? 255: val;
 
676
                        *dst++ = (val= (dst_line1[x].g * f) >> 15) > 255 ? 255: val;
 
677
                        *dst++ = (val= (dst_line1[x].b * f) >> 15) > 255 ? 255: val;
 
678
                        *dst++ = (val= (dst_line1[x].a * f) >> 15) > 255 ? 255: val;
676
679
                }
677
680
        }
678
681
        MEM_freeN(dst_line1);
910
913
   Should be comparable in speed to the ImBuf ..._fast functions at least 
911
914
   for byte-buffers.
912
915
 
 
916
   NOTE: disabled, due to inacceptable inaccuracy and quality loss, see bug #18609 (ton)
 
917
 
913
918
*/
914
919
static int q_scale_linear_interpolation(
915
920
        struct ImBuf *ibuf, int newx, int newy)
1582
1587
        scalefast_Z_ImBuf(ibuf, newx, newy);
1583
1588
 
1584
1589
        /* try to scale common cases in a fast way */
1585
 
        if (q_scale_linear_interpolation(ibuf, newx, newy)) {
 
1590
        /* disabled, quality loss is inacceptable, see report #18609  (ton) */
 
1591
        if (0 && q_scale_linear_interpolation(ibuf, newx, newy)) {
1586
1592
                return ibuf;
1587
1593
        }
1588
1594