]> git.ipfire.org Git - thirdparty/plymouth.git/commitdiff
[frame-buffer] Unroll gradient drawing loop
authorCharlie Brej <cbrej@cs.man.ac.uk>
Thu, 18 Jun 2009 14:31:36 +0000 (15:31 +0100)
committerCharlie Brej <cbrej@cs.man.ac.uk>
Thu, 18 Jun 2009 14:31:36 +0000 (15:31 +0100)
When drawing the gradient, rather than creating each dithered pixel, a block
of 8 pixels is created and copied repeatedly to the target. So long as the
number of noise bits is low and the random number generator is good, no
repetition is visible.

src/libply/ply-frame-buffer.c

index c28a2fd93964d0388efa4ff18a0f6090b518dea6..02ccebb4119a49cb9cac851a466291015d3a20e1 100644 (file)
@@ -1117,23 +1117,51 @@ ply_frame_buffer_fill_with_gradient (ply_frame_buffer_t      *buffer,
 
 
 #define RANDOMIZE(num) (num = (num + (num << 1)) & NOISE_MASK)
+#define UNROLLED_PIXEL_COUNT 8
 
   for (y = buffer->area.y; y < buffer->area.y + buffer->area.height; y++)
     {
       if (cropped_area.y <= y && y < cropped_area.y + cropped_area.height)
         {
-          for (x = cropped_area.x; x < cropped_area.x + cropped_area.width; x++)
+          if (cropped_area.width < UNROLLED_PIXEL_COUNT)
             {
-              pixel = 0xff000000;
-              RANDOMIZE(noise);
-              pixel |= (((red   + noise) & COLOR_MASK) >> RED_SHIFT);
-              RANDOMIZE(noise);
-              pixel |= (((green + noise) & COLOR_MASK) >> GREEN_SHIFT);
-              RANDOMIZE(noise);
-              pixel |= (((blue  + noise) & COLOR_MASK) >> BLUE_SHIFT);
-
-              buffer->shadow_buffer[y * buffer->area.width + x] = pixel;
+              for (x = cropped_area.x; x < cropped_area.x + cropped_area.width; x++)
+                {
+                  pixel = 0xff000000;
+                  RANDOMIZE(noise);
+                  pixel |= (((red   + noise) & COLOR_MASK) >> RED_SHIFT);
+                  RANDOMIZE(noise);
+                  pixel |= (((green + noise) & COLOR_MASK) >> GREEN_SHIFT);
+                  RANDOMIZE(noise);
+                  pixel |= (((blue  + noise) & COLOR_MASK) >> BLUE_SHIFT);
+
+                  buffer->shadow_buffer[y * buffer->area.width + x] = pixel;
+                }
+            }
+          else
+            {
+              uint32_t shaded_set[UNROLLED_PIXEL_COUNT];
+              uint32_t *ptr = &buffer->shadow_buffer[y * buffer->area.width + cropped_area.x];
+              for (x = 0; x < UNROLLED_PIXEL_COUNT; x++)
+                {
+                  shaded_set[x] = 0xff000000;
+                  RANDOMIZE(noise);
+                  shaded_set[x] |= (((red   + noise) & COLOR_MASK) >> RED_SHIFT);
+                  RANDOMIZE(noise);
+                  shaded_set[x] |= (((green + noise) & COLOR_MASK) >> GREEN_SHIFT);
+                  RANDOMIZE(noise);
+                  shaded_set[x] |= (((blue  + noise) & COLOR_MASK) >> BLUE_SHIFT);
+                }
+              for (x = cropped_area.width; x >=UNROLLED_PIXEL_COUNT; x-=UNROLLED_PIXEL_COUNT)
+                {
+                    memcpy((void*)ptr, (void*)shaded_set, UNROLLED_PIXEL_COUNT * sizeof(uint32_t));
+                    ptr += UNROLLED_PIXEL_COUNT;
+                }
+              memcpy((void*)ptr, (void*)shaded_set, x * sizeof(uint32_t));
+              
+              
             }
+          
         }
 
       red += red_step;