diff options
author | Jens Ole Wund <bjornmose@gmx.net> | 2005-09-10 02:31:23 +0400 |
---|---|---|
committer | Jens Ole Wund <bjornmose@gmx.net> | 2005-09-10 02:31:23 +0400 |
commit | 42ee04702c61f84b2180c89956aeb017fc315c4e (patch) | |
tree | fcd655900db28d62151f5f9042d200ba432c8738 /source/blender/img/intern | |
parent | 9d2f0fe302f977bf4671d7113aaeb8b5f4b02028 (diff) |
having a "mini gimp" in image editor
{ hope it does not break builds .. mscv6 .. scons works fine here }
Diffstat (limited to 'source/blender/img/intern')
-rw-r--r-- | source/blender/img/intern/IMG_Api.cpp | 48 | ||||
-rw-r--r-- | source/blender/img/intern/IMG_CanvasRGBA32.cpp | 259 | ||||
-rw-r--r-- | source/blender/img/intern/IMG_CanvasRGBA32.h | 10 | ||||
-rw-r--r-- | source/blender/img/intern/IMG_PixmapRGBA32.cpp | 68 | ||||
-rw-r--r-- | source/blender/img/intern/IMG_PixmapRGBA32.h | 5 |
5 files changed, 385 insertions, 5 deletions
diff --git a/source/blender/img/intern/IMG_Api.cpp b/source/blender/img/intern/IMG_Api.cpp index 95f7204c525..d0f49fc798b 100644 --- a/source/blender/img/intern/IMG_Api.cpp +++ b/source/blender/img/intern/IMG_Api.cpp @@ -59,6 +59,23 @@ void IMG_BrushDispose(IMG_BrushPtr brush) } } +void IMG_BrushSetInnerRaduisRatio(IMG_BrushPtr brush,float aspect) +{ + if (brush) { + TUns32 he = ((IMG_BrushRGBA32*)brush)->getHeight(); + TUns32 we = ((IMG_BrushRGBA32*)brush)->getWidth(); + TUns32 si = we; + if (he > si) si = we; + he = si/2; + we = (TUns32)(aspect*si/2); + if (we < 2) we = 2; + + + ((IMG_BrushRGBA32*)brush)->setRadii(we,he); + } +} + + IMG_CanvasPtr IMG_CanvasCreate(unsigned int w, unsigned int h) { @@ -121,3 +138,34 @@ void IMG_CanvasDrawLineUV(IMG_CanvasPtr canvas, IMG_BrushPtr brush, float uStart if (!(canvas && brush)) return; ((IMG_CanvasRGBA32*)canvas)->blendPixmap(uStart, vStart, uEnd, vEnd, *((IMG_BrushRGBA32*)brush)); } + +void IMG_CanvasDrawLineUVEX(IMG_CanvasPtr canvas, IMG_BrushPtr brush, float uStart, float vStart, float uEnd, float vEnd,char mode) +{ + if (!(canvas && brush)) return; + ((IMG_CanvasRGBA32*)canvas)->blendPixmap(uStart, vStart, uEnd, vEnd, *((IMG_BrushRGBA32*)brush),mode); +} + +void IMG_CanvasSoftenAt(IMG_CanvasPtr canvas,float u, float v, unsigned int size,float alpha, float aspect,char mode) +{ + ((IMG_CanvasRGBA32*)canvas)->SoftenAt(u,v,(TUns32)size,alpha,aspect,mode); +} + +void IMG_CanvasFill(IMG_CanvasPtr canvas,float red, float green, float blue, float alpha) +{ + IMG_ColorRGB c (red, green, blue); + IMG_Rect R (0, 0, ((IMG_CanvasRGBA32*)canvas)->getWidth(), + ((IMG_CanvasRGBA32*)canvas)->getHeight()); // Bounds of this pixmap + ((IMG_CanvasRGBA32*)canvas)->fillRect(R,c); +} + +void IMG_CanvasSmear(IMG_CanvasPtr canvas,float uStart, float vStart, float uEnd, float vEnd, unsigned int size, float alpha, float aspect,char mode) +{ + ((IMG_CanvasRGBA32*)canvas)->Smear(uStart,vStart,uEnd,vEnd,size,alpha,aspect,mode); + +} + +void IMG_CanvasCloneAt(IMG_CanvasPtr canvas,IMG_CanvasPtr other,float u,float v,float cu,float cv,int size,float alpha,float aspect) +{ + ((IMG_CanvasRGBA32*)canvas)->CloneAt((IMG_CanvasRGBA32*)other, u, v, cu, cv, size, alpha, aspect); +} + diff --git a/source/blender/img/intern/IMG_CanvasRGBA32.cpp b/source/blender/img/intern/IMG_CanvasRGBA32.cpp index 2fd5e276298..72e4aaf8fd1 100644 --- a/source/blender/img/intern/IMG_CanvasRGBA32.cpp +++ b/source/blender/img/intern/IMG_CanvasRGBA32.cpp @@ -48,16 +48,18 @@ IMG_CanvasRGBA32::IMG_CanvasRGBA32(void* image, TUns32 width, TUns32 height, TUn void IMG_CanvasRGBA32::blendPixmap( TUns32 xStart, TUns32 yStart, TUns32 xEnd, TUns32 yEnd, - const IMG_PixmapRGBA32& pixmap) + const IMG_PixmapRGBA32& pixmap,char mode) { // Determine visibility of the line IMG_Line l (xStart, yStart, xEnd, yEnd); // Line used for blending IMG_Rect bnds (0, 0, m_width, m_height); // Bounds of this pixmap TVisibility v = bnds.getVisibility(l); + if (mode == 'c'){ if (v == kNotVisible) return; if (v == kPartiallyVisible) { bnds.clip(l); } + } float numSteps = (((float)l.getLength()) / ((float)pixmap.getWidth() / 4)); //numSteps *= 4; @@ -66,7 +68,12 @@ void IMG_CanvasRGBA32::blendPixmap( TInt32 x, y; for (TUns32 s = 0; s < numSteps; s++) { l.getPoint(step, x, y); + if (mode == 'c') { IMG_PixmapRGBA32::blendPixmap((TUns32)x, (TUns32)y, pixmap); + } + else { + if (mode == 't') IMG_PixmapRGBA32::blendPixmapTorus((TUns32)x, (TUns32)y, pixmap); + } step += stepSize; } } @@ -74,11 +81,257 @@ void IMG_CanvasRGBA32::blendPixmap( void IMG_CanvasRGBA32::blendPixmap( float uStart, float vStart, float uEnd, float vEnd, - const IMG_PixmapRGBA32& pixmap) + const IMG_PixmapRGBA32& pixmap, char mode) { TUns32 xStart, yStart, xEnd, yEnd; getPixelAddress(uStart, vStart, xStart, yStart); getPixelAddress(uEnd, vEnd, xEnd, yEnd); - blendPixmap(xStart, yStart, xEnd, yEnd, pixmap); + blendPixmap(xStart, yStart, xEnd, yEnd, pixmap,mode); } + +void IMG_CanvasRGBA32::SoftenAt(float u, float v, TUns32 size, float alpha, float aspect,char mode) +{ + IMG_BrushRGBA32* brush = 0; + int flag=0; + try { + IMG_ColorRGB c (1.0, 1.0, 1.0); + brush = new IMG_BrushRGBA32 (size, size, c, alpha); + } + catch (...) { + /* no brush , no fun ! */ + return; + } + + TUns32 ro,ri; + ro = size/2; + ri = (int)(aspect/2.0f * size); + if (ri > 2 ) ri =2; + if (ri > ro ) ri =ro; + brush->setRadii(ri,ro); + + + TUns32 x, y; + TUns32 xx, yy; + getPixelAddress(u, v, x, y); + xx = x - size/2; + yy = y - size/2; + if(mode == 't') flag = 1; + + /* now modify brush */ + for (int i= 0 ; i<(int)size;i++){ + for (int j= 0 ; j<(int)size;j++){ + + float sR,sG,sB,sA; + float cR,cG,cB=0.0; + +if(mode == 't') + IMG_PixmapRGBA32::getRGBAatTorus(xx+i,yy+j ,&cR,&cG,&cB,0); + +else + IMG_PixmapRGBA32::getRGBAat(xx+i,yy+j ,&cR,&cG,&cB,0); + int ccount = 1; + /* + cR += 7.0*cR; + cG += 7.0*cG; + cB += 7.0*cB; + ccount += 7.0; + */ + +add_if_in(xx+i+1,yy+j+1,cR,cG,cB,ccount,flag); +add_if_in(xx+i+1,yy+j ,cR,cG,cB,ccount,flag); +add_if_in(xx+i+1,yy+j-1,cR,cG,cB,ccount,flag); + +add_if_in(xx+i,yy+j+1,cR,cG,cB,ccount,flag); +add_if_in(xx+i,yy+j-1,cR,cG,cB,ccount,flag); + +add_if_in(xx+i-1,yy+j+1,cR,cG,cB,ccount,flag); +add_if_in(xx+i-1,yy+j ,cR,cG,cB,ccount,flag); +add_if_in(xx+i-1,yy+j-1,cR,cG,cB,ccount,flag); + + + sR =cR*255.0f/ccount; + sG =cG*255.0f/ccount; + sB =cB*255.0f/ccount; + + sA =255.0; + brush->setRGBAat(i,j,&sR,&sG,&sB,NULL); + } + } + + /* apply */ +if(mode == 't') + IMG_PixmapRGBA32::blendPixmapTorus(x, y, *brush); +else + IMG_PixmapRGBA32::blendPixmap(x, y, *brush); + /* done clean up */ + if (brush) { + delete ((IMG_BrushRGBA32*)brush); + brush = 0; + } +} + + +IMG_BrushRGBA32* IMG_CanvasRGBA32::LiftBrush(TUns32 x, TUns32 y, TUns32 size, float alpha, float aspect, short flags ) +{ + IMG_BrushRGBA32* brush = 0; + float mR,mG,mB=0.0; + try { + IMG_ColorRGB c (1.0, 1.0, 1.0); + brush = new IMG_BrushRGBA32 (size, size, c, alpha); + } + catch (...) { + /* no brush , no fun ! */ + return(NULL); + } + + TUns32 ro,ri; + ro = size/2; + ri = (int)(aspect/2.0f * size); + if (ri > 2 ) ri =2; + if (ri > ro ) ri =ro; + brush->setRadii(ri,ro); + + + TUns32 xx, yy; + xx = x - size/2; + yy = y - size/2; + IMG_PixmapRGBA32::getRGBAat(xx,yy,&mR,&mG,&mB,0); + for (int i= 0 ; i<(int)size;i++){ + for (int j= 0 ; j<(int)size;j++){ + float cR,cG,cB,cA=0.0; + cR = mR; cG = mG; cB = mB; + int res =IMG_PixmapRGBA32::getRGBAat(xx+i,yy+j ,&cR,&cG,&cB,0); + cR *= 255.0f; + cG *= 255.0f; + cB *= 255.0f; + cA *= 0.0; + if (res) + brush->setRGBAat(i,j,&cR,&cG,&cB,NULL); + else + brush->setRGBAat(i,j,&cR,&cG,&cB,&cA); + + } + } + return(brush); +} + +IMG_BrushRGBA32* IMG_CanvasRGBA32::LiftBrush(float u, float v, TUns32 size, float alpha, float aspect, short flags ) +{ + IMG_BrushRGBA32* brush = 0; + float mR,mG,mB=0.0; + try { + IMG_ColorRGB c (1.0, 1.0, 1.0); + brush = new IMG_BrushRGBA32 (size, size, c, alpha); + } + catch (...) { + /* no brush , no fun ! */ + return(NULL); + } + + TUns32 ro,ri; + ro = size/2; + ri = (int)(aspect/2.0f * size); + if (ri > 2 ) ri =2; + if (ri > ro ) ri =ro; + brush->setRadii(ri,ro); + + + TUns32 x, y; + TUns32 xx, yy; + getPixelAddress(u, v, x, y); + xx = x - size/2; + yy = y - size/2; + IMG_PixmapRGBA32::getRGBAat(xx,yy,&mR,&mG,&mB,0); + for (int i= 0 ; i<(int)size;i++){ + for (int j= 0 ; j<(int)size;j++){ + float cR,cG,cB=0.0; + if (flags & 0x1) + IMG_PixmapRGBA32::getRGBAatTorus(xx+i,yy+j ,&cR,&cG,&cB,0); + else { + cR = mR; cG = mG; cB = mB; + IMG_PixmapRGBA32::getRGBAat(xx+i,yy+j ,&cR,&cG,&cB,0); + } + cR *= 255.0f; + cG *= 255.0f; + cB *= 255.0f; + brush->setRGBAat(i,j,&cR,&cG,&cB,NULL); + } + } + return(brush); +} + +void IMG_CanvasRGBA32::Smear(float uStart, float vStart, float uEnd, float vEnd, TUns32 size, float alpha, float aspect,char mode) +{ + IMG_BrushRGBA32* brush = NULL; + float du,dv; + du = uEnd - uStart; + dv = vEnd - vStart; + try { + brush = LiftBrush(uStart-du,vStart-dv,size,alpha,aspect,1); + } + catch (...) { + /* no brush , no fun ! */ + return; + } + if (brush){ + blendPixmap(uStart,vStart,uEnd,vEnd,*brush,mode); + delete(brush); + } + +} + +void IMG_CanvasRGBA32::CloneAt(IMG_CanvasRGBA32* other,float u,float v,float cu,float cv,TUns32 size,float alpha,float aspect) +{ + TUns32 x, y; + TUns32 cx, cy; + TUns32 xx, yy; + getPixelAddress(u, v, x, y); + getPixelAddress(cu, cv, cx, cy); + + xx = (x-cx);// - size/2; + yy = (y-cy);// - size/2; + + if (other == NULL) return; + IMG_BrushRGBA32* brush = NULL; + try { + brush = other->LiftBrush(xx,yy,size,alpha,aspect,1); + } + catch (...) { + /* no brush , no fun ! */ + return; + } + if (brush){ + IMG_PixmapRGBA32::blendPixmap(x, y, *brush); + delete(brush); + } + +} + + + +int IMG_CanvasRGBA32::add_if_in(int x, int y,float &R,float &G,float &B, int &count, short flags) + +{ + float r,g,b= 0.0f; + if ((flags & 0x1) == 0) + { + if (IMG_PixmapRGBA32::getRGBAat(x,y,&r,&g,&b,0)) + { + R += r; + G += g; + B += b; + count++; + } +} + else { + + IMG_PixmapRGBA32::getRGBAatTorus(x,y,&r,&g,&b,0); + R += r; + G += g; + B += b; + count++; + } + + return 1; +} diff --git a/source/blender/img/intern/IMG_CanvasRGBA32.h b/source/blender/img/intern/IMG_CanvasRGBA32.h index fb201202fc1..e7eaaa86280 100644 --- a/source/blender/img/intern/IMG_CanvasRGBA32.h +++ b/source/blender/img/intern/IMG_CanvasRGBA32.h @@ -46,6 +46,12 @@ class IMG_CanvasRGBA32 : public IMG_PixmapRGBA32 { public: + int add_if_in(int x, int y,float &R,float &G,float &B, int &count, short flags); + void Smear(float uStart, float vStart, float uEnd, float vEnd ,TUns32 size, float alpha, float aspect,char mode); + IMG_BrushRGBA32* LiftBrush(float u, float v, TUns32 size, float alpha, float aspect, short flags ); + IMG_BrushRGBA32* LiftBrush(TUns32 x, TUns32 y, TUns32 size, float alpha, float aspect, short flags); + void SoftenAt(float u,float v,TUns32 size,float alpha,float aspect,char mode); + void CloneAt(IMG_CanvasRGBA32* other,float u,float v,float cu,float cv,TUns32 size,float alpha,float aspect); /** * Constructor. * @throw <IMG_MemPtr::Size> when an invalid width and/or height is passed. @@ -76,7 +82,7 @@ public: * @param y y-coordinate of the center location of the image. * @param pixmap the pixmap to blend */ - virtual void blendPixmap(TUns32 xStart, TUns32 yStart, TUns32 xEnd, TUns32 yEnd, const IMG_PixmapRGBA32& pixmap); + virtual void blendPixmap(TUns32 xStart, TUns32 yStart, TUns32 xEnd, TUns32 yEnd, const IMG_PixmapRGBA32& pixmap,char mode = 'c'); /** * Blends a pixmap into this pixmap over a line in (u,v) coordinates. @@ -88,7 +94,7 @@ public: * @param v v-coordinate of the center location of the image. * @param pixmap the pixmap to blend */ - virtual void blendPixmap(float uStart, float vStart, float uEnd, float vEnd, const IMG_PixmapRGBA32& pixmap); + virtual void blendPixmap(float uStart, float vStart, float uEnd, float vEnd, const IMG_PixmapRGBA32& pixmap,char mode = 'c'); }; diff --git a/source/blender/img/intern/IMG_PixmapRGBA32.cpp b/source/blender/img/intern/IMG_PixmapRGBA32.cpp index 5ff647cd8ab..49b9348a4be 100644 --- a/source/blender/img/intern/IMG_PixmapRGBA32.cpp +++ b/source/blender/img/intern/IMG_PixmapRGBA32.cpp @@ -262,3 +262,71 @@ void IMG_PixmapRGBA32::blendPixmap(float u, float v, const IMG_PixmapRGBA32& pix getPixelAddress(u, v, x, y); blendPixmap(x, y, pixmap); } + +int IMG_PixmapRGBA32::getRGBAat(TUns32 x, TUns32 y, float *R, float *G, float *B, float *A) const +{ + TPixelPtr srcPtr = 0; + if ((x >= m_width) || (y >= m_height) ) return 0; + srcPtr = getPixelPtr(x,y); + if (srcPtr){ + IMG_ColorRGBA srcColor; + getColor(*srcPtr, srcColor); + if(R) *R = srcColor.m_r; + if(G) *G = srcColor.m_g; + if(B) *B = srcColor.m_b; + if(A) *A = srcColor.m_a; + return 1; + } + return 0; + +} + +int IMG_PixmapRGBA32::getRGBAatTorus(int x, int y, float *R, float *G, float *B, float *A) +{ + x %= m_width; + y %= m_height; + return getRGBAat(x,y,R,G,B,A); +} + +void IMG_PixmapRGBA32::setRGBAat(TUns32 x, TUns32 y, float *R, float *G, float *B, float *A) +{ + TPixelPtr desPtr = 0; + desPtr = getPixelPtr(x,y); + if (desPtr){ + if(R) ((TUns8*)desPtr)[bi_r] = (TUns8)(*R); + if(G) ((TUns8*)desPtr)[bi_g] = (TUns8)(*G); + if(B) ((TUns8*)desPtr)[bi_b] = (TUns8)(*B); + if(A) ((TUns8*)desPtr)[bi_a] = (TUns8)(*A); + + + } + +} + +void IMG_PixmapRGBA32::blendPixmapTorus(TUns32 x, TUns32 y,const IMG_PixmapRGBA32 &pixmap) +{ + float sR,sG,sB,sA, bR,bG,bB,bA; + IMG_Rect bnds; + pixmap.getBounds(bnds); + int ym = bnds.getHeight(); + int xm = bnds.getWidth(); + for (int xa = 0; xa < xm; xa ++) + for (int ya = 0; ya < ym; ya ++){ + int xt = (xa-xm/2 + x) % (m_width ); + int yt = (ya-xm/2 + y) % (m_height); + + getRGBAat(xt,yt,&sR,&sG,&sB,&sA); + + pixmap.getRGBAat(xa,ya,&bR,&bG,&bB,&bA); + + sR = sR*(1-bA) + bR*bA; + sG = sG*(1-bA) + bG*bA; + sB = sB*(1-bA) + bB*bA; + + sR *= 255.0f; + sG *= 255.0f; + sB *= 255.0f; + + setRGBAat(xt,yt,&sR,&sG,&sB,0); + } +} diff --git a/source/blender/img/intern/IMG_PixmapRGBA32.h b/source/blender/img/intern/IMG_PixmapRGBA32.h index 71941737132..0c9352c260f 100644 --- a/source/blender/img/intern/IMG_PixmapRGBA32.h +++ b/source/blender/img/intern/IMG_PixmapRGBA32.h @@ -49,6 +49,11 @@ class IMG_PixmapRGBA32 : public IMG_Pixmap { public: + virtual void blendPixmapTorus(TUns32 x, TUns32 y,const IMG_PixmapRGBA32& pixmap); + void setRGBAat(TUns32 x, TUns32 y, float* R, float* G, float* B,float* A); + int getRGBAat(TUns32 x, TUns32 y, float* R, float* G, float* B,float* A) const; + int getRGBAatTorus(int x, int y, float *R, float *G, float *B, float *A); + /** * The pixel type in this pixmap. */ |