Load the c64 font as a raw bitmap without using the image crate.
authorBernie Innocenti <bernie@codewiz.org>
Sun, 2 Jul 2017 15:55:51 +0000 (11:55 -0400)
committerBernie Innocenti <bernie@codewiz.org>
Sun, 2 Jul 2017 15:55:51 +0000 (11:55 -0400)
Shaves 170KB from the stripped binary.

gentextures.sh [new file with mode: 0644]
lib.rs
text.rs

diff --git a/gentextures.sh b/gentextures.sh
new file mode 100644 (file)
index 0000000..bbfb111
--- /dev/null
@@ -0,0 +1,3 @@
+#!/bin/sh
+set -e
+convert c64-font.png -format GRAY -depth 8  c64-font.gray
diff --git a/lib.rs b/lib.rs
index eba89b1fb1b776a6702cb365e392fa672c037b69..a15ea2b86979c6e8ebd6a73fc1c72468b00362f1 100644 (file)
--- a/lib.rs
+++ b/lib.rs
@@ -31,5 +31,5 @@ pub fn screenshot(display : &glium::Display) {
 }
 
 #[cfg(not(feature = "image"))]
-pub fn screenshot(display : &glium::Display) {
+pub fn screenshot(_ : &glium::Display) {
 }
diff --git a/text.rs b/text.rs
index abcd9b40f17b3235fcf230883f1e57f8c686b28e..14b2633b8a6712910bb49b7abcb46f57bb8d0f59 100644 (file)
--- a/text.rs
+++ b/text.rs
@@ -2,7 +2,6 @@ use cgmath::conv::array4x4;
 use cgmath::{Matrix4, Vector3};
 use glium;
 use glium::{Surface, texture};
-use image;
 use std;
 
 fn gamma<T>(x: T) -> f32
@@ -21,6 +20,23 @@ where
     [gamma(c[0]), gamma(c[1]), gamma(c[2]), 0.0]
 }
 
+#[cfg(feature = "image")]
+fn c64_font() -> (u32, u32, Vec<u8>) {
+    use image;
+    let image =
+        image::load_from_memory_with_format(&include_bytes!("c64-font.png")[..], image::PNG)
+            .unwrap()
+            .to_luma();
+    let (w, h) = image.dimensions();
+    (w, h, image.into_raw())
+}
+
+#[cfg(not(feature = "image"))]
+fn c64_font() -> (u32, u32, Vec<u8>) {
+    let pixels = &include_bytes!("c64-font.gray")[..];
+    (128, 128, Vec::from(pixels))
+}
+
 #[derive(Copy, Clone)]
 struct Vertex {
     position: [f32; 2],
@@ -39,13 +55,9 @@ pub struct Text<'a> {
 
 impl<'a> Text<'a> {
     pub fn new(display: &glium::Display) -> Text {
-        let image =
-            image::load_from_memory_with_format(&include_bytes!("c64-font.png")[..], image::PNG)
-                .unwrap()
-                .to_luma();
-        let (w, h) = image.dimensions();
+        let (w, h, pixels) = c64_font();
         let image = glium::texture::RawImage2d {
-            data: std::borrow::Cow::from(image.into_raw()),
+            data: std::borrow::Cow::from(pixels),
             width: w,
             height: h,
             format: glium::texture::ClientFormat::U8,