88 * This file is part of GPUJPEG. 
99 */ 
1010/* 
11-  * Copyright (c) 2013-2023 , CESNET z.s.p.o.  
11+  * Copyright (c) 2013-2025 , CESNET 
1212 * 
1313 * All rights reserved. 
1414 * 
@@ -64,7 +64,7 @@ static bool parse_pam(FILE *file, struct pam_metadata *info) {
6464                } else  if  (strcmp (key , "HEIGHT" ) ==  0 ) {
6565                        info -> height  =  atoi (val );
6666                } else  if  (strcmp (key , "DEPTH" ) ==  0 ) {
67-                         info -> depth  =  atoi (val );
67+                         info -> ch_count  =  atoi (val );
6868                } else  if  (strcmp (key , "MAXVAL" ) ==  0 ) {
6969                        info -> maxval  =  atoi (val );
7070                } else  if  (strcmp (key , "TUPLTYPE" ) ==  0 ) {
@@ -92,15 +92,15 @@ static bool parse_pnm(FILE *file, char pnm_id, struct pam_metadata *info) {
9292                        fprintf (stderr , "Plain (ASCII) PNM are not supported, input is P%c\n" , pnm_id );
9393                        return  false;
9494                case  '4' :
95-                         info -> depth  =  1 ;
95+                         info -> ch_count  =  1 ;
9696                        info -> maxval  =  1 ;
9797                        info -> bitmap_pbm  =  true;
9898                        break ;
9999                case  '5' :
100-                         info -> depth  =  1 ;
100+                         info -> ch_count  =  1 ;
101101                        break ;
102102                case  '6' :
103-                         info -> depth  =  3 ;
103+                         info -> ch_count  =  3 ;
104104                        break ;
105105                default :
106106                        fprintf (stderr , "Wrong PNM type P%c\n" , pnm_id );
@@ -166,8 +166,8 @@ bool pam_read(const char *filename, struct pam_metadata *info, unsigned char **d
166166                fprintf (stderr , "Unspecified/incorrect size %dx%d!\n" , info -> width , info -> height );
167167                parse_rc  =  false;
168168        }
169-         if  (info -> depth  <= 0 ) {
170-                 fprintf (stderr , "Unspecified/incorrect depth  %d!\n" , info -> depth );
169+         if  (info -> ch_count  <= 0 ) {
170+                 fprintf (stderr , "Unspecified/incorrect channel count  %d!\n" , info -> ch_count );
171171                parse_rc  =  false;
172172        }
173173        if  (info -> maxval  <= 0  ||  info -> maxval  >  65535 ) {
@@ -178,15 +178,15 @@ bool pam_read(const char *filename, struct pam_metadata *info, unsigned char **d
178178                fclose (file );
179179                return  parse_rc ;
180180        }
181-         size_t  datalen  =  (size_t ) info -> depth  *  info -> width  *  info -> height ;
181+         size_t  datalen  =  (size_t ) info -> ch_count  *  info -> width  *  info -> height ;
182182        if  (info -> maxval  ==  1  &&  info -> bitmap_pbm ) {
183183                datalen  =  (info -> width  +  7 ) / 8  *  info -> height ;
184184        } else  if  (info -> maxval  >  255 ) {
185185                datalen  *= 2 ;
186186        }
187187        * data  =  (unsigned char   * ) allocator (datalen );
188188        if  (!* data ) {
189-                 fprintf (stderr , "Unspecified depth header field !\n" );
189+                 fprintf (stderr , "Failed to allocate data !\n" );
190190                fclose (file );
191191                return  false;
192192        }
@@ -201,32 +201,32 @@ bool pam_read(const char *filename, struct pam_metadata *info, unsigned char **d
201201        return  true;
202202}
203203
204- bool  pam_write (const  char  * filename , unsigned int   width , unsigned int   height , int  depth , int  maxval , const  unsigned char   * data , bool  pnm ) {
204+ bool  pam_write (const  char  * filename , unsigned int   width , unsigned int   height , int  ch_count , int  maxval , const  unsigned char   * data , bool  pnm ) {
205205        errno  =  0 ;
206206        FILE  * file  =  fopen (filename , "wb" );
207207        if  (!file ) {
208208                fprintf (stderr , "Failed to open %s for writing: %s\n" , filename , strerror (errno ));
209209                return  false;
210210        }
211211        if  (pnm ) {
212-                 if  (depth  !=  1  &&  depth  !=  3 ) {
212+                 if  (ch_count  !=  1  &&  ch_count  !=  3 ) {
213213                        fprintf (stderr , "Only 1 or 3 channels supported for PNM!\n" );
214214                        fclose (file );
215215                        return  false;
216216                }
217217                fprintf (file , "P%d\n" 
218218                        "%u %u\n" 
219219                        "%d\n" ,
220-                         depth  ==  1  ? 5  : 6 ,
220+                         ch_count  ==  1  ? 5  : 6 ,
221221                        width , height , maxval );
222222        } else  {
223223                const  char  * tuple_type  =  "INVALID" ;
224-                 switch  (depth ) {
224+                 switch  (ch_count ) {
225225                        case  4 : tuple_type  =  "RGB_ALPHA" ; break ;
226226                        case  3 : tuple_type  =  "RGB" ; break ;
227227                        case  2 : tuple_type  =  "GRAYSCALE_ALPHA" ; break ;
228228                        case  1 : tuple_type  =  "GRAYSCALE" ; break ;
229-                         default : fprintf (stderr , "Wrong depth : %d\n" , depth );
229+                         default : fprintf (stderr , "Wrong channel count : %d\n" , ch_count );
230230                }
231231                fprintf (file , "P7\n" 
232232                        "WIDTH %u\n" 
@@ -235,9 +235,9 @@ bool pam_write(const char *filename, unsigned int width, unsigned int height, in
235235                        "MAXVAL %d\n" 
236236                        "TUPLTYPE %s\n" 
237237                        "ENDHDR\n" ,
238-                         width , height , depth , maxval , tuple_type );
238+                         width , height , ch_count , maxval , tuple_type );
239239        }
240-         size_t  len  =  (size_t ) width  *  height  *  depth  *  (maxval  <= 255  ? 1  : 2 );
240+         size_t  len  =  (size_t ) width  *  height  *  ch_count  *  (maxval  <= 255  ? 1  : 2 );
241241        errno  =  0 ;
242242        size_t  bytes_written  =  fwrite ((const  char  * ) data , 1 , len , file );
243243        if  (bytes_written  !=  len ) {
0 commit comments