1 /*****************************************************************************\
2 scaler_open.cpp : Implimentation for the Scaler_Open 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 \*****************************************************************************/
32 #include "scaler_open.h"
37 Scaler_Open::Scaler_Open(SystemServices* pSys,int inputwidth,
38 int numerator,int denominator,
39 BOOL bVIP, unsigned int iNumInks)
40 : Scaler(pSys,inputwidth,numerator,denominator,bVIP, iNumInks),
41 NumInks(iNumInks), vip(bVIP)
43 rowremainder = remainder;
46 Scaler_Open::~Scaler_Open()
49 BOOL Scaler_Open::Process(RASTERDATA* raster_in)
53 if (raster_in == NULL || (raster_in->rasterdata[COLORTYPE_COLOR] == NULL && raster_in->rasterdata[COLORTYPE_BLACK] == NULL))
55 rowremainder=remainder;
61 // just copy both to output buffer
62 for (int i = COLORTYPE_COLOR; i < MAX_COLORTYPE; i++)
64 if (raster_in->rasterdata[i])
66 memcpy(pOutputBuffer[i], raster_in->rasterdata[i], raster_in->rastersize[i]);
73 if (myplane == COLORTYPE_COLOR)
75 if (raster_in->rasterdata[COLORTYPE_BLACK])
77 memcpy(pOutputBuffer[COLORTYPE_BLACK], raster_in->rasterdata[COLORTYPE_BLACK], raster_in->rastersize[COLORTYPE_BLACK]);
81 if (myplane == COLORTYPE_BLACK)
83 if (raster_in->rasterdata[COLORTYPE_COLOR])
85 memcpy(pOutputBuffer[COLORTYPE_COLOR], raster_in->rasterdata[COLORTYPE_COLOR], raster_in->rastersize[COLORTYPE_COLOR]);
90 unsigned int ifactor = (unsigned int) (int) ScaleFactor;
91 unsigned int targptr=0;
92 unsigned int sourceptr=0;
93 unsigned int rem = remainder;
95 if (myplane == COLORTYPE_COLOR || myplane == COLORTYPE_BOTH)
97 if (raster_in->rasterdata[COLORTYPE_COLOR])
99 if (vip) // RGB values interleaved
101 unsigned int width = iInputWidth*3;
102 for (unsigned int i=0; i < width; i += 3)
104 unsigned int factor = ifactor;
110 for (unsigned int j=0; j < factor; j++)
112 pOutputBuffer[COLORTYPE_COLOR][targptr++] = raster_in->rasterdata[COLORTYPE_COLOR][i];
113 pOutputBuffer[COLORTYPE_COLOR][targptr++] = raster_in->rasterdata[COLORTYPE_COLOR][i+1];
114 pOutputBuffer[COLORTYPE_COLOR][targptr++] = raster_in->rasterdata[COLORTYPE_COLOR][i+2];
119 else // KCMY values NOT interleaved
120 // iInputWidth = bytes per plane
121 for (unsigned int i=0; i < NumInks; i++) // loop over planes
123 unsigned int planecount=0; // count output bytes for this plane
124 unsigned int src=0; // count input bytes for this plane
125 while ((planecount < iOutputWidth-1) && (src < iInputWidth))
127 unsigned int factor = ifactor;
133 for (unsigned int j=0; (j < factor) && (planecount < iOutputWidth-1); j++)
135 pOutputBuffer[COLORTYPE_COLOR][targptr++] = raster_in->rasterdata[COLORTYPE_COLOR][sourceptr];
141 while (planecount < iOutputWidth-1) // fill out odd bytes so all planes are equal
143 pOutputBuffer[COLORTYPE_COLOR][targptr++] = raster_in->rasterdata[COLORTYPE_COLOR][sourceptr-1];
151 ifactor = (unsigned int) (int) ScaleFactor;
156 if (myplane == COLORTYPE_BLACK || myplane == COLORTYPE_BOTH)
158 if (raster_in->rasterdata[COLORTYPE_BLACK])
160 // K values NOT interleaved
161 // iInputWidth = bytes per plane
162 unsigned int planecount=0; // count output bytes for this plane
163 unsigned int src=0; // count input bytes for this plane
164 while ((planecount < iOutputWidth-1) && (src < iInputWidth))
166 unsigned int factor = ifactor;
172 for (unsigned int j=0; (j < factor) && (planecount < iOutputWidth-1); j++)
174 pOutputBuffer[COLORTYPE_BLACK][targptr++] = raster_in->rasterdata[COLORTYPE_BLACK][sourceptr];
180 while (planecount < iOutputWidth-1) // fill out odd bytes so all planes are equal
182 pOutputBuffer[COLORTYPE_BLACK][targptr++] = raster_in->rasterdata[COLORTYPE_BLACK][sourceptr-1];
188 unsigned int factor = ifactor;
189 if (rowremainder >= 1000)
192 rowremainder -= 1000;
194 if (myplane == COLORTYPE_BLACK && raster_in->rasterdata[COLORTYPE_COLOR])
197 iRastersReady=factor;
199 rowremainder += remainder;
204 BYTE* Scaler_Open::NextOutputRaster(COLORTYPE color)
206 if (iRastersReady==0)
209 if (myplane == COLORTYPE_BLACK)
211 if (raster.rasterdata[myplane] == NULL)
214 if (color == COLORTYPE_COLOR)
216 iRastersReady--; iRastersDelivered++;
218 if (raster.rastersize[color] > 0)
220 return pOutputBuffer[color];