Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slightly clean up the final URL creation in canvas.toDataURL #21850

Merged
merged 7 commits into from Oct 3, 2018

Slightly clean up the final URL creation in canvas.toDataURL

  • Loading branch information
nox committed Oct 3, 2018
commit cfd446218b9d84e9c6f1b078f8d73fb6df7a8277
@@ -396,19 +396,16 @@ impl HTMLCanvasElementMethods for HTMLCanvasElement {
},
};

// Only handle image/png for now.
let mime_type = "image/png";

let mut encoded = Vec::new();
{
let encoder: PNGEncoder<&mut Vec<u8>> = PNGEncoder::new(&mut encoded);
encoder
.encode(&raw_data, self.Width(), self.Height(), ColorType::RGBA(8))
.unwrap();
}

let encoded = base64::encode(&encoded);
Ok(USVString(format!("data:{};base64,{}", mime_type, encoded)))
// FIXME: Only handle image/png for now.
let mut png = Vec::new();
PNGEncoder::new(&mut png)
.encode(&raw_data, self.Width(), self.Height(), ColorType::RGBA(8))
.unwrap();
let mut url = "data:image/png;base64,".to_owned();
// FIXME(nox): Should this use base64::URL_SAFE?
// FIXME(nox): https://github.com/alicemaz/rust-base64/pull/56
base64::encode_config_buf(&png, base64::STANDARD, &mut url);
Ok(USVString(url))
}
}

ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.