Esempio n. 1
0
        // Load bitmap data into a frame.
        public static void LoadBitmapData(Stream stream, Frame frame, bool mask, bool reverse)
        {
            byte[] data;
            int    stride;
            int    line;

            // Get the buffer and stride for the frame.
            if (!mask)
            {
                data   = frame.Data;
                stride = frame.Stride;
            }
            else
            {
                frame.AddMask();
                data   = frame.Mask;
                stride = frame.MaskStride;
            }

            // BMP images are usuallystored upside down in the stream.
            if (reverse)
            {
                for (line = frame.Height - 1; line >= 0; --line)
                {
                    stream.Read(data, line * stride, stride);
                }
            }
            else
            {
                for (line = 0; line < frame.Height; line++)
                {
                    stream.Read(data, line * stride, stride);
                }
            }
        }
Esempio n. 2
0
        public static void Copy(Frame dest, int x, int y, int width, int height, Frame source, int sourceX, int sourceY)
        {
            // Developers should be aware of any costly conversions.
            // So we don't automatically match the depths.
            if (source.pixelFormat != dest.pixelFormat)
            {
                throw new InvalidOperationException();
            }

            if (x < 0 || y < 0 || width <= 0 || height <= 0)
            {
                throw new ArgumentOutOfRangeException();
            }

            if (x + width > dest.width)
            {
                width = dest.width - x;
            }

            if (y + height > dest.height)
            {
                height = dest.height - x;
            }

            if (source.width - sourceX < width)
            {
                width = source.width - sourceX;
            }
            if (source.height - sourceY < height)
            {
                height = source.height - sourceY;
            }

            //TODO:
            // If we are copying an index bitmap, we need to find the color
            // in the destination palette that is closest to the color we are
            // copying to. We would also need to add colors to the palette,
            // if there is space and optionally optimize the palette.
            // For now we just overwrite the old palette.

            if (source.palette != null)
            {
                dest.palette = (int[])source.palette.Clone();
            }

            int bits = Utils.FormatToBitCount(source.pixelFormat);

            Copy(bits, dest.data, dest.stride, x, y, width, height, source.Data, source.stride, sourceX, sourceY);

            //TODO:
            // The mask is not taken into account when copying. We need to
            // look at adding alpha support.
            // For now, just copy over the mask.
            if (source.Mask != null)
            {
                dest.AddMask();
                Copy(1, dest.mask, dest.maskStride, x, y, width, height, source.mask, source.maskStride, sourceX, sourceY);
            }
        }
Esempio n. 3
0
        // Save the bitmap data in a frame.
        public static void SaveBitmapData(Stream stream, Frame frame,
                                          bool mask, bool inverted)
        {
            byte[] data;
            int    stride;
            int    line, column;

            // Get the buffer and stride for the frame.
            if (!mask)
            {
                data   = frame.Data;
                stride = frame.Stride;
            }
            else
            {
                frame.AddMask();
                data   = frame.Mask;
                stride = frame.MaskStride;
            }

            // BMP images are stored upside down in the stream.
            if (!inverted)
            {
                for (line = frame.Height - 1; line >= 0; --line)
                {
                    stream.Write(data, line * stride, stride);
                }
            }
            else
            {
                for (line = frame.Height - 1; line >= 0; --line)
                {
                    for (column = 0; column < stride; ++column)
                    {
                        stream.WriteByte
                            ((byte)(data[line * stride + column] ^ 0xFF));
                    }
                }
            }
        }
Esempio n. 4
0
	public static void Copy(Frame dest, int x, int y, int width, int height, Frame source, int sourceX, int sourceY)
			{
				// Developers should be aware of any costly conversions.
				// So we don't automatically match the depths.
				if (source.pixelFormat != dest.pixelFormat)
				{
					throw new InvalidOperationException();
				}

				if (x < 0 || y < 0 || width <= 0 || height <= 0)
				{
					throw new ArgumentOutOfRangeException();
				}

				if (x + width > dest.width)
				{
					width = dest.width - x;
				}

				if (y + height > dest.height)
				{
					height = dest.height - x;
				}

				if (source.width - sourceX < width)
				{
					width = source.width - sourceX;
				}
				if (source.height - sourceY < height)
				{
					height = source.height - sourceY;
				}

				//TODO:
				// If we are copying an index bitmap, we need to find the color
				// in the destination palette that is closest to the color we are
				// copying to. We would also need to add colors to the palette,
				// if there is space and optionally optimize the palette.
				// For now we just overwrite the old palette.

				if (source.palette != null)
				{
					dest.palette = (int[])source.palette.Clone();
				}
								
				int bits = Utils.FormatToBitCount(source.pixelFormat);
				Copy (bits, dest.data, dest.stride, x, y, width, height, source.Data, source.stride, sourceX, sourceY);

				//TODO:
				// The mask is not taken into account when copying. We need to
				// look at adding alpha support.
				// For now, just copy over the mask.
				if (source.Mask != null)
				{
					dest.AddMask();
					Copy(1, dest.mask, dest.maskStride,  x, y, width, height, source.mask, source.maskStride, sourceX, sourceY);
				}

			}
Esempio n. 5
0
	// Save the bitmap data in a frame.
	public static void SaveBitmapData(Stream stream, Frame frame,
									  bool mask, bool inverted)
			{
				byte[] data;
				int stride;
				int line, column;

				// Get the buffer and stride for the frame.
				if(!mask)
				{
					data = frame.Data;
					stride = frame.Stride;
				}
				else
				{
					frame.AddMask();
					data = frame.Mask;
					stride = frame.MaskStride;
				}

				// BMP images are stored upside down in the stream.
				if(!inverted)
				{
					for(line = frame.Height - 1; line >= 0; --line)
					{
						stream.Write(data, line * stride, stride);
					}
				}
				else
				{
					for(line = frame.Height - 1; line >= 0; --line)
					{
						for(column = 0; column < stride; ++column)
						{
							stream.WriteByte
								((byte)(data[line * stride + column] ^ 0xFF));
						}
					}
				}
			}
Esempio n. 6
0
	// Load bitmap data into a frame.
	public static void LoadBitmapData(Stream stream, Frame frame, bool mask, bool reverse)
			{
				byte[] data;
				int stride;
				int line;

				// Get the buffer and stride for the frame.
				if(!mask)
				{
					data = frame.Data;
					stride = frame.Stride;
				}
				else
				{
					frame.AddMask();
					data = frame.Mask;
					stride = frame.MaskStride;
				}

				// BMP images are usuallystored upside down in the stream.
				if (reverse)
				{
					for(line = frame.Height - 1; line >= 0; --line)
					{
						stream.Read(data, line * stride, stride);
					}
				}
				else
				{
					for(line = 0; line <  frame.Height; line++)
					{
						stream.Read(data, line * stride, stride);
					}
				}
			}