Tizen 2.1 base
[platform/upstream/hplip.git] / prnt / hpijs / scaler_open.cpp
1 /*****************************************************************************\
2   scaler_open.cpp : Implimentation for the Scaler_Open class
3
4   Copyright (c) 1996 - 2001, Hewlett-Packard Co.
5   All rights reserved.
6
7   Redistribution and use in source and binary forms, with or without
8   modification, are permitted provided that the following conditions
9   are met:
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.
18
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 \*****************************************************************************/
30
31 #include "header.h"
32 #include "scaler_open.h"
33
34
35 APDK_BEGIN_NAMESPACE
36
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)
42 {
43     rowremainder = remainder;
44 }
45
46 Scaler_Open::~Scaler_Open()
47 { }
48
49 BOOL Scaler_Open::Process(RASTERDATA* raster_in)
50 {
51     iRastersDelivered=0;
52
53     if (raster_in == NULL || (raster_in->rasterdata[COLORTYPE_COLOR] == NULL && raster_in->rasterdata[COLORTYPE_BLACK] == NULL))
54     {
55         rowremainder=remainder;
56         return FALSE;
57     }
58
59     if (!scaling)
60         {
61                 // just copy both to output buffer
62                 for (int i = COLORTYPE_COLOR; i < MAX_COLORTYPE; i++)
63                 {
64                         if (raster_in->rasterdata[i])
65                         {
66                                 memcpy(pOutputBuffer[i], raster_in->rasterdata[i], raster_in->rastersize[i]);
67                         }
68                 }
69                 iRastersReady = 1;
70                 return TRUE;
71     }
72
73         if (myplane == COLORTYPE_COLOR)
74         {
75                 if (raster_in->rasterdata[COLORTYPE_BLACK])
76                 {
77                         memcpy(pOutputBuffer[COLORTYPE_BLACK], raster_in->rasterdata[COLORTYPE_BLACK], raster_in->rastersize[COLORTYPE_BLACK]);
78                 }
79         }
80
81         if (myplane == COLORTYPE_BLACK)
82         {
83                 if (raster_in->rasterdata[COLORTYPE_COLOR])
84                 {
85                         memcpy(pOutputBuffer[COLORTYPE_COLOR], raster_in->rasterdata[COLORTYPE_COLOR], raster_in->rastersize[COLORTYPE_COLOR]);
86                 }
87         }
88
89     // multiply row
90     unsigned int ifactor = (unsigned int) (int) ScaleFactor;
91     unsigned int targptr=0;
92     unsigned int sourceptr=0;
93     unsigned int rem = remainder;
94
95         if (myplane == COLORTYPE_COLOR || myplane == COLORTYPE_BOTH)
96         {
97                 if (raster_in->rasterdata[COLORTYPE_COLOR])
98                 {
99                         if (vip)                   // RGB values interleaved
100                         {
101                                 unsigned int width = iInputWidth*3;
102                                 for (unsigned int i=0; i < width; i += 3)
103                                 {
104                                         unsigned int factor = ifactor;
105                                         if (rem >= 1000)
106                                         {
107                                                 factor++;
108                                                 rem -= 1000;
109                                         }
110                                         for (unsigned int j=0; j < factor; j++)
111                                         {
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];
115                                         }
116                                         rem += remainder;
117                                 }
118                         }
119                         else            // KCMY values NOT interleaved
120                                                         // iInputWidth = bytes per plane
121                         for (unsigned int i=0; i < NumInks; i++)  // loop over planes
122                         {
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))
126                                 {
127                                         unsigned int factor = ifactor;
128                                         if (rem >= 1000)
129                                         {
130                                                 factor++;
131                                                 rem -= 1000;
132                                         }
133                                         for (unsigned int j=0; (j < factor) && (planecount < iOutputWidth-1); j++)
134                                         {
135                                                 pOutputBuffer[COLORTYPE_COLOR][targptr++] = raster_in->rasterdata[COLORTYPE_COLOR][sourceptr];
136                                                 planecount++;
137                                         }
138                                         rem += remainder;
139                                         sourceptr++; src++;
140                                 }
141                                 while (planecount < iOutputWidth-1)     // fill out odd bytes so all planes are equal
142                                 {
143                                         pOutputBuffer[COLORTYPE_COLOR][targptr++] = raster_in->rasterdata[COLORTYPE_COLOR][sourceptr-1];
144                                         planecount++;
145                                 }
146
147                         }
148                 }
149         }
150
151         ifactor = (unsigned int) (int) ScaleFactor;
152     targptr=0;
153     sourceptr=0;
154     rem = remainder;
155
156         if (myplane == COLORTYPE_BLACK || myplane == COLORTYPE_BOTH)
157         {       
158                 if (raster_in->rasterdata[COLORTYPE_BLACK])
159                 {       
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))
165                         {
166                                 unsigned int factor = ifactor;
167                                 if (rem >= 1000)
168                                 {
169                                         factor++;
170                                         rem -= 1000;
171                                 }
172                                 for (unsigned int j=0; (j < factor) && (planecount < iOutputWidth-1); j++)
173                                 {
174                                         pOutputBuffer[COLORTYPE_BLACK][targptr++] = raster_in->rasterdata[COLORTYPE_BLACK][sourceptr];
175                                         planecount++;
176                                 }
177                                 rem += remainder;
178                                 sourceptr++; src++;
179                         }
180                         while (planecount < iOutputWidth-1)     // fill out odd bytes so all planes are equal
181                         {
182                                 pOutputBuffer[COLORTYPE_BLACK][targptr++] = raster_in->rasterdata[COLORTYPE_BLACK][sourceptr-1];
183                                 planecount++;
184                         }
185                 }
186         }
187
188     unsigned int factor = ifactor;
189     if (rowremainder >= 1000)
190     {
191         factor++;
192         rowremainder -= 1000;
193     }
194         if (myplane == COLORTYPE_BLACK && raster_in->rasterdata[COLORTYPE_COLOR])
195                 iRastersReady = 1;
196         else
197                 iRastersReady=factor;
198     iRastersDelivered=0;
199     rowremainder += remainder;
200  return TRUE;
201 }
202
203
204 BYTE* Scaler_Open::NextOutputRaster(COLORTYPE color)
205 {
206     if (iRastersReady==0)
207         return NULL;
208
209         if (myplane == COLORTYPE_BLACK)
210         {
211                 if (raster.rasterdata[myplane] == NULL)
212                         iRastersReady = 1;
213         }
214         if (color == COLORTYPE_COLOR)
215         {
216                 iRastersReady--; iRastersDelivered++;
217         }
218         if (raster.rastersize[color] > 0)
219         {
220                 return pOutputBuffer[color];
221         }
222         else
223         {
224                 return NULL;
225         }
226 }
227
228 APDK_END_NAMESPACE
229