Fixed arithmetic overflow in palette generator; some basic fixes related to recent update of the Draw package.

git-svn-id: svn://ultimatepp.org/upp/trunk@1371 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
rylek 2009-07-06 20:09:12 +00:00
parent 814d000ece
commit aa30f86a8c
7 changed files with 129 additions and 125 deletions

View file

@ -182,7 +182,7 @@ void sPalMaker::Update(Box& x, int ii)
static byte sRc(int avg, int pop, int div)
{
return Saturate255(255 * (avg + (pop >> 1)) / pop / (div - 1));
return Saturate255(iscale(avg + (pop >> 1), 255, pop * (div - 1)));
}
sPalMaker::sPalMaker(Raster& raster, RGBA *palette, int ncolors)

View file

@ -1046,7 +1046,7 @@ void HRR::Paint(Draw& draw, const Matrixf& trg_pix, GisTransform transform,
<< ", is_bw = " << is_bw << ", out_pixel = " << out_pixel << ", out_alpha = " << out_alpha);
Matrixf pix_trg = MatrixfInverse(trg_pix);
Rect clip = draw.GetClip();
Rect clip = draw.GetPageSize(); //draw.GetClip();
Rectf csrc = info.log_rect & transform.SourceExtent(Rectf(clip) * pix_trg);
// Pointf scale = Sizef(1, -1) * Sizef(dest.Size()) / Sizef(src.Size());
// Pointf delta = Pointf(dest.TopLeft()) - src.BottomLeft() * scale;

View file

