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);
int tmp;
// Check line buffer
if (buf == null || buf.Length < packBytes * w)
{
buf = new byte[packBytes * w]; // Expand buffer
}
switch (packBytes)
{
case 1: // Samples packed into 1 byte
// Write line by line
for (i = 0; i < h; i++)
{
// Skip to beggining of line in file
out_Renamed.Seek(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; k--)
{
tmp = db.data_array[k] + levShift;
buf[j--] = (byte) ((tmp < minVal)?minVal:((tmp > maxVal)?maxVal:tmp));
}
}
else
{
for (k = db.offset + i * db.scanw + w - 1, j = w - 1; j >= 0; k--)
{
tmp = (SupportClass.URShift(db.data_array[k], fracbits)) + levShift;
buf[j--] = (byte) ((tmp < minVal)?minVal:((tmp > maxVal)?maxVal:tmp));
}
}
out_Renamed.Write(buf, 0, w);
}
break;
case 2: // Samples packed in to 2 bytes (short)
// Write line by line
for (i = 0; i < h; i++)
{
// Skip to beggining of line in file
out_Renamed.Seek(offset + 2 * (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) - 1; j >= 0; k--)
{
tmp = db.data_array[k] + levShift;
tmp = (tmp < minVal)?minVal:((tmp > maxVal)?maxVal:tmp);
buf[j--] = (byte) tmp; // no need for 0xFF mask since
// truncation will do it already
buf[j--] = (byte) (SupportClass.URShift(tmp, 8));
}
}
else
{
for (k = db.offset + i * db.scanw + w - 1, j = (w << 1) - 1; j >= 0; k--)
{
tmp = (SupportClass.URShift(db.data_array[k], fracbits)) + levShift;
tmp = (tmp < minVal)?minVal:((tmp > maxVal)?maxVal:tmp);
buf[j--] = (byte) tmp; // no need for 0xFF mask since
// truncation will do it already
buf[j--] = (byte) (SupportClass.URShift(tmp, 8));
}
}
out_Renamed.Write(buf, 0, w << 1);
}
break;
case 4:
// Write line by line
for (i = 0; i < h; i++)
{
// Skip to beggining of line in file
out_Renamed.Seek(offset + 4 * (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 << 2) - 1; j >= 0; k--)
{
tmp = db.data_array[k] + levShift;
tmp = (tmp < minVal)?minVal:((tmp > maxVal)?maxVal:tmp);
buf[j--] = (byte) tmp; // No need to use 0xFF
buf[j--] = (byte) (SupportClass.URShift(tmp, 8)); // masks since truncation
buf[j--] = (byte) (SupportClass.URShift(tmp, 16)); // will have already the
buf[j--] = (byte) (SupportClass.URShift(tmp, 24)); // same effect
}
}
else
{
for (k = db.offset + i * db.scanw + w - 1, j = (w << 2) - 1; j >= 0; k--)
{
tmp = (SupportClass.URShift(db.data_array[k], fracbits)) + levShift;
tmp = (tmp < minVal)?minVal:((tmp > maxVal)?maxVal:tmp);
buf[j--] = (byte) tmp; // No need to use 0xFF
buf[j--] = (byte) (SupportClass.URShift(tmp, 8)); // masks since truncation
buf[j--] = (byte) (SupportClass.URShift(tmp, 16)); // will have already the
buf[j--] = (byte) (SupportClass.URShift(tmp, 24)); // same effect
}
}
out_Renamed.Write(buf, 0, w << 2);
}
break;
default:
throw new System.IO.IOException("PGX supports only bit-depth between " + "1 and 31");
}
}