Пример #1
0
	// Process a RGB image with alpha and 555 bit fields.
	private static void RgbAlpha555(Frame frame, ScanlineReader reader,
							   		int width, int height,
							   		int offsetX, int offsetY,
							   		int multX, int multY)
			{
				int x, y, offset, posn, value;
				byte[] scanline;
				byte[] data = frame.Data;
				for(y = 0; y < height; ++y)
				{
					offset = ((y * multY) + offsetY) * frame.Stride +
							 offsetX * 2;
					posn = 0;
					scanline = reader.Read();
					for(x = 0; x < width; ++x)
					{
						value = ((scanline[posn] & 0xF8) << 7) |
								((scanline[posn + 1] & 0xF8) << 2) |
								((scanline[posn + 2] & 0xF8) >> 3) |
								((scanline[posn + 3] & 0x80) << 8);
						data[offset]     = (byte)value;
						data[offset + 1] = (byte)(value >> 8);
						offset += multX * 2;
						posn += 4;
					}
				}
			}
Пример #2
0
	// Process a 16-bit RGB image with alpha.
	private static void RgbAlpha16bpp(Frame frame, ScanlineReader reader,
								      int width, int height,
								      int offsetX, int offsetY,
								      int multX, int multY)
			{
				int x, y, offset, posn;
				byte[] scanline;
				byte[] data = frame.Data;
				for(y = 0; y < height; ++y)
				{
					offset = ((y * multY) + offsetY) * frame.Stride +
							 offsetX * 8;
					posn = 0;
					scanline = reader.Read();
					for(x = 0; x < width; ++x)
					{
						// Flip the RGB PNG data into BGR form.
						data[offset]     = scanline[posn + 5];
						data[offset + 1] = scanline[posn + 4];
						data[offset + 2] = scanline[posn + 3];
						data[offset + 3] = scanline[posn + 2];
						data[offset + 4] = scanline[posn + 1];
						data[offset + 5] = scanline[posn];
						data[offset + 6] = scanline[posn + 7];
						data[offset + 7] = scanline[posn + 6];
						offset += multX * 8;
						posn += 8;
					}
				}
			}
Пример #3
0
	// Process a 8-bit indexed image.
	private static void Indexed8bpp(Frame frame, ScanlineReader reader,
								    int width, int height,
								    int offsetX, int offsetY,
								    int multX, int multY)
			{
				int x, y, offset, posn;
				byte[] scanline;
				byte[] data = frame.Data;
				for(y = 0; y < height; ++y)
				{
					offset = ((y * multY) + offsetY) * frame.Stride + offsetX;
					scanline = reader.Read();
					if(multX == 1)
					{
						Array.Copy(scanline, 0, data, offset, width);
					}
					else
					{
						posn = 0;
						for(x = 0; x < width; ++x)
						{
							data[offset] = scanline[posn];
							offset += multX;
							++posn;
						}
					}
				}
			}
Пример #4
0
	// Process a 16-bit gray scale image with alpha.
	private static void GrayScaleAlpha16bpp(Frame frame, ScanlineReader reader,
								       	    int width, int height,
								       	    int offsetX, int offsetY,
								       	    int multX, int multY)
			{
				int x, y, offset, posn;
				byte value;
				byte[] scanline;
				byte[] data = frame.Data;
				for(y = 0; y < height; ++y)
				{
					offset = ((y * multY) + offsetY) * frame.Stride +
							 offsetX * 4;
					posn = 0;
					scanline = reader.Read();
					for(x = 0; x < width; ++x)
					{
						value = scanline[posn];
						data[offset]     = value;
						data[offset + 1] = value;
						data[offset + 2] = value;
						data[offset + 3] = scanline[posn + 2];
						offset += multX * 4;
						posn += 4;
					}
				}
			}
Пример #5
0
	// Process a 4-bit gray scale image.
	private static void GrayScale4bpp(Frame frame, ScanlineReader reader,
								      int width, int height,
								      int offsetX, int offsetY,
								      int multX, int multY)
			{
				int x, y, offset, posn, bit;
				byte value;
				byte[] scanline;
				byte[] data = frame.Data;
				for(y = 0; y < height; ++y)
				{
					offset = ((y * multY) + offsetY) * frame.Stride +
							 offsetX * 3;
					posn = 0;
					bit = 4;
					scanline = reader.Read();
					for(x = 0; x < width; ++x)
					{
						value = (byte)(((scanline[posn] >> bit) & 0x0F) * 0x11);
						data[offset]     = value;
						data[offset + 1] = value;
						data[offset + 2] = value;
						offset += multX * 3;
						bit -= 4;
						if(bit < 0)
						{
							++posn;
							bit = 4;
						}
					}
				}
			}
Пример #6
0
	// Process a 1-bit gray scale image.
	private static void GrayScale1bpp(Frame frame, ScanlineReader reader,
								      int width, int height,
								      int offsetX, int offsetY,
								      int multX, int multY)
			{
				int x, y, offset, posn, bit;
				byte value;
				byte[] scanline;
				byte[] data = frame.Data;
				for(y = 0; y < height; ++y)
				{
					offset = ((y * multY) + offsetY) * frame.Stride +
							 offsetX * 3;
					posn = 0;
					bit = 0x80;
					scanline = reader.Read();
					for(x = 0; x < width; ++x)
					{
						if((scanline[posn] & bit) != 0)
						{
							value = 0xFF;
						}
						else
						{
							value = 0x00;
						}
						data[offset]     = value;
						data[offset + 1] = value;
						data[offset + 2] = value;
						offset += multX * 3;
						bit >>= 1;
						if(bit == 0)
						{
							++posn;
							bit = 0x80;
						}
					}
				}
			}