summaryrefslogtreecommitdiffstats
path: root/scaletab.c
blob: a8b013fe7a8304602b352bde47437f8876a5a840 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/* Run-time scaletable computation for Xcftools
 *
 * This file was written by Henning Makholm <henning@makholm.net>
 * It is hereby in the public domain.
 * 
 * In jurisdictions that do not recognise grants of copyright to the
 * public domain: I, the author and (presumably, in those jurisdictions)
 * copyright holder, hereby permit anyone to distribute and use this code,
 * in source code or binary form, with or without modifications. This
 * permission is world-wide and irrevocable.
 *
 * Of course, I will not be liable for any errors or shortcomings in the
 * code, since I give it away without asking any compenstations.
 *
 * If you use or distribute this code, I would appreciate receiving
 * credit for writing it, in whichever way you find proper and customary.
 */

#include "pixels.h"
#ifndef PRECOMPUTED_SCALETABLE

uint8_t scaletable[256][256] ;
int ok_scaletable = 0 ;

void
mk_scaletable(void)
{
  unsigned p, q, r ;
  if( ok_scaletable ) return ;
  for( p = 0 ; p < 128 ; p++ )
    for( q = 0 ; q <= p ; q++  ) {
      r = (p*q+127)/255 ;
      scaletable[p][q] = scaletable[q][p] = r ;
      scaletable[255-p][q] = scaletable[q][255-p] = q-r ;
      scaletable[p][255-q] = scaletable[255-q][p] = p-r ;
      scaletable[255-p][255-q] = scaletable[255-q][255-p] = (255-q)-(p-r) ;
    }
  ok_scaletable = 1 ;
}

#endif