mirror of
https://github.com/servo/servo.git
synced 2025-07-23 15:23:42 +01:00
Slightly clean up the final URL creation in canvas.toDataURL
This commit is contained in:
parent
a3392610c3
commit
cfd446218b
1 changed files with 10 additions and 13 deletions
|
@ -396,19 +396,16 @@ impl HTMLCanvasElementMethods for HTMLCanvasElement {
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
// Only handle image/png for now.
|
// FIXME: Only handle image/png for now.
|
||||||
let mime_type = "image/png";
|
let mut png = Vec::new();
|
||||||
|
PNGEncoder::new(&mut 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))
|
.encode(&raw_data, self.Width(), self.Height(), ColorType::RGBA(8))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
let mut url = "data:image/png;base64,".to_owned();
|
||||||
|
// FIXME(nox): Should this use base64::URL_SAFE?
|
||||||
let encoded = base64::encode(&encoded);
|
// FIXME(nox): https://github.com/alicemaz/rust-base64/pull/56
|
||||||
Ok(USVString(format!("data:{};base64,{}", mime_type, encoded)))
|
base64::encode_config_buf(&png, base64::STANDARD, &mut url);
|
||||||
|
Ok(USVString(url))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue