]> git.pld-linux.org Git - packages/xv.git/blob - xv-png-fix2.patch
- added jasper patch (don't use internal functions or hacks)
[packages/xv.git] / xv-png-fix2.patch
1 This patch to Andreas Dilger's XV PNG patch 1.2d addresses the following
2 bugs, buglets and typos:
3
4  - fixes a core-dump triggered by an unfortunate "feature" in libpng 0.97
5    and later (i.e., libpng frees text buffers it didn't allocate)
6
7  - forces text comments inherited from GIF or elsewhere to be in proper
8    PNG format (i.e., Unix-style "LF" line-endings); inherited PNG comments
9    are still assumed to be in proper format
10
11  - corrects argument types for png_xv_error() and png_xv_warning() to
12    match what png_create_write_struct() and png_create_read_struct()
13    expect
14
15  - changes default ">>" increment on compression dial from 2 to 3 so that
16    maximum compression (level 9) is one click away from default (level 6)
17
18  - fixes some comment typos and removes overlooked debug code
19
20 This code has been tested with various versions of libpng, most recently
21 version 1.0.1c4 (precursor to 1.0.2), with no apparent problems.
22
23 Greg Roelofs, newt@pobox.com
24 10 May 1998
25
26
27
28 *** xvpng.c.stock       Thu Jun 13 16:42:11 1996
29 --- xvpng.c     Sun May 10 13:02:07 1998
30 ***************
31 *** 49,54 ****
32 --- 49,57 ----
33   
34   #define BUTTH    24
35   
36 + #define LF       10   /* a.k.a. '\n' on ASCII machines */
37 + #define CR       13   /* a.k.a. '\r' on ASCII machines */
38
39   /*** local functions ***/
40   static    void drawPD         PARM((int, int, int, int));
41   static    void clickPD        PARM((int, int));
42 ***************
43 *** 57,64 ****
44   static    int  WritePNG       PARM((FILE *, byte *, int, int, int,
45                                       byte *, byte *, byte *, int));
46   
47 ! static    void png_xv_error   PARM((png_struct *png_ptr, char *message));
48 ! static    void png_xv_warning PARM((png_struct *png_ptr, char *message));
49   
50   /*** local variables ***/
51   static char *filename;
52 --- 60,69 ----
53   static    int  WritePNG       PARM((FILE *, byte *, int, int, int,
54                                       byte *, byte *, byte *, int));
55   
56 ! static    void png_xv_error   PARM((png_structp png_ptr,
57 !                                     png_const_charp message));
58 ! static    void png_xv_warning PARM((png_structp png_ptr,
59 !                                     png_const_charp message));
60   
61   /*** local variables ***/
62   static char *filename;
63 ***************
64 *** 87,93 ****
65     XSelectInput(theDisp, pngW, ExposureMask | ButtonPressMask | KeyPressMask);
66   
67     DCreate(&cDial, pngW,  12, 25, DWIDE, DHIGH, (double)Z_NO_COMPRESSION,
68 !           (double)Z_BEST_COMPRESSION, COMPRESSION, 1.0, 2.0,
69             infofg, infobg, hicol, locol, "Compression", NULL);
70   
71     DCreate(&gDial, pngW, DWIDE+27, 25, DWIDE, DHIGH, 1.0, 3.5,DISPLAY_GAMMA,0.01,0.2,
72 --- 92,98 ----
73     XSelectInput(theDisp, pngW, ExposureMask | ButtonPressMask | KeyPressMask);
74   
75     DCreate(&cDial, pngW,  12, 25, DWIDE, DHIGH, (double)Z_NO_COMPRESSION,
76 !           (double)Z_BEST_COMPRESSION, COMPRESSION, 1.0, 3.0,
77             infofg, infobg, hicol, locol, "Compression", NULL);
78   
79     DCreate(&gDial, pngW, DWIDE+27, 25, DWIDE, DHIGH, 1.0, 3.5,DISPLAY_GAMMA,0.01,0.2,
80 ***************
81 *** 594,607 ****
82       int j;
83       p = pic;
84       for(j = 0; j < h; j++) {
85 -   fflush(stdout);
86         if(info_ptr->color_type == PNG_COLOR_TYPE_GRAY) {
87           int k;
88           for(k = 0; k < w; k++)
89             png_line[k] = ptype==PIC24 ? MONO(p[k*3], p[k*3+1], p[k*3+2]) :
90                                          remap[p[k]];
91           png_write_row(png_ptr, png_line);
92 !       } else  /* rbg or palette */
93           png_write_row(png_ptr, p);
94         if((j & 0x1f) == 0) WaitCursor();
95         p += linesize;
96 --- 606,618 ----
97       int j;
98       p = pic;
99       for(j = 0; j < h; j++) {
100         if(info_ptr->color_type == PNG_COLOR_TYPE_GRAY) {
101           int k;
102           for(k = 0; k < w; k++)
103             png_line[k] = ptype==PIC24 ? MONO(p[k*3], p[k*3+1], p[k*3+2]) :
104                                          remap[p[k]];
105           png_write_row(png_ptr, png_line);
106 !       } else  /* RGB or palette */
107           png_write_row(png_ptr, p);
108         if((j & 0x1f) == 0) WaitCursor();
109         p += linesize;
110 ***************
111 *** 690,700 ****
112               tp++;
113             }
114           }
115 !         /* It is just a generic comment */
116           else {
117             tp->key = "Comment";
118             tp->text = key;
119 !           tp->text_length = strlen(tp->text);
120             tp->compression = tp->text_length > 750 ? 0 : -1;
121             info_ptr->num_text++;
122             key = NULL;
123 --- 701,725 ----
124               tp++;
125             }
126           }
127 !         /* Just a generic comment:  make sure line-endings are valid for PNG */
128           else {
129 +           char *p=key, *q=key;     /* only deleting chars, not adding any */
130
131 +           while (*p) {
132 +             if (*p == CR) {        /* lone CR or CR/LF:  EOL either way */
133 +               *q++ = LF;           /* LF is the only allowed PNG line-ending */
134 +               if (p[1] == LF)      /* get rid of any original LF */
135 +                 ++p;
136 +             } else if (*p == LF)   /* lone LF */
137 +               *q++ = LF;
138 +             else
139 +               *q++ = *p;
140 +             ++p;
141 +           }
142 +           *q = '\0';               /* unnecessary...but what the heck */
143             tp->key = "Comment";
144             tp->text = key;
145 !           tp->text_length = q - key;
146             tp->compression = tp->text_length > 750 ? 0 : -1;
147             info_ptr->num_text++;
148             key = NULL;
149 ***************
150 *** 712,726 ****
151     info_ptr->valid |= PNG_INFO_tIME;
152   
153     png_write_end(png_ptr, info_ptr);
154 !   png_destroy_write_struct(&png_ptr, &info_ptr);
155   
156     if (text)
157     {
158       free(text);
159       if (savecmnt)
160         free(savecmnt);
161     }
162   
163     return 0;
164   }
165   
166 --- 737,758 ----
167     info_ptr->valid |= PNG_INFO_tIME;
168   
169     png_write_end(png_ptr, info_ptr);
170 !   fflush(fp);   /* just in case we core-dump before finishing... */
171   
172     if (text)
173     {
174       free(text);
175 +     /* must do this or png_destroy_write_struct() 0.97+ will free text again: */
176 +     info_ptr->text = (png_textp)NULL;
177       if (savecmnt)
178 +     {
179         free(savecmnt);
180 +       savecmnt = (char *)NULL;
181 +     }
182     }
183   
184 +   png_destroy_write_struct(&png_ptr, &info_ptr);
185
186     return 0;
187   }
188   
189 ***************
190 *** 941,948 ****
191 --- 999,1010 ----
192   /*******************************************/
193   static void
194   png_xv_error(png_ptr, message)
195 + /*
196        png_struct *png_ptr;
197        char *message;
198 +  */
199 +      png_structp png_ptr;
200 +      png_const_charp message;
201   {
202     SetISTR(ISTR_WARNING,"%s:  libpng error: %s", fbasename, message);
203   
204 ***************
205 *** 953,960 ****
206 --- 1015,1026 ----
207   /*******************************************/
208   static void
209   png_xv_warning(png_ptr, message)
210 + /*
211        png_struct *png_ptr;
212        char *message;
213 +  */
214 +      png_structp png_ptr;
215 +      png_const_charp message;
216   {
217     if (!png_ptr)
218       return;
This page took 0.050389 seconds and 3 git commands to generate.