]> git.ipfire.org Git - thirdparty/plymouth.git/commitdiff
[two-step] Add merge-fade as a progress animation transition type
authorCharlie Brej <cbrej@cs.man.ac.uk>
Wed, 13 May 2009 12:11:36 +0000 (13:11 +0100)
committerRay Strode <rstrode@redhat.com>
Wed, 20 May 2009 21:27:53 +0000 (17:27 -0400)
The merge fade merges the two frames before drawing them to the framebuffer.
This makes a smooth transition between areas with partly transparent pixels or
areas in later frames becoming trasparent. This is set as the default on the
"glow" theme.

src/libplybootsplash/ply-progress-animation.c
src/libplybootsplash/ply-progress-animation.h
src/plugins/splash/two-step/plugin.c
themes/glow/glow.plymouth.in

index 9f3fbf2f65fcc3cb2d3a873786c199d6981dbf91..42db34ec95fc44dc9ddace9610b79e6bc3b84d0d 100644 (file)
@@ -147,6 +147,51 @@ draw_background (ply_progress_animation_t *progress_animation)
                          progress_animation->frame_area.height);
 }
 
+static uint32_t*
+image_fade_merge(ply_image_t* frame0, ply_image_t* frame1, float fade, int width, int height)
+{
+  int frame0_width = ply_image_get_width (frame0);
+  int frame0_height = ply_image_get_height (frame0);
+  int frame1_width = ply_image_get_width (frame1);
+  int frame1_height = ply_image_get_height (frame1);
+
+  uint32_t *frame0_data = ply_image_get_data (frame0);
+  uint32_t *frame1_data = ply_image_get_data (frame1);
+
+  uint32_t *reply_data = malloc (width * height * sizeof (uint32_t));
+  int x, y, i;
+
+
+  for (y = 0; y < height; y++)
+    {
+      for (x = 0; x < width; x++)
+        {
+          uint32_t pixel0, pixel1, pixelout;
+          
+          if (y < frame0_height && x < frame0_width)
+            pixel0 = frame0_data[y*frame0_width+x];
+          else 
+            pixel0 = 0;
+          
+          if (y < frame1_height && x < frame1_width)
+            pixel1 = frame1_data[y*frame1_width+x];
+          else 
+            pixel1 = 0;
+            
+          pixelout = 0;
+          for (i = 0; i < 4; i++)
+            {
+              int subval0 = (pixel0 >> (i * 8)) & 0xFF;
+              int subval1 = (pixel1 >> (i * 8)) & 0xFF;
+              int subvalout = subval0 * (1-fade) + subval1 * fade;
+              pixelout |= (subvalout & 0xFF) << (i * 8);
+            }
+          reply_data[y*width+x] = pixelout;
+        }
+    }
+  return reply_data;
+}
+
 void
 ply_progress_animation_draw (ply_progress_animation_t *progress_animation)
 {
@@ -183,8 +228,6 @@ ply_progress_animation_draw (ply_progress_animation_t *progress_animation)
 
   progress_animation->frame_area.x = progress_animation->area.x;
   progress_animation->frame_area.y = progress_animation->area.y;
-  progress_animation->frame_area.width = ply_image_get_width (frames[frame_number]);
-  progress_animation->frame_area.height = ply_image_get_height (frames[frame_number]);
   frame_data = ply_image_get_data (frames[frame_number]);
 
   if (progress_animation->is_transitioning)
@@ -192,6 +235,8 @@ ply_progress_animation_draw (ply_progress_animation_t *progress_animation)
       double now;
       double fade_percentage;
       double fade_out_opacity;
+      int width, height;
+      uint32_t* faded_data;
       now = ply_get_timestamp ();
 
       fade_percentage = (now - progress_animation->transition_start_time) / progress_animation->transition_duration;
@@ -201,20 +246,50 @@ ply_progress_animation_draw (ply_progress_animation_t *progress_animation)
       fade_percentage = CLAMP (fade_percentage, 0.0, 1.0);
 
       previous_frame_data = ply_image_get_data (frames[frame_number - 1]);
-      if (progress_animation->transition == PLY_PROGRESS_ANIMATION_TRANSITION_FADE_OVER)
-        fade_out_opacity = 1.0;
+      if (progress_animation->transition == PLY_PROGRESS_ANIMATION_TRANSITION_MERGE_FADE)
+        {
+          width = MAX(ply_image_get_width (frames[frame_number]), ply_image_get_width (frames[frame_number - 1]));
+          height = MAX(ply_image_get_height (frames[frame_number]), ply_image_get_width (frames[frame_number - 1]));
+          progress_animation->frame_area.width = width;
+          progress_animation->frame_area.height = height;
+
+          faded_data = image_fade_merge(frames[frame_number - 1], frames[frame_number], fade_percentage, width, height);
+
+          ply_frame_buffer_fill_with_argb32_data_at_opacity (progress_animation->frame_buffer,
+                                                             &progress_animation->frame_area, 0, 0,
+                                                             faded_data, 1.0);
+        free(faded_data);
+        }
       else
-        fade_out_opacity = 1.0 - fade_percentage;
-
-      ply_frame_buffer_fill_with_argb32_data_at_opacity (progress_animation->frame_buffer,
-                                                         &progress_animation->frame_area, 0, 0,
-                                                         previous_frame_data, fade_out_opacity);
-      ply_frame_buffer_fill_with_argb32_data_at_opacity (progress_animation->frame_buffer,
-                                                         &progress_animation->frame_area, 0, 0,
-                                                         frame_data, fade_percentage);
+        {
+          if (progress_animation->transition == PLY_PROGRESS_ANIMATION_TRANSITION_FADE_OVER)
+            fade_out_opacity = 1.0;
+          else
+            fade_out_opacity = 1.0 - fade_percentage;
+
+          progress_animation->frame_area.width = ply_image_get_width (frames[frame_number - 1]);
+          progress_animation->frame_area.height = ply_image_get_height (frames[frame_number - 1]);
+          ply_frame_buffer_fill_with_argb32_data_at_opacity (progress_animation->frame_buffer,
+                                                             &progress_animation->frame_area, 0, 0,
+                                                             previous_frame_data, fade_out_opacity);
+
+          progress_animation->frame_area.width = ply_image_get_width (frames[frame_number]);
+          progress_animation->frame_area.height = ply_image_get_height (frames[frame_number]);
+          ply_frame_buffer_fill_with_argb32_data_at_opacity (progress_animation->frame_buffer,
+                                                             &progress_animation->frame_area, 0, 0,
+                                                             frame_data, fade_percentage);
+
+          width = MAX(ply_image_get_width (frames[frame_number]), ply_image_get_width (frames[frame_number - 1]));
+          height = MAX(ply_image_get_height (frames[frame_number]), ply_image_get_width (frames[frame_number - 1]));
+          progress_animation->frame_area.width = width;
+          progress_animation->frame_area.height = height;
+        }
+      
     }
   else
     {
+      progress_animation->frame_area.width = ply_image_get_width (frames[frame_number]);
+      progress_animation->frame_area.height = ply_image_get_height (frames[frame_number]);
       ply_frame_buffer_fill_with_argb32_data (progress_animation->frame_buffer,
                                               &progress_animation->frame_area, 0, 0,
                                               frame_data);
index f199187fdc22003772510f80d85b46feee2fbfb4..3c51d10f694e56f84b39dea795f6e4632f1eec38 100644 (file)
@@ -36,6 +36,7 @@ typedef enum
   PLY_PROGRESS_ANIMATION_TRANSITION_NONE,
   PLY_PROGRESS_ANIMATION_TRANSITION_FADE_OVER,
   PLY_PROGRESS_ANIMATION_TRANSITION_CROSS_FADE,
+  PLY_PROGRESS_ANIMATION_TRANSITION_MERGE_FADE,
 } ply_progress_animation_transition_t;
 
 #ifndef PLY_HIDE_FUNCTION_DECLARATIONS
index 88f2355a4553e7d4322d7c1cce8af05864ab1a80..68d75ad9140010d58e7c676f24994d4eba1214c6 100644 (file)
@@ -165,6 +165,8 @@ create_plugin (ply_key_file_t *key_file)
         plugin->transition = PLY_PROGRESS_ANIMATION_TRANSITION_FADE_OVER;
       else if (strcmp (transition, "cross-fade") == 0)
         plugin->transition = PLY_PROGRESS_ANIMATION_TRANSITION_CROSS_FADE;
+      else if (strcmp (transition, "merge-fade") == 0)
+        plugin->transition = PLY_PROGRESS_ANIMATION_TRANSITION_MERGE_FADE;
     }
   free (transition);
 
index 73694910077cf0a806c5f0b5fcb965d5e3e7f785..b3c4372c3eef65d075c083e9c712bcdb6e77dd4d 100644 (file)
@@ -7,5 +7,5 @@ ModuleName=two-step
 ImageDir=@PLYMOUTH_THEME_PATH@/glow
 HorizontalAlignment=.25
 VerticalAlignment=.5
-Transition=fade-over
+Transition=merge-fade
 TransitionDuration=.5