Tissemand
Squire
I've been converting some snippets from C# (UltimaSDK) to C and using 32-bit bitmaps (RGBA8888) instead of UltimaSDK's 16-bit one's (ARGB1555)...
I'm currently stuck trying to convert this section:
This is what I currently have:
I just don't know where each of the read pixels go, or how to get there, so any pointers would be great.
read_short(FILE *file) and read_int(FILE *file) read 2 and 4 bytes respectively (duh), and I also have a function called ARGB1555toRGBA8888(unsigned short color)...
Any ideas?
I'm currently stuck trying to convert this section:
Code:
private static unsafe Bitmap LoadStatic( Stream stream )
{
BinaryReader bin = new BinaryReader( stream );
bin.ReadInt32();
int width = bin.ReadInt16();
int height = bin.ReadInt16();
if ( width <= 0 || height <= 0 )
return null;
int[] lookups = new int[height];
int start = (int)bin.BaseStream.Position + (height * 2);
for ( int i = 0; i < height; ++i )
lookups[i] = (int)(start + (bin.ReadUInt16() * 2));
Bitmap bmp = new Bitmap( width, height, PixelFormat.Format16bppArgb1555 );
BitmapData bd = bmp.LockBits( new Rectangle( 0, 0, width, height ), ImageLockMode.WriteOnly, PixelFormat.Format16bppArgb1555 );
ushort *line = (ushort *)bd.Scan0;
int delta = bd.Stride >> 1;
for ( int y = 0; y < height; ++y, line += delta )
{
bin.BaseStream.Seek( lookups[y], SeekOrigin.Begin );
ushort *cur = line;
ushort *end;
int xOffset, xRun;
while ( ((xOffset = bin.ReadUInt16()) + (xRun = bin.ReadUInt16())) != 0 )
{
cur += xOffset;
end = cur + xRun;
while ( cur < end )
*cur++ = (ushort)(bin.ReadUInt16() ^ 0x8000);
}
}
bmp.UnlockBits( bd );
return bmp;
}
This is what I currently have:
Code:
GRRLIB_texImg *get_image( unsigned int object_id, enum art_type type )
{
fseek( art, art_position( object_id, type ), SEEK_SET );
unsigned short width, height;
read_int( art );
width = read_short( art );
height = read_short( art );
printf( "w=%d h=%d", width, height );
if ( width <= 0 || height <= 0 )
return NULL;
int lookups[height];
int i, start = ftell(art) + height * 2;
for( i = 0; i < height; i++ )
lookups[i] = (int)(start + (unsigned short)(read_short( art ) * 2 ));
GRRLIB_texImg *image = GRRLIB_CreateEmptyTexture( width, height );
int y;
for ( y = 0; y < height; ++y )
{
fseek( art, lookups[y], SEEK_SET );
unsigned short xOffset, xRun;
while ( ((xOffset = read_short(art)) + (xRun = read_short(art))) != 0 )
{
printf( "%x", read_short(art) ); // I have no idea what to do here or anywhere around here.
}
}
return image;
}
read_short(FILE *file) and read_int(FILE *file) read 2 and 4 bytes respectively (duh), and I also have a function called ARGB1555toRGBA8888(unsigned short color)...
Any ideas?