@ -825,7 +825,7 @@ void PathDraw::Set(Draw& _draw, const PathStyle& _style, Color _color, double _w
dash *= -avg;
miter = style->miter;
clip_rect = draw->GetClip();
clip_rect = draw->GetPageSize(); //draw->GetClip();
double cr = style->width;
if(style->miter == style->MITER_SHARP)
{

View file

@ -166,8 +166,8 @@ void LineDraw::Set(Draw& _draw, LineStyle pattern, Color color, int width, doubl
active = NULL;
}
first = last = Null;
clip = draw->GetClip();
Size size = draw->GetPagePixels();
Size size = draw->GetPageSize();
clip = draw->GetPageSize(); // GetClip()
max_rad = max(size.cx, size.cy);
vertices.Clear();
indices.Clear();
@ -607,7 +607,7 @@ void Plotter::Set(Draw& _draw, Sizef _scale, Pointf _delta, int reserve, double
void Plotter::Set(Draw& _draw, const Matrixf& matrix, int reserve, double meter)
{
Rect rc = _draw.GetClip();
Rect rc = _draw.GetPageSize(); //GetClip();
if(reserve < 0)
reserve = DotsToPixels(_draw, -reserve);
rc.Inflate(reserve);
@ -664,12 +664,14 @@ void Plotter::SetMapMeters(double mm)
void Plotter::SetXorMode(bool xm)
{
if(SystemDraw *sdraw = dynamic_cast<SystemDraw *>(draw)) {
#ifdef PLATFORM_WIN32
SetROP2(*draw, xm ? R2_NOTXORPEN : R2_COPYPEN);
SetROP2(*sdraw, xm ? R2_NOTXORPEN : R2_COPYPEN);
#endif
#ifdef PLATFORM_X11
XSetFunction(Xdisplay, draw->GetGC(), xm ? X11_ROP2_NOT_XOR : X11_ROP2_COPY);
XSetFunction(Xdisplay, sdraw->GetGC(), xm ? X11_ROP2_NOT_XOR : X11_ROP2_COPY);
#endif
}
}
static inline void AddRectMatrix(Rectf& out, const Rectf& rc, const Matrixf& mx)
@ -760,12 +762,14 @@ Point Plotter::LtoPointOrtho(Pointf pt) const
static void PaintRectPart(Draw& draw, int x, int y, int w, int h)
{
if(SystemDraw *sdraw = dynamic_cast<SystemDraw *>(&draw)) {
#if defined(PLATFORM_WIN32)
::PatBlt(draw, x, y, w, h, PATINVERT);
::PatBlt(*sdraw, x, y, w, h, PATINVERT);
#elif defined(PLATFORM_X11)
Point offset = draw.GetOffset();
XFillRectangle(Xdisplay, draw.GetDrawable(), draw.GetGC(), x + offset.x, y + offset.y, w, h);
Point offset = sdraw->GetOffset();
XFillRectangle(Xdisplay, sdraw->GetDrawable(), sdraw->GetGC(), x + offset.x, y + offset.y, w, h);
#endif
}
}
static void PaintRectPart(Draw& draw, const Rect& rc) { PaintRectPart(draw, rc.left, rc.top, rc.Width(), rc.Height()); }
@ -775,129 +779,132 @@ enum { DRAG_STEP = 4 };
void PaintDragHorzLine(Draw& draw, const Rect& rc, Color c1, Color c2, Color bgnd, int mingap)
{
Size sz = rc.Size();
if(SystemDraw *sdraw = dynamic_cast<SystemDraw *>(&draw)) {
#if defined(PLATFORM_WIN32)
draw.BeginGdi();
static word bmp_bits[8];
HBITMAP hbmp = CreateBitmap(8, 8, 1, 1, bmp_bits);
HBRUSH brush = CreatePatternBrush(hbmp);
DeleteObject(hbmp);
COLORREF cc1 = (COLORREF)c1 ^ (COLORREF)bgnd, cc2 = (COLORREF)c2 ^ (COLORREF)bgnd;
COLORREF old_bk = SetTextColor(draw, cc1);
HGDIOBJ old_brush = SelectObject(draw, brush);
sdraw->BeginGdi();
static word bmp_bits[8];
HBITMAP hbmp = CreateBitmap(8, 8, 1, 1, bmp_bits);
HBRUSH brush = CreatePatternBrush(hbmp);
DeleteObject(hbmp);
COLORREF cc1 = (COLORREF)c1 ^ (COLORREF)bgnd, cc2 = (COLORREF)c2 ^ (COLORREF)bgnd;
COLORREF old_bk = SetTextColor(*sdraw, cc1);
HGDIOBJ old_brush = SelectObject(*sdraw, brush);
#elif defined(PLATFORM_X11)
XGCValues gcv_old, gcv_new;
XGetGCValues(Xdisplay, draw.GetGC(), GCForeground | GCFunction, &gcv_old);
gcv_new.function = X11_ROP2_XOR;
gcv_new.foreground = GetXPixel(c1) ^ GetXPixel(bgnd);
XChangeGC(Xdisplay, draw.GetGC(), GCForeground | GCFunction, &gcv_new);
XGCValues gcv_old, gcv_new;
XGetGCValues(Xdisplay, sdraw->GetGC(), GCForeground | GCFunction, &gcv_old);
gcv_new.function = X11_ROP2_XOR;
gcv_new.foreground = GetXPixel(c1) ^ GetXPixel(bgnd);
XChangeGC(Xdisplay, sdraw->GetGC(), GCForeground | GCFunction, &gcv_new);
#endif
int whites = (sz.cx - 2 * mingap + DRAG_STEP) / (2 * DRAG_STEP);
if(rc.Width() <= 2 * mingap)
PaintRectPart(draw, rc);
else if(whites <= 0)
{
PaintRectPart(draw, rc.left, rc.top, mingap, sz.cy);
PaintRectPart(draw, rc.right - mingap, rc.top, mingap, sz.cy);
int whites = (sz.cx - 2 * mingap + DRAG_STEP) / (2 * DRAG_STEP);
if(rc.Width() <= 2 * mingap)
PaintRectPart(*sdraw, rc);
else if(whites <= 0) {
PaintRectPart(*sdraw, rc.left, rc.top, mingap, sz.cy);
PaintRectPart(*sdraw, rc.right - mingap, rc.top, mingap, sz.cy);
#if defined(PLATFORM_WIN32)
SetTextColor(draw, cc2);
SetTextColor(*sdraw, cc2);
#elif defined(PLATFORM_X11)
gcv_new.foreground = GetXPixel(c2) ^ GetXPixel(bgnd);
XChangeGC(Xdisplay, draw.GetGC(), GCForeground, &gcv_new);
gcv_new.foreground = GetXPixel(c2) ^ GetXPixel(bgnd);
XChangeGC(Xdisplay, sdraw->GetGC(), GCForeground, &gcv_new);
#endif
PaintRectPart(*sdraw, rc.left + mingap, rc.top, sz.cx - 2 * mingap, sz.cy);
}
else
{
int rem = sz.cx - whites * 2 * DRAG_STEP + DRAG_STEP;
int lrem = rem >> 1, rrem = (rem + 1) >> 1;
PaintRectPart(*sdraw, rc.left, rc.top, lrem, sz.cy);
PaintRectPart(*sdraw, rc.right - rrem, rc.top, rrem, sz.cy);
int i;
int start = rc.left + lrem - DRAG_STEP;
for(i = 1; i < whites; i++)
PaintRectPart(*sdraw, start + 2 * DRAG_STEP * i, rc.top, DRAG_STEP, sz.cy);
#if defined(PLATFORM_WIN32)
SetTextColor(*sdraw, cc2);
#elif defined(PLATFORM_X11)
gcv_new.foreground = GetXPixel(c2) ^ GetXPixel(bgnd);
XChangeGC(Xdisplay, sdraw->GetGC(), GCForeground, &gcv_new);
#endif
start = rc.left + lrem;
for(i = 0; i < whites; i++)
PaintRectPart(*sdraw, start + 2 * DRAG_STEP * i, rc.top, DRAG_STEP, sz.cy);
}
#if defined(PLATFORM_WIN32)
SelectObject(*sdraw, old_brush);
DeleteObject(brush);
SetTextColor(*sdraw, old_bk);
sdraw->EndGdi();
#elif defined(PLATFORM_X11)
XChangeGC(Xdisplay, sdraw->GetGC(), GCForeground | GCFunction, &gcv_old);
#endif
PaintRectPart(draw, rc.left + mingap, rc.top, sz.cx - 2 * mingap, sz.cy);
}
else
{
int rem = sz.cx - whites * 2 * DRAG_STEP + DRAG_STEP;
int lrem = rem >> 1, rrem = (rem + 1) >> 1;
PaintRectPart(draw, rc.left, rc.top, lrem, sz.cy);
PaintRectPart(draw, rc.right - rrem, rc.top, rrem, sz.cy);
int i;
int start = rc.left + lrem - DRAG_STEP;
for(i = 1; i < whites; i++)
PaintRectPart(draw, start + 2 * DRAG_STEP * i, rc.top, DRAG_STEP, sz.cy);
#if defined(PLATFORM_WIN32)
SetTextColor(draw, cc2);
#elif defined(PLATFORM_X11)
gcv_new.foreground = GetXPixel(c2) ^ GetXPixel(bgnd);
XChangeGC(Xdisplay, draw.GetGC(), GCForeground, &gcv_new);
#endif
start = rc.left + lrem;
for(i = 0; i < whites; i++)
PaintRectPart(draw, start + 2 * DRAG_STEP * i, rc.top, DRAG_STEP, sz.cy);
}
#if defined(PLATFORM_WIN32)
SelectObject(draw, old_brush);
DeleteObject(brush);
SetTextColor(draw, old_bk);
draw.EndGdi();
#elif defined(PLATFORM_X11)
XChangeGC(Xdisplay, draw.GetGC(), GCForeground | GCFunction, &gcv_old);
#endif
}
void PaintDragVertLine(Draw& draw, const Rect& rc, Color c1, Color c2, Color bgnd, int mingap)
{
Size sz = rc.Size();
if(SystemDraw *sdraw = dynamic_cast<SystemDraw *>(&draw)) {
#if defined(PLATFORM_WIN32)
draw.BeginGdi();
static word bmp_bits[8];
HBITMAP hbmp = CreateBitmap(8, 8, 1, 1, bmp_bits);
HBRUSH brush = CreatePatternBrush(hbmp);
DeleteObject(hbmp);
COLORREF cc1 = (COLORREF)c1 ^ (COLORREF)bgnd, cc2 = (COLORREF)c2 ^ (COLORREF)bgnd;
COLORREF old_bk = SetTextColor(draw, cc1);
HGDIOBJ old_brush = SelectObject(draw, brush);
sdraw->BeginGdi();
static word bmp_bits[8];
HBITMAP hbmp = CreateBitmap(8, 8, 1, 1, bmp_bits);
HBRUSH brush = CreatePatternBrush(hbmp);
DeleteObject(hbmp);
COLORREF cc1 = (COLORREF)c1 ^ (COLORREF)bgnd, cc2 = (COLORREF)c2 ^ (COLORREF)bgnd;
COLORREF old_bk = SetTextColor(*sdraw, cc1);
HGDIOBJ old_brush = SelectObject(*sdraw, brush);
#elif defined(PLATFORM_X11)
XGCValues gcv_old, gcv_new;
XGetGCValues(Xdisplay, draw.GetGC(), GCForeground | GCFunction, &gcv_old);
gcv_new.function = X11_ROP2_XOR;
gcv_new.foreground = GetXPixel(c1) ^ GetXPixel(bgnd);
XChangeGC(Xdisplay, draw.GetGC(), GCForeground | GCFunction, &gcv_new);
XGCValues gcv_old, gcv_new;
XGetGCValues(Xdisplay, sdraw->GetGC(), GCForeground | GCFunction, &gcv_old);
gcv_new.function = X11_ROP2_XOR;
gcv_new.foreground = GetXPixel(c1) ^ GetXPixel(bgnd);
XChangeGC(Xdisplay, sdraw->GetGC(), GCForeground | GCFunction, &gcv_new);
#endif
int whites = (sz.cy - 2 * mingap + DRAG_STEP) / (2 * DRAG_STEP);
if(rc.Height() <= 2 * mingap)
PaintRectPart(draw, rc);
else if(whites <= 0)
{
PaintRectPart(draw, rc.left, rc.top, sz.cx, mingap);
PaintRectPart(draw, rc.left, rc.bottom - mingap, sz.cx, mingap);
int whites = (sz.cy - 2 * mingap + DRAG_STEP) / (2 * DRAG_STEP);
if(rc.Height() <= 2 * mingap)
PaintRectPart(*sdraw, rc);
else if(whites <= 0)
{
PaintRectPart(*sdraw, rc.left, rc.top, sz.cx, mingap);
PaintRectPart(*sdraw, rc.left, rc.bottom - mingap, sz.cx, mingap);
#if defined(PLATFORM_WIN32)
SetTextColor(draw, cc2);
SetTextColor(*sdraw, cc2);
#elif defined(PLATFORM_X11)
gcv_new.foreground = GetXPixel(c2) ^ GetXPixel(bgnd);
XChangeGC(Xdisplay, draw.GetGC(), GCForeground, &gcv_new);
gcv_new.foreground = GetXPixel(c2) ^ GetXPixel(bgnd);
XChangeGC(Xdisplay, sdraw->GetGC(), GCForeground, &gcv_new);
#endif
PaintRectPart(*sdraw, rc.left, rc.top + mingap, sz.cx, sz.cy - 2 * mingap);
}
else
{
int rem = sz.cy - whites * 2 * DRAG_STEP + DRAG_STEP;
int lrem = rem >> 1, rrem = (rem + 1) >> 1;
PaintRectPart(*sdraw, rc.left, rc.top, sz.cx, lrem);
PaintRectPart(*sdraw, rc.left, rc.bottom - rrem, sz.cx, rrem);
int i;
int start = rc.top + lrem - DRAG_STEP;
for(i = 1; i < whites; i++)
PaintRectPart(*sdraw, rc.left, start + 2 * DRAG_STEP * i, sz.cx, DRAG_STEP);
#if defined(PLATFORM_WIN32)
SetTextColor(*sdraw, cc2);
#elif defined(PLATFORM_X11)
gcv_new.foreground = GetXPixel(c2) ^ GetXPixel(bgnd);
XChangeGC(Xdisplay, sdraw->GetGC(), GCForeground, &gcv_new);
#endif
start = rc.left + lrem;
for(i = 0; i < whites; i++)
PaintRectPart(*sdraw, rc.left, start + 2 * DRAG_STEP * i, sz.cx, DRAG_STEP);
}
#if defined(PLATFORM_WIN32)
SelectObject(*sdraw, old_brush);
DeleteObject(brush);
SetTextColor(*sdraw, old_bk);
sdraw->EndGdi();
#elif defined(PLATFORM_X11)
XChangeGC(Xdisplay, sdraw->GetGC(), GCForeground | GCFunction, &gcv_old);
#endif
PaintRectPart(draw, rc.left, rc.top + mingap, sz.cx, sz.cy - 2 * mingap);
}
else
{
int rem = sz.cy - whites * 2 * DRAG_STEP + DRAG_STEP;
int lrem = rem >> 1, rrem = (rem + 1) >> 1;
PaintRectPart(draw, rc.left, rc.top, sz.cx, lrem);
PaintRectPart(draw, rc.left, rc.bottom - rrem, sz.cx, rrem);
int i;
int start = rc.top + lrem - DRAG_STEP;
for(i = 1; i < whites; i++)
PaintRectPart(draw, rc.left, start + 2 * DRAG_STEP * i, sz.cx, DRAG_STEP);
#if defined(PLATFORM_WIN32)
SetTextColor(draw, cc2);
#elif defined(PLATFORM_X11)
gcv_new.foreground = GetXPixel(c2) ^ GetXPixel(bgnd);
XChangeGC(Xdisplay, draw.GetGC(), GCForeground, &gcv_new);
#endif
start = rc.left + lrem;
for(i = 0; i < whites; i++)
PaintRectPart(draw, rc.left, start + 2 * DRAG_STEP * i, sz.cx, DRAG_STEP);
}
#if defined(PLATFORM_WIN32)
SelectObject(draw, old_brush);
DeleteObject(brush);
SetTextColor(draw, old_bk);
draw.EndGdi();
#elif defined(PLATFORM_X11)
XChangeGC(Xdisplay, draw.GetGC(), GCForeground | GCFunction, &gcv_old);
#endif
}
void PaintDragRect(Draw& draw, const Rect& rc, Color c1, Color c2, Color bgnd, int width)
@ -908,8 +915,7 @@ void PaintDragRect(Draw& draw, const Rect& rc, Color c1, Color c2, Color bgnd, i
PaintDragHorzLine(draw, rc, LtRed, White, SWhite, width);
else if(rc.Width() <= 2 * width)
PaintDragVertLine(draw, rc, LtRed, White, SWhite, width);
else
{
else {
PaintDragHorzLine(draw, Rect(rc.left, rc.top, rc.right, rc.top + width), LtRed, White, SWhite, width);
PaintDragHorzLine(draw, Rect(rc.left, rc.bottom - width, rc.right, rc.bottom), LtRed, White, SWhite, width);
PaintDragVertLine(draw, Rect(rc.left, rc.top + width, rc.left + width, rc.bottom - width), LtRed, White, SWhite, 0);
@ -1575,8 +1581,7 @@ void AreaTool::Paint()
{
if(!plotter.draw)
return;
if(!(plotter.clip && plotter.draw->GetClip()))
{
if(!(plotter.clip.Intersects(plotter.draw->GetPageSize /*GetClip*/()))) {
Clear();
return;
}

View file

@ -1,10 +1,9 @@
description "Experimental (sometimes obsolete) painting code";
description "Experimental (sometimes obsolete) painting code\377";
uses
Draw,
Geom,
TCore,
PdfDraw;
TCore;
library(WIN32) comdlg32;

View file

@ -2,7 +2,7 @@
#pragma hdrstop
#ifdef PLATFORM_WIN32
#include <PdfDraw/PdfDraw.h>
//#include <PdfDraw/PdfDraw.h>
#include <commdlg.h>
#else
@ -888,7 +888,7 @@ void DrawPolyPolyPolygon(Draw& draw, const Point *vertices, int vertex_count,
if(vertex_count == 0)
return;
#ifdef PLATFORM_WIN32
#ifdef PLATFORM_WIN32_ //!!TODO
if(PdfDraw *pdf = dynamic_cast<PdfDraw *>(&draw)) {
pdf->DrawPolyPolyPolygon(vertices, vertex_count, subpolygon_counts, subpolygon_count_count,
disjunct_polygon_counts, disjunct_polygon_count_count, color, width, outline, pattern, doxor);

View file

@ -3,7 +3,7 @@ NAMESPACE_UPP
static const int DOTS_PER_METER_INT = 23622;
static const double DOTS_PER_METER_DBL = 600e3 / 25.4;
Draw& ScreenInfo();
SystemDraw& ScreenInfo();
Size GetPixelsPerMeter(const Draw& draw);
int GetHorzPixelsPerMeter(const Draw& draw);