]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
* grub-core/video/bitmap_scale.c (scale_bilinear): Increased precision
authorVladimir Testov <vladimir.testov@rosalab.ru>
Tue, 1 Oct 2013 12:34:04 +0000 (16:34 +0400)
committerVladimir Testov <vladimir.testov@rosalab.ru>
Tue, 1 Oct 2013 12:34:04 +0000 (16:34 +0400)
       to eliminate artefacts in bilinear interpolation.

ChangeLog
grub-core/video/bitmap_scale.c

index d7b9fb8684856918e88bed39d615ce84abc3d9c0..cbaba2f34269d283d65f80e10dbca167d4025dc0 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2013-10-01  Vladimir Testov  <vladimir.testov@rosalab.ru>
+
+       * grub-core/video/bitmap_scale.c (scale_bilinear): Increased precision
+       to eliminate artefacts in bilinear interpolation.
+
 2013-09-28  Vladimir Serbinenko  <phcoder@gmail.com>
 
        * grub-core/video/readers/tga.c: Support paletted tga.
index 73f50f61185b42591626123758026f6d3da82fa1..7ad411909ac2c3a33aa97f1776e09a5ca994e720 100644 (file)
@@ -286,18 +286,20 @@ scale_bilinear (struct grub_video_bitmap *dst, struct grub_video_bitmap *src)
                 {
                   /* Get the component's values for the
                      four source corner pixels. */
-                  grub_uint8_t f00 = sptr[comp];
-                  grub_uint8_t f10 = sptr[comp + bytes_per_pixel];
-                  grub_uint8_t f01 = sptr[comp + sstride];
-                  grub_uint8_t f11 = sptr[comp + sstride + bytes_per_pixel];
+                  int f00 = sptr[comp];
+                  int f10 = sptr[comp + bytes_per_pixel];
+                  int f01 = sptr[comp + sstride];
+                  int f11 = sptr[comp + sstride + bytes_per_pixel];
 
-                  /* Do linear interpolations along the top and bottom
-                     rows of the box. */
-                  grub_uint8_t f0y = (256 - v) * f00 / 256 + v * f01 / 256;
-                  grub_uint8_t f1y = (256 - v) * f10 / 256 + v * f11 / 256;
+                  /* Count coeffecients. */
+                  int c00 = (256 - u) * (256 - v);
+                  int c10 = u * (256 - v);
+                  int c01 = (256 - u) * v;
+                  int c11 = u * v;
 
-                  /* Interpolate vertically. */
-                  grub_uint8_t fxy = (256 - u) * f0y / 256 + u * f1y / 256;
+                  /* Interpolate. */
+                  int fxy = c00 * f00 + c01 * f01 + c10 * f10 + c11 * f11;
+                  fxy = fxy / (256 * 256);
 
                   dptr[comp] = fxy;
                 }