public override void write(int ulx, int uly, int w, int h)
{
int k, i, j;
int fracbits = fb; // In local variable for faster access
int tOffx, tOffy; // Active tile offset in the X and Y direction
// Initialize db
db.ulx = ulx;
db.uly = uly;
db.w = w;
db.h = h;
// Get the current active tile offset
//UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
tOffx = src.getCompULX(c) - (int) System.Math.Ceiling(src.ImgULX / (double) src.getCompSubsX(c));
//UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
tOffy = src.getCompULY(c) - (int) System.Math.Ceiling(src.ImgULY / (double) src.getCompSubsY(c));
// Check the array size
if (db.data_array != null && db.data_array.Length < w * h)
{
// A new one will be allocated by getInternCompData()
db.data_array = null;
}
// Request the data and make sure it is not
// progressive
do
{
db = (DataBlkInt) src.getInternCompData(db, c);
}
while (db.progressive);
// variables used during coeff saturation
int tmp, maxVal = (1 << src.getNomRangeBits(c)) - 1;
// If nominal bitdepth greater than 8, calculate down shift
int downShift = src.getNomRangeBits(c) - 8;
if (downShift < 0)
{
downShift = 0;
}
// Check line buffer
if (buf == null || buf.Length < w)
{
buf = new byte[w]; // Expand buffer
}
// Write line by line
for (i = 0; i < h; i++)
{
// Skip to beggining of line in file
out_Renamed.Seek(this.offset + this.w * (uly + tOffy + i) + ulx + tOffx, System.IO.SeekOrigin.Begin);
// Write all bytes in the line
if (fracbits == 0)
{
for (k = db.offset + i * db.scanw + w - 1, j = w - 1; j >= 0; j--, k--)
{
tmp = db.data_array[k] + levShift;
buf[j] = (byte) (((tmp < 0)?0:((tmp > maxVal)?maxVal:tmp)) >> downShift);
}
}
else
{
for (k = db.offset + i * db.scanw + w - 1, j = w - 1; j >= 0; j--, k--)
{
tmp = (db.data_array[k] >> fracbits) + levShift;
buf[j] = (byte) (((tmp < 0)?0:((tmp > maxVal)?maxVal:tmp)) >> downShift);
}
}
out_Renamed.Write(buf, 0, w);
}
}