~ubuntu-branches/ubuntu/jaunty/freeimage/jaunty

« back to all changes in this revision

Viewing changes to FreeImage/TestAPI/testTools.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Federico Di Gregorio
  • Date: 2007-05-07 15:35:21 UTC
  • Revision ID: james.westby@ubuntu.com-20070507153521-m4lx765bzxxug9qf
Tags: upstream-3.9.3
Import upstream version 3.9.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// ==========================================================
 
2
// FreeImage 3 Test Script
 
3
//
 
4
// Design and implementation by
 
5
// - Herv� Drolon (drolon@infonie.fr)
 
6
//
 
7
// This file is part of FreeImage 3
 
8
//
 
9
// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY
 
10
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES
 
11
// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE
 
12
// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED
 
13
// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT
 
14
// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY
 
15
// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL
 
16
// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER
 
17
// THIS DISCLAIMER.
 
18
//
 
19
// Use at your own risk!
 
20
// ==========================================================
 
21
 
 
22
 
 
23
#include "TestSuite.h"
 
24
 
 
25
 
 
26
// ----------------------------------------------------------
 
27
 
 
28
/** Create a Zone Plate test pattern.
 
29
 
 
30
  The circular zone plate has zero horizontal and vertical frequencies at the center. 
 
31
  Horizontal frequencies increase as you move horizontally, and vertical frequencies increase as you move vertically.
 
32
  These patterns are useful to:
 
33
  <ul>
 
34
  <li> evaluate image compression 
 
35
  <li> evaluate filter properties 
 
36
  <li> evaluate the quality of resampling algorithms 
 
37
  <li> adjust gamma correction - at the proper gamma setting, the m�ires should be minimized 
 
38
  </ul>
 
39
  Reference: 
 
40
  [1] Ken Turkowski, Open Source Repository. [Online] http://www.worldserver.com/turk/opensource/
 
41
*/
 
42
FIBITMAP* createZonePlateImage(unsigned width, unsigned height, int scale) {
 
43
        const double PI = 3.1415926535898;
 
44
        BYTE sinTab[256];
 
45
 
 
46
        FIBITMAP *dst;
 
47
        int i, j, x, y;
 
48
        int cX, cY, d;
 
49
 
 
50
        // allocate a 8-bit dib
 
51
        dst = FreeImage_Allocate(width, height, 8);
 
52
        if(!dst)
 
53
                return NULL;
 
54
 
 
55
        // build a greyscale palette
 
56
        RGBQUAD *pal = FreeImage_GetPalette(dst);
 
57
        for(i = 0; i < 256; i++) {
 
58
                pal[i].rgbRed = i;
 
59
                pal[i].rgbGreen = i;
 
60
                pal[i].rgbBlue = i;
 
61
        }
 
62
 
 
63
        // build the sinus table
 
64
        for(i = 0; i < 256; i++) {
 
65
                sinTab[i] = (BYTE)(127.5 * sin(PI * (i - 127.5) / 127.5) + 127.5);
 
66
        }
 
67
 
 
68
        cX = width / 2;
 
69
        cY = height / 2;
 
70
        
 
71
        // create a zone plate
 
72
        for(i = height, y = -cY; i--; y++) {
 
73
                BYTE *dst_bits = FreeImage_GetScanLine(dst, i);
 
74
                for (j = width, x = -cX; j--; x++) {
 
75
                        d = ((x * x + y * y) * scale) >> 8;
 
76
                        dst_bits[j] = sinTab[d & 0xFF];
 
77
                }
 
78
        }
 
79
 
 
80
        return dst;
 
81
}
 
82