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

[FEATURE REQUEST] Play n times #15

Open
n0kovo opened this issue Dec 21, 2022 · 0 comments
Open

[FEATURE REQUEST] Play n times #15

n0kovo opened this issue Dec 21, 2022 · 0 comments

Comments

@n0kovo
Copy link

n0kovo commented Dec 21, 2022

Hi! Very cool project!

It would be nice to be able to be able to stop the player after n plays (or frames?).

Or maybe have the program read the number of loops from the file data if it exists.
(Random Scala code (should give an idea) reading loop count bytes. Found here):

  val raf = new RandomAccessFile(src, "rw")
  // skip GIF header, 6 bytes. Don't care of it much.
  raf.skipBytes(6)
  // don't need image dimension
  raf.skipBytes(4)
  val flags = raf.readUnsignedByte()
  val headerSize = 3 * (1 << ((flags & 7) + 1)) // 00000111 - size of color table
  val headerExists = flags & 128 // 10000000 - is there a color table at all
  // skip background color and pixel ratio
  raf.skipBytes(2)
  if (headerExists != 0) {
    raf.skipBytes(headerSize)
  }
  val signature = raf.readUnsignedShort()
  require(signature == 0x21ff)
  raf.skipBytes(13) // NETSCAPE 2.0
  raf.skipBytes(1) // GIF animation flag has to be 1
  ctx.loopCount.foreach {
    v =>
      raf.writeByte(v & 0xff)
      raf.writeByte((v >> 8) & 0xff)
  }
  raf.close()

Turns out it's pretty hard finding information on parsing GIF data 🤔

I might have a go (lol) at this, at some point.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant