aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvi Kivity <avi@redhat.com>2012-01-03 15:32:57 +0200
committerAnthony Liguori <aliguori@us.ibm.com>2012-01-12 10:03:28 -0600
commita0f426109e17d579c2712f5b96a50215e6cc06a4 (patch)
tree772b9cbe1226cce709b5ae86b0e4466e589ca678
parent19bf7c87081835449d5683ecb0858255bf5a0546 (diff)
vga: optimize ppm_save() divisions
ppm_save() spends upwards of 50% of its time doing divisions. Replace them with shifts. Reviewed-by: Alon Levy <alevy@redhat.com> Signed-off-by: Avi Kivity <avi@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
-rw-r--r--hw/vga.c10
1 files changed, 4 insertions, 6 deletions
diff --git a/hw/vga.c b/hw/vga.c
index 4878fbcbb1..950f97e440 100644
--- a/hw/vga.c
+++ b/hw/vga.c
@@ -2373,12 +2373,10 @@ int ppm_save(const char *filename, struct DisplaySurface *ds)
v = *(uint32_t *)d;
else
v = (uint32_t) (*(uint16_t *)d);
- r = ((v >> ds->pf.rshift) & ds->pf.rmax) * 256 /
- (ds->pf.rmax + 1);
- g = ((v >> ds->pf.gshift) & ds->pf.gmax) * 256 /
- (ds->pf.gmax + 1);
- b = ((v >> ds->pf.bshift) & ds->pf.bmax) * 256 /
- (ds->pf.bmax + 1);
+ /* Limited to 8 or fewer bits per channel: */
+ r = ((v >> ds->pf.rshift) & ds->pf.rmax) << (8 - ds->pf.rbits);
+ g = ((v >> ds->pf.gshift) & ds->pf.gmax) << (8 - ds->pf.gbits);
+ b = ((v >> ds->pf.bshift) & ds->pf.bmax) << (8 - ds->pf.bbits);
*pbuf++ = r;
*pbuf++ = g;
*pbuf++ = b;