/// <summary> /// Writes initial file /// </summary> public void CreateSwapFile() { // Instrumentation DateTime tStart = DateTime.Now; Close(); m_fs = File.Open(m_name, FileMode.Create, FileAccess.ReadWrite, FileShare.Read); m_fs.Write(TIFHeader, 0, TIFHeader.Length); byte[] buff = new byte[RowSize]; byte[] bk = Slide.GetColorBytes(m_bkColor); for (uint i = 0; i < buff.Length; i += 3) { buff[i] = bk[0]; buff[i + 1] = bk[1]; buff[i + 2] = bk[2]; } for (uint i = 0; i < m_y; i++) { m_fs.Write(buff, 0, buff.Length); } m_fs.Flush(); // Instrumentation TimeSpan ts = DateTime.Now.Subtract(tStart); WriteInstrumentationMessage("Swap file creation done: " + ts.TotalSeconds.ToString("0.000") + " sec (" + m_fs.Length.ToString("0") + " bytes)"); }
/// <summary> /// inserts the bitmap to file /// </summary> public bool SetBitmap(Bitmap b, int x, int y, bool preserveBitmap) { // Instrumentation WriteInstrumentationMessage("Bitmap pushed: at [" + x.ToString("0") + "," + y.ToString("0") + "], size [" + b.Width.ToString("0") + "," + b.Height.ToString("0") + "]"); DateTime tStart = DateTime.Now; bool ReadPerformed = false; // Decide how much of the file has to be pasted int x1 = x; int dx1 = b.Width; int xOrigin = 0; if (ComputeLimits(ref x1, ref dx1, ref xOrigin, m_x)) { return(false); } int y1 = y; int dy1 = b.Height; int yOrigin = 0; if (ComputeLimits(ref y1, ref dy1, ref yOrigin, m_y)) { return(false); } // Decide the start and the end of the buffer to be read // Note that in bmp files the rows are up side down uint rs = RowSize; long bufferStart = TIFHeader.Length + (long)(y1) * (long)(rs); int bufferSize = (int)(rs * dy1); if (m_buffer == null || m_buffer.Length != bufferSize || !preserveBitmap) { m_buffer = new byte[bufferSize]; if (dx1 < m_x) // need to fetch the unaffected areas { ReadPerformed = true; m_fs.Seek(bufferStart, SeekOrigin.Begin); m_fs.Read(m_buffer, 0, m_buffer.Length); } } // Fill image to the buffer for (int j = 0; j < dy1; j++) { int offset = j * (int)rs + x1 * 3; for (int i = 0, k = offset; i < dx1; i++, k += 3) { byte[] bb = Slide.GetColorBytes(b.GetPixel(xOrigin + i, yOrigin + j)); m_buffer[k] = bb[0]; m_buffer[k + 1] = bb[1]; m_buffer[k + 2] = bb[2]; } } m_fs.Seek(bufferStart, SeekOrigin.Begin); m_fs.Write(m_buffer, 0, m_buffer.Length); m_fs.Flush(); // Instrumentation TimeSpan ts = DateTime.Now.Subtract(tStart); int pix = b.Width * b.Height; WriteInstrumentationMessage("Bitmap saved: at [" + x1.ToString("0") + "," + y1.ToString("0") + "], size [" + dx1.ToString("0") + "," + dy1.ToString("0") + "] in " + ts.TotalSeconds.ToString("0.000") + " sec (" + pix.ToString("0") + " pixels)"); return(ReadPerformed); }