Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions avif.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,13 @@ uint32_t avif_decoder_get_duration(const avif_decoder d) {
}

uint32_t avif_decoder_get_loop_count(const avif_decoder d) {
if (!d || !d->decoder) {
return 0;
}
switch (d->decoder->repetitionCount) {
case AVIF_REPETITION_COUNT_INFINITE:
return 0;
case AVIF_REPETITION_COUNT_UNKNOWN:
return 1;
return 0;
default:
return d->decoder->repetitionCount;
}
Expand Down
24 changes: 24 additions & 0 deletions avif_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ func TestAvifOperations(t *testing.T) {
t.Run("NewAvifEncoder", testNewAvifEncoder)
t.Run("AvifDecoder_DecodeTo", testAvifDecoderDecodeTo)
t.Run("AvifEncoder_Encode", testAvifEncoderEncode)
t.Run("AvifDecoder_UnknownLoopCount", testAvifDecoderUnknownLoopCount)
})

t.Run("Conversion Operations", func(t *testing.T) {
Expand Down Expand Up @@ -115,6 +116,29 @@ func testAvifDecoderDuration(t *testing.T) {
}
}

func testAvifDecoderUnknownLoopCount(t *testing.T) {
testAvifImage, err := os.ReadFile("testdata/spinning-globe-unknown-loop-count.avif")
if err != nil {
t.Fatalf("Unexpected error while reading AVIF image: %v", err)
}
decoder, err := newAvifDecoder(testAvifImage)
if err != nil {
t.Fatalf("Unexpected error while decoding AVIF image data: %v", err)
}
defer decoder.Close()

// Verify the image is animated
if !decoder.IsAnimated() {
t.Error("Expected image to be animated")
}

// Check that unknown loop count is treated as infinite (0)
loopCount := decoder.LoopCount()
if loopCount != 0 {
t.Errorf("Expected loop count to be 0 (infinite) for unknown loop count, got %d", loopCount)
}
}

// Basic Encoder Tests
// ----------------------------------------

Expand Down
Binary file added testdata/spinning-globe-unknown-loop-count.avif
Binary file not shown.