1141cc406Sopenharmony_ci/* @file plustek-pp_scale.c 2141cc406Sopenharmony_ci * @brief Scaling functionality 3141cc406Sopenharmony_ci * 4141cc406Sopenharmony_ci * Copyright (C) 2000-2004 Gerhard Jaeger <gerhard@gjaeger.de> 5141cc406Sopenharmony_ci * 6141cc406Sopenharmony_ci * History: 7141cc406Sopenharmony_ci * - 0.32 - initial version 8141cc406Sopenharmony_ci * - 0.33 - no changes 9141cc406Sopenharmony_ci * - 0.34 - no changes 10141cc406Sopenharmony_ci * - 0.35 - no changes 11141cc406Sopenharmony_ci * - 0.36 - no changes 12141cc406Sopenharmony_ci * - 0.37 - no changes 13141cc406Sopenharmony_ci * - 0.38 - no changes 14141cc406Sopenharmony_ci * - 0.39 - no changes 15141cc406Sopenharmony_ci * - 0.40 - no changes 16141cc406Sopenharmony_ci * - 0.41 - no changes 17141cc406Sopenharmony_ci * - 0.42 - changed include names 18141cc406Sopenharmony_ci * - 0.43 - cleanup, removed floating point stuff 19141cc406Sopenharmony_ci * . 20141cc406Sopenharmony_ci * <hr> 21141cc406Sopenharmony_ci * This file is part of the SANE package. 22141cc406Sopenharmony_ci * 23141cc406Sopenharmony_ci * This program is free software; you can redistribute it and/or 24141cc406Sopenharmony_ci * modify it under the terms of the GNU General Public License as 25141cc406Sopenharmony_ci * published by the Free Software Foundation; either version 2 of the 26141cc406Sopenharmony_ci * License, or (at your option) any later version. 27141cc406Sopenharmony_ci * 28141cc406Sopenharmony_ci * This program is distributed in the hope that it will be useful, but 29141cc406Sopenharmony_ci * WITHOUT ANY WARRANTY; without even the implied warranty of 30141cc406Sopenharmony_ci * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 31141cc406Sopenharmony_ci * General Public License for more details. 32141cc406Sopenharmony_ci * 33141cc406Sopenharmony_ci * You should have received a copy of the GNU General Public License 34141cc406Sopenharmony_ci * along with this program. If not, see <https://www.gnu.org/licenses/>. 35141cc406Sopenharmony_ci * 36141cc406Sopenharmony_ci * As a special exception, the authors of SANE give permission for 37141cc406Sopenharmony_ci * additional uses of the libraries contained in this release of SANE. 38141cc406Sopenharmony_ci * 39141cc406Sopenharmony_ci * The exception is that, if you link a SANE library with other files 40141cc406Sopenharmony_ci * to produce an executable, this does not by itself cause the 41141cc406Sopenharmony_ci * resulting executable to be covered by the GNU General Public 42141cc406Sopenharmony_ci * License. Your use of that executable is in no way restricted on 43141cc406Sopenharmony_ci * account of linking the SANE library code into it. 44141cc406Sopenharmony_ci * 45141cc406Sopenharmony_ci * This exception does not, however, invalidate any other reasons why 46141cc406Sopenharmony_ci * the executable file might be covered by the GNU General Public 47141cc406Sopenharmony_ci * License. 48141cc406Sopenharmony_ci * 49141cc406Sopenharmony_ci * If you submit changes to SANE to the maintainers to be included in 50141cc406Sopenharmony_ci * a subsequent release, you agree by submitting the changes that 51141cc406Sopenharmony_ci * those changes may be distributed with this exception intact. 52141cc406Sopenharmony_ci * 53141cc406Sopenharmony_ci * If you write modifications of your own for SANE, it is your choice 54141cc406Sopenharmony_ci * whether to permit this exception to apply to your modifications. 55141cc406Sopenharmony_ci * If you do not wish that, delete this exception notice. 56141cc406Sopenharmony_ci * <hr> 57141cc406Sopenharmony_ci */ 58141cc406Sopenharmony_ci#include "plustek-pp_scan.h" 59141cc406Sopenharmony_ci 60141cc406Sopenharmony_ci/************************ exported functions *********************************/ 61141cc406Sopenharmony_ci 62141cc406Sopenharmony_ci/** scaling picture data in x-direction, using a DDA algo 63141cc406Sopenharmony_ci * (digital differential analyzer). 64141cc406Sopenharmony_ci */ 65141cc406Sopenharmony_ci_LOC void ScaleX( pScanData ps, pUChar inBuf, pUChar outBuf ) 66141cc406Sopenharmony_ci{ 67141cc406Sopenharmony_ci UChar tmp; 68141cc406Sopenharmony_ci int step; 69141cc406Sopenharmony_ci int izoom; 70141cc406Sopenharmony_ci int ddax; 71141cc406Sopenharmony_ci register ULong i, j, x; 72141cc406Sopenharmony_ci 73141cc406Sopenharmony_ci#ifdef DEBUG 74141cc406Sopenharmony_ci _VAR_NOT_USED( dbg_level ); 75141cc406Sopenharmony_ci#endif 76141cc406Sopenharmony_ci 77141cc406Sopenharmony_ci /* scale... */ 78141cc406Sopenharmony_ci izoom = (int)(1000000/ps->DataInf.XYRatio); 79141cc406Sopenharmony_ci 80141cc406Sopenharmony_ci switch( ps->DataInf.wAppDataType ) { 81141cc406Sopenharmony_ci 82141cc406Sopenharmony_ci case COLOR_BW : step = 0; break; 83141cc406Sopenharmony_ci case COLOR_HALFTONE: step = 0; break; 84141cc406Sopenharmony_ci case COLOR_256GRAY : step = 1; break; 85141cc406Sopenharmony_ci case COLOR_TRUE24 : step = 3; break; /*NOTE: COLOR_TRUE32 is the same !*/ 86141cc406Sopenharmony_ci case COLOR_TRUE48 : step = 6; break; 87141cc406Sopenharmony_ci default : step = 99; break; 88141cc406Sopenharmony_ci } 89141cc406Sopenharmony_ci 90141cc406Sopenharmony_ci /* when not supported, only copy the data 91141cc406Sopenharmony_ci */ 92141cc406Sopenharmony_ci if( 99 == step ) { 93141cc406Sopenharmony_ci memcpy( outBuf, inBuf, ps->DataInf.dwAppBytesPerLine ); 94141cc406Sopenharmony_ci return; 95141cc406Sopenharmony_ci } 96141cc406Sopenharmony_ci 97141cc406Sopenharmony_ci /* now scale... 98141cc406Sopenharmony_ci */ 99141cc406Sopenharmony_ci ddax = 0; 100141cc406Sopenharmony_ci x = 0; 101141cc406Sopenharmony_ci if( 0 == step ) { 102141cc406Sopenharmony_ci 103141cc406Sopenharmony_ci /* binary scaling 104141cc406Sopenharmony_ci */ 105141cc406Sopenharmony_ci memset( outBuf, 0, ps->DataInf.dwAppBytesPerLine ); 106141cc406Sopenharmony_ci 107141cc406Sopenharmony_ci for( i = 0; i < ps->DataInf.dwPhysBytesPerLine*8; i++ ) { 108141cc406Sopenharmony_ci 109141cc406Sopenharmony_ci ddax -= 1000; 110141cc406Sopenharmony_ci 111141cc406Sopenharmony_ci while( ddax < 0 ) { 112141cc406Sopenharmony_ci 113141cc406Sopenharmony_ci tmp = inBuf[(i>>3)]; 114141cc406Sopenharmony_ci 115141cc406Sopenharmony_ci if((x>>3) < ps->DataInf.dwAppBytesPerLine ) { 116141cc406Sopenharmony_ci if( 0 != (tmp &= (1 << ((~(i & 0x7))&0x7)))) 117141cc406Sopenharmony_ci outBuf[x>>3] |= (1 << ((~(x & 0x7))&0x7)); 118141cc406Sopenharmony_ci } 119141cc406Sopenharmony_ci x++; 120141cc406Sopenharmony_ci ddax += izoom; 121141cc406Sopenharmony_ci } 122141cc406Sopenharmony_ci } 123141cc406Sopenharmony_ci 124141cc406Sopenharmony_ci } else { 125141cc406Sopenharmony_ci 126141cc406Sopenharmony_ci /* color and gray scaling 127141cc406Sopenharmony_ci */ 128141cc406Sopenharmony_ci for( i = 0; i < ps->DataInf.dwPhysBytesPerLine*step; i+=step ) { 129141cc406Sopenharmony_ci 130141cc406Sopenharmony_ci ddax -= 1000; 131141cc406Sopenharmony_ci 132141cc406Sopenharmony_ci while( ddax < 0 ) { 133141cc406Sopenharmony_ci 134141cc406Sopenharmony_ci for( j = 0; j < (ULong)step; j++ ) { 135141cc406Sopenharmony_ci 136141cc406Sopenharmony_ci if((x+j) < ps->DataInf.dwAppBytesPerLine ) { 137141cc406Sopenharmony_ci outBuf[x+j] = inBuf[i+j]; 138141cc406Sopenharmony_ci } 139141cc406Sopenharmony_ci } 140141cc406Sopenharmony_ci x += step; 141141cc406Sopenharmony_ci ddax += izoom; 142141cc406Sopenharmony_ci } 143141cc406Sopenharmony_ci } 144141cc406Sopenharmony_ci } 145141cc406Sopenharmony_ci} 146141cc406Sopenharmony_ci 147141cc406Sopenharmony_ci/* END PLUSTEK-PP_SCALE.C ...................................................*/ 148