mirror of
https://github.com/doukutsu-rs/doukutsu-rs
synced 2025-11-26 14:17:08 +00:00
texture_set: streamed image loading
This commit is contained in:
parent
31b149d135
commit
647e5c73cd
|
|
@ -29,6 +29,7 @@
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::io;
|
use std::io;
|
||||||
|
use std::io::SeekFrom;
|
||||||
use std::path;
|
use std::path;
|
||||||
|
|
||||||
use crate::ggez::{Context, GameError, GameResult};
|
use crate::ggez::{Context, GameError, GameResult};
|
||||||
|
|
@ -87,6 +88,14 @@ impl io::Write for File {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl io::Seek for File {
|
||||||
|
fn seek(&mut self, pos: SeekFrom) -> io::Result<u64> {
|
||||||
|
match *self {
|
||||||
|
File::VfsFile(ref mut f) => f.seek(pos),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Filesystem {
|
impl Filesystem {
|
||||||
/// Create a new `Filesystem` instance, using the given `id` and (on
|
/// Create a new `Filesystem` instance, using the given `id` and (on
|
||||||
/// some platforms) the `author` as a portion of the user
|
/// some platforms) the `author` as a portion of the user
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@
|
||||||
use std::collections::VecDeque;
|
use std::collections::VecDeque;
|
||||||
use std::fmt::{self, Debug};
|
use std::fmt::{self, Debug};
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::io::{Read, Seek, Write};
|
use std::io::{Read, Seek, Write, BufRead};
|
||||||
use std::path::{self, Path, PathBuf};
|
use std::path::{self, Path, PathBuf};
|
||||||
|
|
||||||
use crate::ggez::error::{GameError, GameResult};
|
use crate::ggez::error::{GameError, GameResult};
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::io::Read;
|
use std::io::{Read, BufReader, Seek, SeekFrom};
|
||||||
|
|
||||||
use crate::ggez::{Context, GameError, GameResult};
|
use crate::ggez::{Context, GameError, GameResult};
|
||||||
use crate::ggez::filesystem;
|
use crate::ggez::filesystem;
|
||||||
|
|
@ -97,10 +97,12 @@ impl TextureSet {
|
||||||
|
|
||||||
fn load_image(&self, ctx: &mut Context, path: &str) -> GameResult<Image> {
|
fn load_image(&self, ctx: &mut Context, path: &str) -> GameResult<Image> {
|
||||||
let img = {
|
let img = {
|
||||||
let mut buf = Vec::new();
|
let mut buf = [0u8; 8];
|
||||||
let mut reader = filesystem::open(ctx, path)?;
|
let mut reader = filesystem::open(ctx, path)?;
|
||||||
let _ = reader.read_to_end(&mut buf)?;
|
reader.read_exact(&mut buf)?;
|
||||||
let image = image::load_from_memory(&buf)?;
|
reader.seek(SeekFrom::Start(0))?;
|
||||||
|
|
||||||
|
let image = image::load(BufReader::new(reader), image::guess_format(&buf)?)?;
|
||||||
let mut rgba = image.to_rgba();
|
let mut rgba = image.to_rgba();
|
||||||
|
|
||||||
if image.color().channel_count() != 4 {
|
if image.color().channel_count() != 4 {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue