|
|
| version 1.20, 2001/10/19 12:43:30 | version 1.30.2.1, 2003/01/29 13:40:30 |
|---|---|
| Line 1 | Line 1 |
| /** @file | /** @file |
| Parser: image manipulations impl1. | Parser: image manipulations impl1. |
| Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com) | Copyright (c) 2001, 2003 ArtLebedev Group (http://www.artlebedev.com) |
| Author: Alexander Petrosyan <paf@design.ru> (http://design.ru/paf) | Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru) |
| $Id$ | |
| based on: gd | based on: gd |
| Written by Tom Boutell, 5/94. | Written by Tom Boutell, 5/94. |
| Line 17 | Line 14 |
| can incorporate them into new versions. | can incorporate them into new versions. |
| */ | */ |
| static const char* IDENT_GIF_C="$Date$"; | |
| #include "gif.h" | #include "gif.h" |
| #include "pa_value_includes.h" | |
| #include "mtables.h" | #include "mtables.h" |
| #include "pa_common.h" | |
| //static void BrushApply(int x, int y); | //static void BrushApply(int x, int y); |
| //static void TileApply(int x, int y); | //static void TileApply(int x, int y); |
| Line 337 void gdImage::Arc(int cx, int cy, int w, | Line 338 void gdImage::Arc(int cx, int cy, int w, |
| int w2, h2; | int w2, h2; |
| w2 = w/2; | w2 = w/2; |
| h2 = h/2; | h2 = h/2; |
| while (e < s) { | while (e < s) e += 360; |
| e += 360; | // paf |
| } | while(s<0) s+=360; |
| while(s>360) s-=360; | |
| while(e<0) e+=360; | |
| while(e>360) e-=360; | |
| for (i=s; (i <= e); i++) { | for (i=s; (i <= e); i++) { |
| int x, y; | int x, y; |
| x = ((long)cost[i % 360] * (long)w2 / costScale) + cx; | x = ((long)cost[i] * (long)w2 / costScale) + cx; |
| y = ((long)sint[i % 360] * (long)h2 / sintScale) + cy; | y = ((long)sint[i] * (long)h2 / sintScale) + cy; |
| if (i != s) { | if (i != s) { |
| Line(lx, ly, x, y, color); | Line(lx, ly, x, y, color); |
| } | } |
| Line 402 void gdImage::Sector(int cx, int cy, int | Line 406 void gdImage::Sector(int cx, int cy, int |
| int w2, h2; | int w2, h2; |
| w2 = w/2; | w2 = w/2; |
| h2 = h/2; | h2 = h/2; |
| while (e < s) { | while (e < s) e += 360; |
| e += 360; | // paf |
| } | while(s<0) s+=360; |
| while(s>360) s-=360; | |
| while(e<0) e+=360; | |
| while(e>360) e-=360; | |
| for (i=s; (i <= e); i++) { | for (i=s; (i <= e); i++) { |
| int x, y; | int x, y; |
| x = ((long)cost[i % 360] * (long)w2 / costScale) + cx; | x = ((long)cost[i] * (long)w2 / costScale) + cx; |
| y = ((long)sint[i % 360] * (long)h2 / sintScale) + cy; | y = ((long)sint[i] * (long)h2 / sintScale) + cy; |
| if(i==s || i==e) | if(i==s || i==e) |
| Line(cx, cy, x, y, color); | Line(cx, cy, x, y, color); |
| if (i != s) { | if (i != s) { |
| Line 642 void gdImage::Copy(gdImage& dst, int dst | Line 649 void gdImage::Copy(gdImage& dst, int dst |
| } | } |
| } | } |
| static double round(double param) { return floor(param+0.5); } | |
| void gdImage::CopyResampled(gdImage& dst, | void gdImage::CopyResampled(gdImage& dst, |
| int dstX, int dstY, | int dstX, int dstY, |
| int srcX, int srcY, | int srcX, int srcY, |
| Line 652 void gdImage::CopyResampled(gdImage& dst | Line 658 void gdImage::CopyResampled(gdImage& dst |
| { | { |
| gdImage& src=*this; | gdImage& src=*this; |
| int x, y; | int x, y; |
| int srcTransparent=src.GetTransparent(); | |
| int dstTransparent=dst.GetTransparent(); | |
| for (y = dstY; (y < dstY + dstH); y++) { | for (y = dstY; (y < dstY + dstH); y++) { |
| for (x = dstX; (x < dstX + dstW); x++) { | for (x = dstX; (x < dstX + dstW); x++) { |
| int pd = dst.GetPixel (x, y); | int pd = dst.GetPixel (x, y); |
| /* Added 7/24/95: support transparent copies */ | /* Added 7/24/95: support transparent copies */ |
| if (src.GetTransparent() == pd) | /* fixed by paf 20030116, another fix below */ |
| if (pd == dstTransparent) | |
| continue; | continue; |
| double sy1, sy2, sx1, sx2; | double sy1, sy2, sx1, sx2; |
| double sx, sy; | double sx, sy; |
| double spixels = 0; | double spixels = 0; |
| double red = 0.0, green = 0.0, blue = 0.0; | double red = 0.0, green = 0.0, blue = 0.0; |
| bool transparent=true; | |
| sy1 = ((double) y - (double) dstY) * (double) srcH / | sy1 = ((double) y - (double) dstY) * (double) srcH / |
| (double) dstH; | (double) dstH; |
| sy2 = ((double) (y + 1) - (double) dstY) * (double) srcH / | sy2 = ((double) (y + 1) - (double) dstY) * (double) srcH / |
| Line 719 void gdImage::CopyResampled(gdImage& dst | Line 729 void gdImage::CopyResampled(gdImage& dst |
| p = src.GetPixel ( | p = src.GetPixel ( |
| (int) sx, | (int) sx, |
| (int) sy); | (int) sy); |
| red += Red (p) * pcontribution; | // fix added 20020116 by paf to support transparent src |
| green += Green (p) * pcontribution; | if (p!=srcTransparent) { |
| blue += Blue (p) * pcontribution; | transparent = false; |
| red += Red (p) * pcontribution; | |
| green += Green (p) * pcontribution; | |
| blue += Blue (p) * pcontribution; | |
| } | |
| spixels += xportion * yportion; | spixels += xportion * yportion; |
| sx += 1.0; | sx += 1.0; |
| } while (sx < sx2); | } while (sx < sx2); |
| sy += 1.0; | sy += 1.0; |
| } while (sy < sy2); | } while (sy < sy2); |
| if(transparent) | |
| continue; | |
| if (spixels != 0.0) { | if (spixels != 0.0) { |
| red /= spixels; | red /= spixels; |
| green /= spixels; | green /= spixels; |
| Line 939 void gdImage::LineReplaceColor(int x1, i | Line 957 void gdImage::LineReplaceColor(int x1, i |
| if(y1!=y2) | if(y1!=y2) |
| return; | return; |
| for(int x=x1; x<=x2; x++) { | for(int x=x1; x<=x2; x++) |
| unsigned char *pixel=&pixels[x][y1]; | if(BoundsSafe(x, y1)) { |
| if(*pixel==a) | unsigned char *pixel=&pixels[x][y1]; |
| *pixel=b; | if(*pixel==a) |
| } | *pixel=b; |
| } | |
| } | } |
| void gdImage::FilledPolygonReplaceColor(Point *p, int n, int a, int b) | void gdImage::FilledPolygonReplaceColor(Point *p, int n, int a, int b) |