File indexing completed on 2025-03-09 04:09:53

0001 /* Run-time scaletable computation for Xcftools
0002  *
0003  * This file was written by Henning Makholm <henning@makholm.net>
0004  * It is hereby in the public domain.
0005  * 
0006  * In jurisdictions that do not recognise grants of copyright to the
0007  * public domain: I, the author and (presumably, in those jurisdictions)
0008  * copyright holder, hereby permit anyone to distribute and use this code,
0009  * in source code or binary form, with or without modifications. This
0010  * permission is world-wide and irrevocable.
0011  *
0012  * Of course, I will not be liable for any errors or shortcomings in the
0013  * code, since I give it away without asking any compenstations.
0014  *
0015  * If you use or distribute this code, I would appreciate receiving
0016  * credit for writing it, in whichever way you find proper and customary.
0017  */
0018 
0019 #include "pixels.h"
0020 #ifndef PRECOMPUTED_SCALETABLE
0021 
0022 uint8_t scaletable[256][256] ;
0023 int ok_scaletable = 0 ;
0024 
0025 void
0026 mk_scaletable(void)
0027 {
0028   unsigned p, q, r ;
0029   if( ok_scaletable ) return ;
0030   for( p = 0 ; p < 128 ; p++ )
0031     for( q = 0 ; q <= p ; q++  ) {
0032       r = (p*q+127)/255 ;
0033       scaletable[p][q] = scaletable[q][p] = r ;
0034       scaletable[255-p][q] = scaletable[q][255-p] = q-r ;
0035       scaletable[p][255-q] = scaletable[255-q][p] = p-r ;
0036       scaletable[255-p][255-q] = scaletable[255-q][255-p] = (255-q)-(p-r) ;
0037     }
0038   ok_scaletable = 1 ;
0039 }
0040 
0041 #endif
0042