275
template <typename Image>
276
inline void scale_image_bilinear (Image& target,const Image& source)
279
int source_width=source.width();
280
int source_height=source.height();
282
int target_width=target.width();
283
int target_height=target.height();
285
if (source_width<1 || source_height<1 ||
286
target_width<1 || target_height<1) return;
287
int x=0,y=0,xs=0,ys=0;
288
int tw2 = target_width/2;
289
int th2 = target_height/2;
292
for (y=0;y<target_height;++y)
294
ys = y*source_height/target_height;
296
if (ys1>=source_height)
298
unsigned yprt = y*source_height%target_height;
299
unsigned yprt1 = target_height-yprt;
300
for (x=0;x<target_width;++x)
302
xs = x*source_width/target_width;
303
if (source_width>=target_width || source_height>=target_height){
304
target(x,y)=source(xs,ys);
307
unsigned xprt = x*source_width%target_width;
308
unsigned xprt1 = target_width-xprt;
310
if (xs1>=source_width)
313
unsigned a = source(xs,ys);
314
unsigned b = source(xs1,ys);
315
unsigned c = source(xs,ys1);
316
unsigned d = source(xs1,ys1);
320
for(int i=0; i<4; i++){
326
r = (r*xprt+p*xprt1+tw2)/target_width;
330
s = (s*xprt+p*xprt1+tw2)/target_width;
333
r = (s*yprt+r*yprt1+th2)/target_height;
347
template <typename Image>
348
inline void scale_image_bilinear8 (Image& target,const Image& source)
351
int source_width=source.width();
352
int source_height=source.height();
354
int target_width=target.width();
355
int target_height=target.height();
357
if (source_width<1 || source_height<1 ||
358
target_width<1 || target_height<1) return;
359
int x=0,y=0,xs=0,ys=0;
360
int tw2 = target_width/2;
361
int th2 = target_height/2;
364
for (y=0;y<target_height;++y)
366
ys = y*source_height/target_height;
368
if (ys1>=source_height)
370
unsigned yprt = y*source_height%target_height;
371
unsigned yprt1 = target_height-yprt;
372
for (x=0;x<target_width;++x)
374
xs = x*source_width/target_width;
375
if (source_width>=target_width || source_height>=target_height){
376
target(x,y)=source(xs,ys);
379
unsigned xprt = x*source_width%target_width;
380
unsigned xprt1 = target_width-xprt;
382
if (xs1>=source_width)
385
unsigned a = source(xs,ys);
386
unsigned b = source(xs1,ys);
387
unsigned c = source(xs,ys1);
388
unsigned d = source(xs1,ys1);
394
r = (r*xprt+p*xprt1+tw2)/target_width;
398
s = (s*xprt+p*xprt1+tw2)/target_width;
401
r = (s*yprt+r*yprt1+th2)/target_height;
402
target(x,y)=(0xff<<24) | (r<<16) | (r<<8) | r;
271
407
inline MAPNIK_DECL void save_to_file (Image32 const& image,
272
408
std::string const& file,
273
409
std::string const& type)