public void blitSubrect(int sx, int sy, int sw, int sh, int dx, int dy, Softimage src, Softimage dest) { Rectangle oldclip = dest.clip; dest.setClip(dx, dy, sw, sh); blit(dx - sx, dy - sy, src, dest); dest.clip = oldclip; }
public unsafe void blit(int x, int y, Softimage src, Softimage dest) { int xlen, ylen, s, d, spitch, dpitch; if(CLIP2(src, dest, ref x, ref y, out xlen, out ylen, out s, out d, out spitch, out dpitch)) return; int luc = intlucent; if(luc != 0) { for(; ylen > 0; ylen--) for(x = 0; x < xlen; x++) dest.data[d++] = mixLucent(src.data[s++], dest.data[d], luc); s += spitch; d += dpitch; } else { xlen *= 4; while(ylen-- > 0) { pr2.Common.Lib.memcpy(dest.data+d, src.data+s, xlen); s += spitch; d += dpitch; } } }
public LockCache(Image img, Rectangle rect, bool rdonly) { this.rdonly = rdonly; this.rect = rect; this.img = img; //tex = img.tex_cache; tex = img.GetTex(); //mbg 2/24/07 - changed this. not sure whether it makes sense buf = new int[rect.Width * rect.Height]; //tex.GetData(buf); tex.GetData(0, rect, buf, 0, buf.Length); gchandle = GCHandle.Alloc(buf, GCHandleType.Pinned); data = (int*)gchandle.AddrOfPinnedObject().ToPointer(); //todo -- cant softimage use a pointer? pretty please? Softimage = new Softimage(buf, img.width, img.width, img.height); }
public unsafe void loadSoftimage(Softimage si) { if (tex_const != null) throw new Exception("Cannot loadSoftimage on a constant texture"); invalidate_tex_rt(); allocCache(); int[] buf = new int[width * height]; fixed (int* pbuf = buf) si.dump(pbuf); tex_cache.SetData(buf); }
/// <summary> /// source data must be no pitch linear /// </summary> public unsafe Softimage imageFrom24bpp(int w, int h, byte[] data) { Softimage img = new Softimage(w,h); int* idptr = img.data; byte* dptr = (byte*)idptr; fixed(byte* csptr = data) { byte* sptr = csptr; for(int y = 0; y < h; y++) { for(int x = 0; x < w; x++) { #if XBOX360 *dptr++ = 255; *dptr++ = sptr[2]; *dptr++ = sptr[1]; *dptr++ = sptr[0]; sptr += 3; #else *dptr++ = sptr[0]; *dptr++ = sptr[1]; *dptr++ = sptr[2]; *dptr++ = 255; sptr += 3; #endif } dptr = dptr + (img.w - img.p) * 4; } } return img; }
public System.Drawing.Bitmap ToSystemDrawingBitmap() { System.Drawing.Bitmap ret = new System.Drawing.Bitmap(Width, Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb); System.Drawing.Imaging.BitmapData bmpdata = ret.LockBits(new System.Drawing.Rectangle(0, 0, Width, Height), System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb); Softimage dest = new Softimage(bmpdata.Scan0, Width, bmpdata.Stride, Height); dump(dest.data); swapBytes(dest.data); ret.UnlockBits(bmpdata); return ret; }
public Softimage(System.Drawing.Bitmap bmp) { p = w = bmp.Width; h = bmp.Height; alloc(); System.Drawing.Imaging.BitmapData bmpdata = bmp.LockBits(new System.Drawing.Rectangle(0, 0, Width, Height), System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb); Softimage src = new Softimage(bmpdata.Scan0, Width, bmpdata.Stride/4, Height); src.dump(data); bmp.UnlockBits(bmpdata); }
/// <summary> /// clones a softimage /// </summary> Softimage(Softimage source) { p = w = source.w; h = source.h; alloc(); source.dump(data); initClip(); }
bool CLIP2(Softimage src, Softimage dest, ref int x, ref int y, out int xlen, out int ylen, out int s, out int d, out int spitch, out int dpitch) { xlen=src.w; ylen=src.h; s = 0; d = 0; spitch = src.p; dpitch = dest.p; if(clip2(ref x, ref y, ref xlen, ref ylen, ref s, ref d, spitch, dpitch, dest.cx, dest.cy, dest.cx1, dest.cy1)) return true; else return false; }
//----------depth buffer management---------- /// <summary> /// please do not dispose the depth buffer. /// </summary> //public DepthStencilBuffer GetDepthBuffer(int width, int height, DepthFormat format) { // if(width > depthBuffer_width || height > depthBuffer_height || _depthBuffer == null) { // if(_depthBuffer != null) _depthBuffer.Dispose(); // _depthBuffer = new DepthStencilBuffer(Device, width, height, format); // } // return _depthBuffer; //} //DepthStencilBuffer _depthBuffer; //int depthBuffer_width = 0, depthBuffer_height = 0; //public DepthStencilBuffer GetCurrentDepthBuffer() { return Device.DepthStencilBuffer; } ///// <summary> ///// creates and activates a depth buffer of the given width and height ///// </summary> //public void SetDepthBuffer(int width, int height, DepthFormat format) { // Device.DepthStencilBuffer = GetDepthBuffer(width, height, format); //} ///// <summary> ///// creates and activates a depth buffer to match the current screen ///// </summary> //public void SetDepthBuffer(DepthFormat format) { // SetDepthBuffer(screen.Width, screen.Height, format); //} //public void RemoveDepthBuffer() { // Device.DepthStencilBuffer = null; //} //---------- //misc.. /// <summary> /// returns null if there is no image. be sure to dispose! /// </summary> public Image GetImageFromClipboard() { System.Drawing.Image img = System.Windows.Forms.Clipboard.GetImage(); if(img == null) return null; Image ret = NewImage(img.Width, img.Height); using(System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(img)) using(Softimage si = new Softimage(bmp)) { ret.loadSoftimage(si); } return ret; }
public Image LoadSoftimage(Softimage si) { Image img = new Image(Device, si.Width, si.Height); img.loadSoftimage(si); return img; }