Skip to content

Commit 98e3539

Browse files
committed
Use Iterators on BMP loading
1 parent a5baa80 commit 98e3539

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

image/shared/src/main/scala/eu/joaocosta/minart/graphics/image/BmpImageLoader.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import java.io.InputStream
55
import scala.annotation.tailrec
66

77
import eu.joaocosta.minart.graphics._
8-
import eu.joaocosta.minart.graphics.image.helpers.LazyListHelpers._
8+
import eu.joaocosta.minart.graphics.image.helpers.IteratorHelpers._
99
import eu.joaocosta.minart.graphics.image.helpers._
1010

1111
/** Image loader for BMP files.
@@ -26,7 +26,7 @@ object BmpImageLoader extends ImageLoader {
2626
)
2727

2828
object Header {
29-
def fromBytes(bytes: LazyList[Int]): ParseResult[Header] = (
29+
def fromBytes(bytes: Iterator[Int]): ParseResult[Header] = (
3030
for {
3131
magic <- readString(2).validate(
3232
supportedFormats,
@@ -51,15 +51,15 @@ object BmpImageLoader extends ImageLoader {
5151
)
5252
compressionMethod <- readLENumber(4).validate(_ == 0, _ => "Compression is not supported")
5353
header = Header(magic, size, offset, width, height, bitsPerPixel)
54-
_ <- State.set(bytes.drop(offset))
54+
_ <- skipBytes(offset - 34)
5555
} yield header
5656
).run(bytes)
5757
}
5858

5959
@tailrec
6060
def loadPixels(
6161
loadColor: ParseState[String, Color],
62-
data: LazyList[Int],
62+
data: Iterator[Int],
6363
acc: List[Color] = Nil
6464
): ParseResult[List[Color]] = {
6565
if (data.isEmpty) Right(data -> acc.reverse)
@@ -86,7 +86,7 @@ object BmpImageLoader extends ImageLoader {
8686
)
8787

8888
def loadImage(is: InputStream): Either[String, RamSurface] = {
89-
val bytes: LazyList[Int] = LazyList.continually(is.read()).takeWhile(_ != -1)
89+
val bytes: Iterator[Int] = Iterator.continually(is.read()).takeWhile(_ != -1)
9090
Header.fromBytes(bytes).flatMap { case (data, header) =>
9191
val pixels = header.bitsPerPixel match {
9292
case 24 =>

0 commit comments

Comments
 (0)