1 /*****************************************************************************\
2 scaler.cpp : Implimentation for the Scaler class
4 Copyright (c) 1996 - 2001, Hewlett-Packard Co.
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions
10 1. Redistributions of source code must retain the above copyright
11 notice, this list of conditions and the following disclaimer.
12 2. Redistributions in binary form must reproduce the above copyright
13 notice, this list of conditions and the following disclaimer in the
14 documentation and/or other materials provided with the distribution.
15 3. Neither the name of Hewlett-Packard nor the names of its
16 contributors may be used to endorse or promote products derived
17 from this software without specific prior written permission.
19 THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
20 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
22 NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
24 TO, PATENT INFRINGEMENT; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
25 OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26 ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 \*****************************************************************************/
35 #define MAX_OUTPUT_RASTERS 32
38 Scaler::Scaler(SystemServices* pSys,unsigned int inputwidth,
39 unsigned int numerator,unsigned int denominator, BOOL vip, unsigned int BytesPerPixel)
40 : pSS(pSys), iInputWidth(inputwidth)
43 ASSERT(denominator > 0);
45 constructor_error=NO_ERROR;
46 for (int i = COLORTYPE_COLOR; i < MAX_COLORTYPE; i++)
\r
48 pOutputBuffer[i] = NULL;
\r
51 ScaleFactor= (float)numerator / (float)denominator;
52 if (ScaleFactor > (float)MAX_OUTPUT_RASTERS) //
54 constructor_error = INDEX_OUT_OF_RANGE;
57 int factor = (int)ScaleFactor;
58 float rem = ScaleFactor - (float)factor;
62 iOutputWidth = (int) (((float) iInputWidth / (float) denominator) *
64 iOutputWidth++; // safety measure to protect against roundoff error
66 if (numerator == denominator)
71 // ScaleBound=max number of output rows per input row;
72 // i.e., if scale=4.28, then sometimes 5 rows will come out
74 int ScaleBound = int(ScaleFactor);
75 if (ScaleFactor > (float) ScaleBound)
78 // allocate a buffer for one output row
79 int RSBuffSize= (int)(((float)(BytesPerPixel*iOutputWidth)) * ScaleBound );
80 pOutputBuffer[COLORTYPE_COLOR]=(BYTE*)pSS->AllocMem(RSBuffSize);
81 if (pOutputBuffer[COLORTYPE_COLOR] == NULL)
83 constructor_error=ALLOCMEM_ERROR;
87 // Initialize RGB buffer to white
\r
90 memset(pOutputBuffer[COLORTYPE_COLOR], 0xFF, RSBuffSize);
\r
93 int BlackBuffSize= (int)(((float)(iOutputWidth)) * ScaleBound );
94 pOutputBuffer[COLORTYPE_BLACK]=(BYTE*)pSS->AllocMem(BlackBuffSize);
95 if (pOutputBuffer[COLORTYPE_BLACK] == NULL)
97 constructor_error=ALLOCMEM_ERROR;
101 if (ScaleFactor < 2.0)
102 ReplicateOnly = TRUE;
103 else ReplicateOnly=FALSE;
105 if (ScaleFactor > (float)factor)
107 else fractional=FALSE;
112 for (int i = COLORTYPE_COLOR; i < MAX_COLORTYPE; i++)
114 if (pOutputBuffer[i])
116 pSS->FreeMemory(pOutputBuffer[i]);
117 pOutputBuffer[i] = NULL;
122 unsigned int Scaler::GetMaxOutputWidth(COLORTYPE rastercolor)
124 if (rastercolor == COLORTYPE_COLOR)
126 return (iOutputWidth-1)*NUMBER_PLANES; // we padded it in case of roundoff error
130 return (iOutputWidth-1); // we padded it in case of roundoff error
134 unsigned int Scaler::GetOutputWidth(COLORTYPE color)
136 if (color == COLORTYPE_COLOR)
138 if (raster.rasterdata[color])
139 if (myplane == COLORTYPE_BLACK)
140 return raster.rastersize[color];
142 return (iOutputWidth-1)*NUMBER_PLANES; // we padded it in case of roundoff error
148 if (raster.rasterdata[color])
149 if (myplane == COLORTYPE_COLOR)
150 return raster.rastersize[color];
152 return (iOutputWidth-1); // we padded it in case of roundoff error