Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorWade Brainerd <wadetb@gmail.com>2008-05-19 02:18:50 (GMT)
committer Wade Brainerd <wadetb@gmail.com>2008-05-19 02:18:50 (GMT)
commitb60bfd619cebda212385c397e9aad00e382a6a27 (patch)
treed031346bf060dc39ef91e119cb973b7126bbc3e1 /src
parent5822328cab1162b32452dfb915b33d98307b55d1 (diff)
WIP on scrolling. Don't get!
Diffstat (limited to 'src')
-rw-r--r--src/canvas.h146
-rw-r--r--src/colorsc_wrap.cxx32
2 files changed, 113 insertions, 65 deletions
diff --git a/src/canvas.h b/src/canvas.h
index 8556d54..e221b39 100644
--- a/src/canvas.h
+++ b/src/canvas.h
@@ -426,10 +426,14 @@ public:
alpha = new unsigned char[width*height];
image_shared = new unsigned int[width*height];
+
image_reference = new unsigned short[REFERENCE_WIDTH*REFERENCE_HEIGHT];
+ memset(image_reference, 0, REFERENCE_WIDTH*REFERENCE_HEIGHT*sizeof(unsigned short));
image_video[0] = new unsigned int[VIDEO_WIDTH*VIDEO_HEIGHT];
image_video[1] = new unsigned int[VIDEO_WIDTH*VIDEO_HEIGHT];
+ memset(image_video[0], 0, VIDEO_WIDTH*VIDEO_HEIGHT*sizeof(unsigned int));
+ memset(image_video[1], 0, VIDEO_WIDTH*VIDEO_HEIGHT*sizeof(unsigned int));
video_idx = 0;
clear();
@@ -480,10 +484,10 @@ public:
clear_image();
}
- // Changes the size of the canvas.
- // Rather than trying to repaint everything from scratch, we simply quickly rescale it.
- void resize(int new_width, int new_height)
- {
+ // Changes the size of the canvas.
+ // Rather than trying to repaint everything from scratch, we simply quickly rescale it.
+ void resize(int new_width, int new_height)
+ {
unsigned int* new_image = new unsigned int[new_width*new_height];
unsigned int* new_image_backup = new unsigned int[new_width*new_height];
unsigned char* new_alpha = new unsigned char[new_width*new_height];
@@ -497,31 +501,31 @@ public:
int rx = 0;
for (int x = 0; x < new_width; x++)
{
- int sofs = (ry>>16)*width + (rx>>16);
- int dofs = y*new_width+x;
- new_image[dofs] = image[sofs];
- new_image_backup[dofs] = image_backup[sofs];
- new_alpha[dofs] = alpha[sofs];
- new_image_shared[dofs] = image_shared[sofs];
- rx += dx;
+ int sofs = (ry>>16)*width + (rx>>16);
+ int dofs = y*new_width+x;
+ new_image[dofs] = image[sofs];
+ new_image_backup[dofs] = image_backup[sofs];
+ new_alpha[dofs] = alpha[sofs];
+ new_image_shared[dofs] = image_shared[sofs];
+ rx += dx;
}
- ry += dy;
- }
-
- delete[] image;
- delete[] image_backup;
- delete[] alpha;
- delete[] image_shared;
-
- width = new_width;
- height = new_height;
-
- image = new_image;
- image_backup = new_image_backup;
- alpha = new_alpha;
- image_shared = new_image_shared;
+ ry += dy;
}
+
+ delete[] image;
+ delete[] image_backup;
+ delete[] alpha;
+ delete[] image_shared;
+
+ width = new_width;
+ height = new_height;
+ image = new_image;
+ image_backup = new_image_backup;
+ alpha = new_alpha;
+ image_shared = new_image_shared;
+ }
+
// Resets the brush to a random color and a default size and type.
void reset_brush()
{
@@ -578,10 +582,6 @@ public:
memset(image_shared, 0xff, width*height*sizeof(unsigned int));
- memset(image_reference, 0, REFERENCE_WIDTH*REFERENCE_HEIGHT*sizeof(unsigned short));
- memset(image_video[0], 0, VIDEO_WIDTH*VIDEO_HEIGHT*sizeof(unsigned short));
- memset(image_video[1], 0, VIDEO_WIDTH*VIDEO_HEIGHT*sizeof(unsigned short));
-
dirtymin = Pos(0, 0);
dirtymax = Pos(width, height);
}
@@ -1026,42 +1026,68 @@ public:
// Blit
//
// Draws a region of the canvas into a GdkImage for display on the screen, with optional scaling
- // and darkening.
+ // and darkening.
- void blit_2x(GdkImage* img, int x, int y, int w, int h, bool overlay)
+ void blit_2x(GdkImage* img, int x, int y, int w, int h, int scroll_x, int scroll_y, bool overlay)
{
- if (overlay)
+ unsigned short* pixels = (unsigned short*)img->mem;
+ int pitch = img->bpl/sizeof(unsigned short);
+
+ // Translate origin to output location.
+ unsigned short* dest_pixels = pixels + y*pitch+x;
+
+ int src_x = (x - scroll_x)/2;
+ int src_y = (y - scroll_y)/2;
+
+ if (src_x < 0) src_x = 0;
+
+ while (src_y < 0)
{
- unsigned short* pixels = (unsigned short*)img->mem;
- int pitch = img->bpl/sizeof(unsigned short);
+ unsigned short* __restrict row0 = dest_pixels;
+ unsigned short* __restrict row1 = dest_pixels + pitch;
+ dest_pixels += pitch*2;
+ for (int cx = 0; cx < w; cx++)
+ {
+ unsigned int rgb = 0;
+ row0[0] = rgb;
+ row0[1] = rgb;
+ row1[0] = rgb;
+ row1[1] = rgb;
+ row0 += 2;
+ row1 += 2;
+ }
+ src_y++;
+ h--;
+ }
- for (int cy = 0; cy < h; cy++)
+ unsigned int* src_pixels = &image[src_y*width+src_x];
+
+ for (int cy = 0; cy < h; cy++)
+ {
+ unsigned int* __restrict src = src_pixels;
+ unsigned short* __restrict row0 = dest_pixels;
+ unsigned short* __restrict row1 = dest_pixels + pitch;
+ src_pixels += width;
+ dest_pixels += pitch*2;
+ for (int cx = 0; cx < w; cx++)
{
- unsigned int* __restrict src = &image[(y+cy)*width+x];
- unsigned short* __restrict row0 = &pixels[((y+cy)*2+0)*pitch+x*2];
- unsigned short* __restrict row1 = &pixels[((y+cy)*2+1)*pitch+x*2];
- for (int cx = 0; cx < w; cx++)
- {
- unsigned int p = *src++;
- p &= ~0x03030303;
- p >>= 2;
- unsigned int r = (((p>>16)&0xff)>>3)<<11;
- unsigned int g = (((p>> 8)&0xff)>>2)<<5;
- unsigned int b = (((p>> 0)&0xff)>>3);
- unsigned int rgb = r|g|b;
- row0[0] = rgb;
- row0[1] = rgb;
- row1[0] = rgb;
- row1[1] = rgb;
- row0 += 2;
- row1 += 2;
- }
+ unsigned int p = *src++;
+ unsigned int r = (((p>>16)&0xff)>>3)<<11;
+ unsigned int g = (((p>> 8)&0xff)>>2)<<5;
+ unsigned int b = (((p>> 0)&0xff)>>3);
+ unsigned int rgb = r|g|b;
+ row0[0] = rgb;
+ row0[1] = rgb;
+ row1[0] = rgb;
+ row1[1] = rgb;
+ row0 += 2;
+ row1 += 2;
}
}
- else
+
+/*
+ if (overlay)
{
- unsigned short* pixels = (unsigned short*)img->mem;
- int pitch = img->bpl/sizeof(unsigned short);
for (int cy = 0; cy < h; cy++)
{
@@ -1071,6 +1097,8 @@ public:
for (int cx = 0; cx < w; cx++)
{
unsigned int p = *src++;
+ p &= ~0x03030303;
+ p >>= 2;
unsigned int r = (((p>>16)&0xff)>>3)<<11;
unsigned int g = (((p>> 8)&0xff)>>2)<<5;
unsigned int b = (((p>> 0)&0xff)>>3);
@@ -1084,6 +1112,8 @@ public:
}
}
}
+ else
+ */
}
//---------------------------------------------------------------------------------------------
diff --git a/src/colorsc_wrap.cxx b/src/colorsc_wrap.cxx
index daaefdb..6a3b4d2 100644
--- a/src/colorsc_wrap.cxx
+++ b/src/colorsc_wrap.cxx
@@ -9349,7 +9349,9 @@ SWIGINTERN PyObject *_wrap_Canvas_blit_2x(PyObject *SWIGUNUSEDPARM(self), PyObje
int arg4 ;
int arg5 ;
int arg6 ;
- bool arg7 ;
+ int arg7 ;
+ int arg8 ;
+ bool arg9 ;
void *argp1 = 0 ;
int res1 = 0 ;
int val3 ;
@@ -9360,8 +9362,12 @@ SWIGINTERN PyObject *_wrap_Canvas_blit_2x(PyObject *SWIGUNUSEDPARM(self), PyObje
int ecode5 = 0 ;
int val6 ;
int ecode6 = 0 ;
- bool val7 ;
+ int val7 ;
int ecode7 = 0 ;
+ int val8 ;
+ int ecode8 = 0 ;
+ bool val9 ;
+ int ecode9 = 0 ;
PyObject * obj0 = 0 ;
PyObject * obj1 = 0 ;
PyObject * obj2 = 0 ;
@@ -9369,8 +9375,10 @@ SWIGINTERN PyObject *_wrap_Canvas_blit_2x(PyObject *SWIGUNUSEDPARM(self), PyObje
PyObject * obj4 = 0 ;
PyObject * obj5 = 0 ;
PyObject * obj6 = 0 ;
+ PyObject * obj7 = 0 ;
+ PyObject * obj8 = 0 ;
- if (!PyArg_ParseTuple(args,(char *)"OOOOOOO:Canvas_blit_2x",&obj0,&obj1,&obj2,&obj3,&obj4,&obj5,&obj6)) SWIG_fail;
+ if (!PyArg_ParseTuple(args,(char *)"OOOOOOOOO:Canvas_blit_2x",&obj0,&obj1,&obj2,&obj3,&obj4,&obj5,&obj6,&obj7,&obj8)) SWIG_fail;
res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_Canvas, 0 | 0 );
if (!SWIG_IsOK(res1)) {
SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Canvas_blit_2x" "', argument " "1"" of type '" "Canvas *""'");
@@ -9402,12 +9410,22 @@ SWIGINTERN PyObject *_wrap_Canvas_blit_2x(PyObject *SWIGUNUSEDPARM(self), PyObje
SWIG_exception_fail(SWIG_ArgError(ecode6), "in method '" "Canvas_blit_2x" "', argument " "6"" of type '" "int""'");
}
arg6 = static_cast< int >(val6);
- ecode7 = SWIG_AsVal_bool(obj6, &val7);
+ ecode7 = SWIG_AsVal_int(obj6, &val7);
if (!SWIG_IsOK(ecode7)) {
- SWIG_exception_fail(SWIG_ArgError(ecode7), "in method '" "Canvas_blit_2x" "', argument " "7"" of type '" "bool""'");
+ SWIG_exception_fail(SWIG_ArgError(ecode7), "in method '" "Canvas_blit_2x" "', argument " "7"" of type '" "int""'");
}
- arg7 = static_cast< bool >(val7);
- (arg1)->blit_2x(arg2,arg3,arg4,arg5,arg6,arg7);
+ arg7 = static_cast< int >(val7);
+ ecode8 = SWIG_AsVal_int(obj7, &val8);
+ if (!SWIG_IsOK(ecode8)) {
+ SWIG_exception_fail(SWIG_ArgError(ecode8), "in method '" "Canvas_blit_2x" "', argument " "8"" of type '" "int""'");
+ }
+ arg8 = static_cast< int >(val8);
+ ecode9 = SWIG_AsVal_bool(obj8, &val9);
+ if (!SWIG_IsOK(ecode9)) {
+ SWIG_exception_fail(SWIG_ArgError(ecode9), "in method '" "Canvas_blit_2x" "', argument " "9"" of type '" "bool""'");
+ }
+ arg9 = static_cast< bool >(val9);
+ (arg1)->blit_2x(arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9);
resultobj = SWIG_Py_Void();
return resultobj;
fail: