public bool Equals(IPixelReference other) { if (null != (object)other) { return(Red == other.Red && Green == other.Green && Blue == other.Blue); } else { return(false); } }
/// <summary> /// /// </summary> /// <returns></returns> public PixelMap GetPixelMap() { if (_YMap == null) { return(null); } int area = _YMap.Width * _YMap.Height; int width = _YMap.Width; int height = _YMap.Height; int pixsep = 3; int rowsep = width * pixsep; sbyte[] bytes = new sbyte[height * rowsep]; _YMap.Image(0, bytes, rowsep, pixsep, false); if ((_CrMap != null) && (_CbMap != null) && (_CrCbDelay >= 0)) { _CbMap.Image(1, bytes, rowsep, pixsep, _CrCbHalf); _CrMap.Image(2, bytes, rowsep, pixsep, _CrCbHalf); } // Convert image to RGB PixelMap pixelMap = new PixelMap().Init(bytes, height, width); if ((_CrMap != null) && (_CbMap != null) && (_CrCbDelay >= 0)) { unsafe { fixed(sbyte *pBuffer = bytes) { Pixel *pPix = (Pixel *)pBuffer; InterWaveTransform.YCbCr2Rgb(pPix, width, height); } } } else { IPixelReference pixel = pixelMap.CreateGPixelReference(0); for (int x = width * height; x-- > 0; pixel.IncOffset()) { pixel.SetGray((sbyte)(127 - pixel.Blue)); } } return(pixelMap); }
public IPixelMap GetPixelMap(int subsample, Rectangle rect, IPixelMap retval) { if (_YMap == null) { return(null); } if (retval == null) { retval = new PixelMap(); } int width = rect.Width; int height = rect.Height; int pixsep = 3; int rowsep = width * pixsep; sbyte[] bytes = retval.Init(height, width, null).Data; _YMap.Image(subsample, rect, 0, bytes, rowsep, pixsep, false); if ((_CrMap != null) && (_CbMap != null) && (_CrCbDelay >= 0)) { _CbMap.Image(subsample, rect, 1, bytes, rowsep, pixsep, _CrCbHalf); _CrMap.Image(subsample, rect, 2, bytes, rowsep, pixsep, _CrCbHalf); } if ((_CrMap != null) && (_CbMap != null) && (_CrCbDelay >= 0)) { unsafe { fixed(sbyte *pBuffer = bytes) { Pixel *pPix = (Pixel *)pBuffer; InterWaveTransform.YCbCr2Rgb(pPix, width, height); } } } else { IPixelReference pixel = retval.CreateGPixelReference(0); for (int x = width * height; x-- > 0; pixel.IncOffset()) { pixel.SetGray((sbyte)(127 - pixel.Blue)); } } return(retval); }
public void EqualsIPixelReference() { int width = 16; int height = 16; Pixel color = Pixel.BluePixel; IPixelMap map1 = PixelMapTests.CreateInitVerifyPixelMap(width, height, color); IPixelMap map2 = PixelMapTests.CreateInitVerifyPixelMap(width, height, color); IPixelMap map3 = PixelMapTests.CreateInitVerifyPixelMap(width, height, Pixel.BlackPixel); IPixelReference pix1 = map1.CreateGPixelReference(0); IPixelReference pix2 = map2.CreateGPixelReference(0); IPixelReference pix3 = map3.CreateGPixelReference(0); Assert.True(pix1.Equals(pix2)); Assert.False(pix1.Equals(pix3)); Assert.False(pix1.Equals((IPixelReference)null)); }
/// <summary> /// Copy pixel values from source. /// </summary> /// <param name="ref"> /// Source /// </param> public void SetPixels(IPixelReference source, int length) { if (source.ColorNumber != _ncolors || source.BlueOffset != _blueOffset || source.GreenOffset != _greenOffset || source.RedOffset != _redOffset) { while (length-- > 0) { CopyFrom(source); source.IncOffset(); IncOffset(); } } else { Array.Copy(source.Parent.Data, source.Offset, _parent.Data, _offset, length * _ncolors); source.IncOffset(length); IncOffset(length); } }
public void FillTest002() { int width = 16; int height = 16; int border = 4; sbyte color1 = 0; sbyte color2 = -1; var bmp1 = CreateIntiFillVerifyBitmap(width, height, border, color1); var bmp2 = CreateIntiFillVerifyBitmap(width, height, border, color2); bmp1.Fill(bmp2, 4, 4); IPixelReference pix1 = bmp1.CreateGPixelReference(0); pix1.SetOffset(5, 5); Assert.Equal(color2, pix1.ToPixel().Blue); pix1.SetOffset(3, 5); Assert.Equal(color1, pix1.ToPixel().Blue); }
public void Scale(Rectangle srcRect, IPixelMap srcMap, Rectangle targetRect, IPixelMap targetMap) { // Parameter validation if ((srcRect.Width != srcMap.Width) || (srcRect.Height != srcMap.Height)) { throw new DjvuArgumentException("Invalid rectangle", nameof(srcRect)); } // Compute rectangles Rectangle required_red = new Rectangle(); Rectangle sourceRect = CreateRectangles(targetRect, required_red); if ((srcRect.XMin > sourceRect.XMin) || (srcRect.YMin > sourceRect.YMin) || (srcRect.XMax < sourceRect.XMax) || (srcRect.YMax < sourceRect.YMax)) { throw new DjvuArgumentException("Invalid rectangle", nameof(srcRect)); } // Adjust output pixmap if ((targetRect.Width != (int)targetMap.Width) || (targetRect.Height != (int)targetMap.Height)) { targetMap.Init(targetRect.Height, targetRect.Width, null); } // Prepare temp stuff int bufw = required_red.Width; Pixel[] lbuffer = new Pixel[bufw + 2]; try { if ((_XShift > 0) || (_YShift > 0)) { _PixelMap1 = new PixelMap().Init(1, bufw, null); _PixelMap2 = new PixelMap().Init(2, bufw, null); _L1 = _L2 = -1; } IPixelReference upper = srcMap.CreateGPixelReference(0, 0); IPixelReference lower = srcMap.CreateGPixelReference(0, 0); IPixelReference dest = targetMap.CreateGPixelReference(0, 0); // Loop on output lines for (int y = targetRect.YMin; y < targetRect.YMax; y++) { // Perform vertical interpolation { int fy = _VCoord[y]; int fy1 = fy >> FRACBITS; int fy2 = fy1 + 1; // Obtain upper and lower line in reduced image if ((_XShift > 0) || (_YShift > 0)) { lower = GetLine(fy1, required_red, srcRect, srcMap); upper = GetLine(fy2, required_red, srcRect, srcMap); } else { int dx = required_red.XMin - srcRect.XMin; if (required_red.YMin > fy1) { fy1 = required_red.YMin; } if (required_red.YMax <= fy2) { fy2 = required_red.YMax - 1; } lower.SetOffset(fy1 - srcRect.YMin, dx); // srcMap.CreateGPixelReference(fy1 - srcRect.YMin, dx); upper.SetOffset(fy2 - srcRect.YMin, dx); // srcMap.CreateGPixelReference(fy2 - srcRect.YMin, dx); } // Compute line int idest = 1; short[] deltas = interp[fy & FRACMASK]; unsafe { for (int edest = idest + bufw; idest < edest; upper.IncOffset(), lower.IncOffset()) { Pixel destPix = lbuffer[idest++]; int color = 0; sbyte *colorPtr = (sbyte *)&color; // Skip alpha and set pointer to Blue colorPtr++; *colorPtr = lower.Blue; *colorPtr += (sbyte)deltas[(256 + upper.Blue) - *colorPtr]; // Set pointer to Green colorPtr++; *colorPtr = lower.Green; *colorPtr += (sbyte)deltas[(256 + upper.Green) - *colorPtr]; // Set pointer to Red colorPtr++; *colorPtr = lower.Red; *colorPtr += (sbyte)deltas[(256 + upper.Red) - *colorPtr]; //Pixel d = (Pixel) lower.ToPixel(); //destPix.SetBGR(d); destPix.SetBGR(*colorPtr); } } } // Perform horizontal interpolation { // Prepare for side effects lbuffer[0] = lbuffer[1]; // lbuffer[bufw] = lbuffer[bufw]; int line = 1 - required_red.XMin; dest.SetOffset(y - targetRect.YMin, 0); //= targetMap.CreateGPixelReference(y - targetRect.YMin, 0); // Loop horizontally unsafe { for (int x = targetRect.XMin; x < targetRect.XMax; x++) { int n = _HCoord[x]; int lowerl = line + (n >> FRACBITS); Pixel lower0 = lbuffer[lowerl]; Pixel lower1 = lbuffer[lowerl + 1]; short[] deltas = interp[n & FRACMASK]; int color = 0; sbyte *colorPtr = (sbyte *)&color; // Skip alpha and set pointer to Blue colorPtr++; *colorPtr = lower0.Blue; *colorPtr += (sbyte)deltas[(256 + lower1.Blue) - *colorPtr]; // Set pointer to Green colorPtr++; *colorPtr = lower0.Green; *colorPtr += (sbyte)deltas[(256 + lower1.Green) - *colorPtr]; // Set pointer to Red colorPtr++; *colorPtr = lower0.Red; *colorPtr += (sbyte)deltas[(256 + lower1.Red) - *colorPtr]; dest.SetBGR(*colorPtr); dest.IncOffset(); } } } } } finally { _PixelMap1 = null; _PixelMap2 = null; } }