Advertisement
Guest User

grub scale nearest + improvement with memcpy

a guest
Feb 25th, 2015
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.22 KB | None | 0 0
  1. static grub_err_t
  2. scale_nn (struct grub_video_bitmap *dst, struct grub_video_bitmap *src)
  3. {
  4.   grub_err_t err = verify_bitmaps(dst, src);
  5.   if (err != GRUB_ERR_NONE)
  6.     return err;
  7.  
  8.   grub_uint8_t *ddata = dst->data;
  9.   grub_uint8_t *sdata = src->data;
  10.   unsigned dw = dst->mode_info.width;
  11.   unsigned dh = dst->mode_info.height;
  12.   unsigned sw = src->mode_info.width;
  13.   unsigned sh = src->mode_info.height;
  14.   unsigned dstride = dst->mode_info.pitch;
  15.   unsigned sstride = src->mode_info.pitch;
  16.   unsigned bytes_per_pixel = dst->mode_info.bytes_per_pixel;
  17.   unsigned x_ratio = ((sw << 16) / dw) + 1;
  18.   unsigned y_ratio = ((sh << 16) / dh) + 1;
  19.   unsigned src_line, dst_line, src_pos, dst_pos, ratio, i, j;
  20.  
  21.   /* grub scale nearest + improvement with memcpy & reduce multiplication */
  22.   unsigned dw_bpp = dw*bytes_per_pixel;
  23.  
  24.   for (i=0;i<dh;i++) {
  25.     src_line = ((i*y_ratio)>>16)*sstride;
  26.     dst_line = i*dstride;
  27.     ratio   = 0;
  28.     for (j=0;j<dw_bpp;j+=bytes_per_pixel){
  29.       src_pos = src_line+(ratio>>16)*bytes_per_pixel;
  30.       dst_pos = dst_line+j;
  31.      
  32.       /* improve with memcpy */
  33.       memcpy(ddata+dst_pos, sdata+src_pos, bytes_per_pixel);
  34.       ratio+=x_ratio;
  35.     }
  36.   }
  37.   return GRUB_ERR_NONE;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement