Skip to content

Commit 8660412

Browse files
authored
Merge pull request #2681 from image-rs/remove-read-rect
Rip out ImageDecoderRect
2 parents dfd9971 + 7cda3e7 commit 8660412

File tree

5 files changed

+8
-502
lines changed

5 files changed

+8
-502
lines changed

src/codecs/bmp/decoder.rs

Lines changed: 1 addition & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,8 @@ use crate::color::ColorType;
1111
use crate::error::{
1212
DecodingError, ImageError, ImageResult, UnsupportedError, UnsupportedErrorKind,
1313
};
14-
use crate::io::free_functions::load_rect;
1514
use crate::io::ReadExt;
16-
use crate::{ImageDecoder, ImageDecoderRect, ImageFormat};
15+
use crate::{ImageDecoder, ImageFormat};
1716

1817
const BITMAPCOREHEADER_SIZE: u32 = 12;
1918
const BITMAPINFOHEADER_SIZE: u32 = 40;
@@ -1415,34 +1414,6 @@ impl<R: BufRead + Seek> ImageDecoder for BmpDecoder<R> {
14151414
}
14161415
}
14171416

1418-
impl<R: BufRead + Seek> ImageDecoderRect for BmpDecoder<R> {
1419-
fn read_rect(
1420-
&mut self,
1421-
x: u32,
1422-
y: u32,
1423-
width: u32,
1424-
height: u32,
1425-
buf: &mut [u8],
1426-
row_pitch: usize,
1427-
) -> ImageResult<()> {
1428-
let start = self.reader.stream_position()?;
1429-
load_rect(
1430-
x,
1431-
y,
1432-
width,
1433-
height,
1434-
buf,
1435-
row_pitch,
1436-
self,
1437-
self.total_bytes() as usize,
1438-
|_, _| Ok(()),
1439-
|s, buf| s.read_image_data(buf),
1440-
)?;
1441-
self.reader.seek(SeekFrom::Start(start))?;
1442-
Ok(())
1443-
}
1444-
}
1445-
14461417
#[cfg(test)]
14471418
mod test {
14481419
use std::io::{BufReader, Cursor};
@@ -1464,16 +1435,6 @@ mod test {
14641435
}
14651436
}
14661437

1467-
#[test]
1468-
fn read_rect() {
1469-
let f =
1470-
BufReader::new(std::fs::File::open("tests/images/bmp/images/Core_8_Bit.bmp").unwrap());
1471-
let mut decoder = BmpDecoder::new(f).unwrap();
1472-
1473-
let mut buf: Vec<u8> = vec![0; 8 * 8 * 3];
1474-
decoder.read_rect(0, 0, 8, 8, &mut buf, 8 * 3).unwrap();
1475-
}
1476-
14771438
#[test]
14781439
fn read_rle_too_short() {
14791440
let data = vec![

src/codecs/farbfeld.rs

Lines changed: 2 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ use crate::color::ExtendedColorType;
2222
use crate::error::{
2323
DecodingError, ImageError, ImageResult, UnsupportedError, UnsupportedErrorKind,
2424
};
25-
use crate::io::free_functions::load_rect;
26-
use crate::{ColorType, ImageDecoder, ImageDecoderRect, ImageEncoder, ImageFormat};
25+
use crate::{ColorType, ImageDecoder, ImageEncoder, ImageFormat};
2726

2827
/// farbfeld Reader
2928
pub struct FarbfeldReader<R: Read> {
@@ -215,36 +214,6 @@ impl<R: Read> ImageDecoder for FarbfeldDecoder<R> {
215214
}
216215
}
217216

218-
impl<R: Read + Seek> ImageDecoderRect for FarbfeldDecoder<R> {
219-
fn read_rect(
220-
&mut self,
221-
x: u32,
222-
y: u32,
223-
width: u32,
224-
height: u32,
225-
buf: &mut [u8],
226-
row_pitch: usize,
227-
) -> ImageResult<()> {
228-
// A "scanline" (defined as "shortest non-caching read" in the doc) is just one channel in this case
229-
230-
let start = self.reader.stream_position()?;
231-
load_rect(
232-
x,
233-
y,
234-
width,
235-
height,
236-
buf,
237-
row_pitch,
238-
self,
239-
2,
240-
|s, scanline| s.reader.seek(SeekFrom::Start(scanline * 2)).map(|_| ()),
241-
|s, buf| s.reader.read_exact(buf),
242-
)?;
243-
self.reader.seek(SeekFrom::Start(start))?;
244-
Ok(())
245-
}
246-
}
247-
248217
/// farbfeld encoder
249218
pub struct FarbfeldEncoder<W: Write> {
250219
w: W,
@@ -314,94 +283,12 @@ impl<W: Write> ImageEncoder for FarbfeldEncoder<W> {
314283
#[cfg(test)]
315284
mod tests {
316285
use crate::codecs::farbfeld::FarbfeldDecoder;
317-
use crate::ImageDecoderRect;
318-
use byteorder_lite::{ByteOrder, NativeEndian};
319-
use std::io::{Cursor, Seek, SeekFrom};
320-
321-
static RECTANGLE_IN: &[u8] = b"farbfeld\
322-
\x00\x00\x00\x02\x00\x00\x00\x03\
323-
\xFF\x01\xFE\x02\xFD\x03\xFC\x04\xFB\x05\xFA\x06\xF9\x07\xF8\x08\
324-
\xF7\x09\xF6\x0A\xF5\x0B\xF4\x0C\xF3\x0D\xF2\x0E\xF1\x0F\xF0\x10\
325-
\xEF\x11\xEE\x12\xED\x13\xEC\x14\xEB\x15\xEA\x16\xE9\x17\xE8\x18";
326-
327-
#[test]
328-
fn read_rect_1x2() {
329-
static RECTANGLE_OUT: &[u16] = &[
330-
0xF30D, 0xF20E, 0xF10F, 0xF010, 0xEB15, 0xEA16, 0xE917, 0xE818,
331-
];
332-
333-
read_rect(1, 1, 1, 2, RECTANGLE_OUT);
334-
}
335-
336-
#[test]
337-
fn read_rect_2x2() {
338-
static RECTANGLE_OUT: &[u16] = &[
339-
0xFF01, 0xFE02, 0xFD03, 0xFC04, 0xFB05, 0xFA06, 0xF907, 0xF808, 0xF709, 0xF60A, 0xF50B,
340-
0xF40C, 0xF30D, 0xF20E, 0xF10F, 0xF010,
341-
];
342-
343-
read_rect(0, 0, 2, 2, RECTANGLE_OUT);
344-
}
345-
346-
#[test]
347-
fn read_rect_2x1() {
348-
static RECTANGLE_OUT: &[u16] = &[
349-
0xEF11, 0xEE12, 0xED13, 0xEC14, 0xEB15, 0xEA16, 0xE917, 0xE818,
350-
];
351-
352-
read_rect(0, 2, 2, 1, RECTANGLE_OUT);
353-
}
354-
355-
#[test]
356-
fn read_rect_2x3() {
357-
static RECTANGLE_OUT: &[u16] = &[
358-
0xFF01, 0xFE02, 0xFD03, 0xFC04, 0xFB05, 0xFA06, 0xF907, 0xF808, 0xF709, 0xF60A, 0xF50B,
359-
0xF40C, 0xF30D, 0xF20E, 0xF10F, 0xF010, 0xEF11, 0xEE12, 0xED13, 0xEC14, 0xEB15, 0xEA16,
360-
0xE917, 0xE818,
361-
];
362-
363-
read_rect(0, 0, 2, 3, RECTANGLE_OUT);
364-
}
365-
366-
#[test]
367-
fn read_rect_in_stream() {
368-
static RECTANGLE_OUT: &[u16] = &[0xEF11, 0xEE12, 0xED13, 0xEC14];
369-
370-
let mut input = vec![];
371-
input.extend_from_slice(b"This is a 31-byte-long prologue");
372-
input.extend_from_slice(RECTANGLE_IN);
373-
let mut input_cur = Cursor::new(input);
374-
input_cur.seek(SeekFrom::Start(31)).unwrap();
375-
376-
let mut out_buf = [0u8; 64];
377-
FarbfeldDecoder::new(input_cur)
378-
.unwrap()
379-
.read_rect(0, 2, 1, 1, &mut out_buf, 8)
380-
.unwrap();
381-
let exp = degenerate_pixels(RECTANGLE_OUT);
382-
assert_eq!(&out_buf[..exp.len()], &exp[..]);
383-
}
286+
use std::io::Cursor;
384287

385288
#[test]
386289
fn dimension_overflow() {
387290
let header = b"farbfeld\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF";
388291

389292
assert!(FarbfeldDecoder::new(Cursor::new(header)).is_err());
390293
}
391-
392-
fn read_rect(x: u32, y: u32, width: u32, height: u32, exp_wide: &[u16]) {
393-
let mut out_buf = [0u8; 64];
394-
FarbfeldDecoder::new(Cursor::new(RECTANGLE_IN))
395-
.unwrap()
396-
.read_rect(x, y, width, height, &mut out_buf, width as usize * 8)
397-
.unwrap();
398-
let exp = degenerate_pixels(exp_wide);
399-
assert_eq!(&out_buf[..exp.len()], &exp[..]);
400-
}
401-
402-
fn degenerate_pixels(exp_wide: &[u16]) -> Vec<u8> {
403-
let mut exp = vec![0u8; exp_wide.len() * 2];
404-
NativeEndian::write_u16_into(exp_wide, &mut exp);
405-
exp
406-
}
407294
}

src/io/decoder.rs

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -175,26 +175,6 @@ impl<T: ?Sized + ImageDecoder> ImageDecoder for Box<T> {
175175
}
176176
}
177177

178-
/// Specialized image decoding not be supported by all formats
179-
pub trait ImageDecoderRect: ImageDecoder {
180-
/// Decode a rectangular section of the image.
181-
///
182-
/// This function takes a slice of bytes and writes the pixel data of the image into it.
183-
/// The rectangle is specified by the x and y coordinates of the top left corner, the width
184-
/// and height of the rectangle, and the row pitch of the buffer. The row pitch is the number
185-
/// of bytes between the start of one row and the start of the next row. The row pitch must be
186-
/// at least as large as the width of the rectangle in bytes.
187-
fn read_rect(
188-
&mut self,
189-
x: u32,
190-
y: u32,
191-
width: u32,
192-
height: u32,
193-
buf: &mut [u8],
194-
row_pitch: usize,
195-
) -> ImageResult<()>;
196-
}
197-
198178
/// `AnimationDecoder` trait
199179
pub trait AnimationDecoder<'a> {
200180
/// Consume the decoder producing a series of frames.

0 commit comments

Comments
 (0)