GIF writer stores the first pixel of each frame as colormap index 1 since 6.9.13-60

Aperta Adatta ai principianti
#490 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
1/5
Tempo stimato
Meno di un'ora
Idoneità per principianti
88/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
c
Ambito
cli

Direzione di ricerca

Il bug si trova in EncodeImage() in coders/gif.c, dove il primo codice viene impostato con un AND logico (&&) invece che bit a bit (&). Guarda la riga che assegna waiting_code quando y == 0 e cambia && in &. Completato quando l'esempio a tre frame scrive una GIF il cui primo pixel di ogni frame viene riletto come srgb(46,47,49), srgb(85,84,73), srgb(89,110,74), e i test del coder GIF continuano a passare.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

ImageMagick version

6.9.13-61 Q16 (also 6.9.13-60; 6.9.13-59 is not affected)

Operating system

MacOS

Operating system, version and so on

macOS 27.3 (arm64), Apple clang 21.0.0 (clang-2100.4.1.1). Also seen in RMagick's CI on Linux and with the Windows installer.

Description

Since 6.9.13-60 the GIF writer stores the first pixel of each frame as colormap index 1, unless its index is 0. EncodeImage() in coders/gif.c sets the first code with a logical AND:

waiting_code=(short) (((size_t) (*indexes)) && 0xff);

The line came in with ImageMagick/ImageMagick6@d267cf0c. The same change in ImageMagick 7, ImageMagick/ImageMagick@28c1eb3bd3, uses & 0xff, so ImageMagick 7 is not affected. clang warns about the ImageMagick 6 line (use of logical '&&' with constant operand [-Wconstant-logical-operand]).

Using a bitwise AND fixes it:

--- a/coders/gif.c
+++ b/coders/gif.c
@@ -676,7 +676,7 @@ static MagickBooleanType EncodeImage(const ImageInfo *image_info,Image *image,
     indexes=GetVirtualIndexQueue(image);
     if (y == 0)
       {
-        waiting_code=(short) (((size_t) (*indexes)) && 0xff);
+        waiting_code=(short) (((size_t) (*indexes)) & 0xff);
         p++;
       }
     for (x=(ssize_t) (y == 0 ? 1 : 0); x < (ssize_t) image->columns; x++)

With this change, every pixel of every frame in the example below matches.

Steps to Reproduce

Write a three-frame palette image as GIF and print the first pixel of each frame:

convert rose: \( rose: -flop \) \( rose: -flip \) -colors 64 a.miff
convert a.miff a.gif
convert a.miff -format '%[pixel:p{0,0}]\n' info:
convert a.gif -format '%[pixel:p{0,0}]\n' info:

Output with 6.9.13-61:

srgb(46,47,49)
srgb(85,84,73)
srgb(89,110,74)
srgb(51,45,43)
srgb(51,45,43)
srgb(51,45,43)

(51,45,43) is colormap entry 1. Only pixel 0,0 of each frame differs; all other pixels match.

Images

None needed; the example uses the built-in rose: image.

Lingua principale
C
Stelle
251
Fork
98
Merge medio
1g 5h
PR unite (30g)
2

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di ImageMagick/ImageMagick6

Tutte le issue di ImageMagick/ImageMagick6

Issue simili

Altre issue su C

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.