1 /* @file plustek-pp_scale.c
2 * @brief Scaling functionality
3 *
4 * Copyright (C) 2000-2004 Gerhard Jaeger <gerhard@gjaeger.de>
5 *
6 * History:
7 * - 0.32 - initial version
8 * - 0.33 - no changes
9 * - 0.34 - no changes
10 * - 0.35 - no changes
11 * - 0.36 - no changes
12 * - 0.37 - no changes
13 * - 0.38 - no changes
14 * - 0.39 - no changes
15 * - 0.40 - no changes
16 * - 0.41 - no changes
17 * - 0.42 - changed include names
18 * - 0.43 - cleanup, removed floating point stuff
19 * .
20 * <hr>
21 * This file is part of the SANE package.
22 *
23 * This program is free software; you can redistribute it and/or
24 * modify it under the terms of the GNU General Public License as
25 * published by the Free Software Foundation; either version 2 of the
26 * License, or (at your option) any later version.
27 *
28 * This program is distributed in the hope that it will be useful, but
29 * WITHOUT ANY WARRANTY; without even the implied warranty of
30 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
31 * General Public License for more details.
32 *
33 * You should have received a copy of the GNU General Public License
34 * along with this program. If not, see <https://www.gnu.org/licenses/>.
35 *
36 * As a special exception, the authors of SANE give permission for
37 * additional uses of the libraries contained in this release of SANE.
38 *
39 * The exception is that, if you link a SANE library with other files
40 * to produce an executable, this does not by itself cause the
41 * resulting executable to be covered by the GNU General Public
42 * License. Your use of that executable is in no way restricted on
43 * account of linking the SANE library code into it.
44 *
45 * This exception does not, however, invalidate any other reasons why
46 * the executable file might be covered by the GNU General Public
47 * License.
48 *
49 * If you submit changes to SANE to the maintainers to be included in
50 * a subsequent release, you agree by submitting the changes that
51 * those changes may be distributed with this exception intact.
52 *
53 * If you write modifications of your own for SANE, it is your choice
54 * whether to permit this exception to apply to your modifications.
55 * If you do not wish that, delete this exception notice.
56 * <hr>
57 */
58 #include "plustek-pp_scan.h"
59
60 /************************ exported functions *********************************/
61
62 /** scaling picture data in x-direction, using a DDA algo
63 * (digital differential analyzer).
64 */
ScaleX( pScanData ps, pUChar inBuf, pUChar outBuf )65 _LOC void ScaleX( pScanData ps, pUChar inBuf, pUChar outBuf )
66 {
67 UChar tmp;
68 int step;
69 int izoom;
70 int ddax;
71 register ULong i, j, x;
72
73 #ifdef DEBUG
74 _VAR_NOT_USED( dbg_level );
75 #endif
76
77 /* scale... */
78 izoom = (int)(1000000/ps->DataInf.XYRatio);
79
80 switch( ps->DataInf.wAppDataType ) {
81
82 case COLOR_BW : step = 0; break;
83 case COLOR_HALFTONE: step = 0; break;
84 case COLOR_256GRAY : step = 1; break;
85 case COLOR_TRUE24 : step = 3; break; /*NOTE: COLOR_TRUE32 is the same !*/
86 case COLOR_TRUE48 : step = 6; break;
87 default : step = 99; break;
88 }
89
90 /* when not supported, only copy the data
91 */
92 if( 99 == step ) {
93 memcpy( outBuf, inBuf, ps->DataInf.dwAppBytesPerLine );
94 return;
95 }
96
97 /* now scale...
98 */
99 ddax = 0;
100 x = 0;
101 if( 0 == step ) {
102
103 /* binary scaling
104 */
105 memset( outBuf, 0, ps->DataInf.dwAppBytesPerLine );
106
107 for( i = 0; i < ps->DataInf.dwPhysBytesPerLine*8; i++ ) {
108
109 ddax -= 1000;
110
111 while( ddax < 0 ) {
112
113 tmp = inBuf[(i>>3)];
114
115 if((x>>3) < ps->DataInf.dwAppBytesPerLine ) {
116 if( 0 != (tmp &= (1 << ((~(i & 0x7))&0x7))))
117 outBuf[x>>3] |= (1 << ((~(x & 0x7))&0x7));
118 }
119 x++;
120 ddax += izoom;
121 }
122 }
123
124 } else {
125
126 /* color and gray scaling
127 */
128 for( i = 0; i < ps->DataInf.dwPhysBytesPerLine*step; i+=step ) {
129
130 ddax -= 1000;
131
132 while( ddax < 0 ) {
133
134 for( j = 0; j < (ULong)step; j++ ) {
135
136 if((x+j) < ps->DataInf.dwAppBytesPerLine ) {
137 outBuf[x+j] = inBuf[i+j];
138 }
139 }
140 x += step;
141 ddax += izoom;
142 }
143 }
144 }
145 }
146
147 /* END PLUSTEK-PP_SCALE.C ...................................................*/
148