private byte[] DownloadStiIndexed(SlfRecordStci aStciRecord, int aDataLength) { Ja2Data.StciHeader _header = DownloadStciHeader(aStciRecord); StciIndexed _indexedRec = aStciRecord.StciIndexed.First(); Ja2Data.StciIndexedHeader _subHeader = new Ja2Data.StciIndexedHeader((UInt16)_indexedRec.NumberOfSubImages); _subHeader.BlueDepth = _indexedRec.BlueDepth; _subHeader.GreenDepth = _indexedRec.GreenDepth; _subHeader.RedDepth = _indexedRec.RedDepth; _subHeader.NumberOfColous = (uint)_indexedRec.NumberOfColours; _header.SubHeader = _subHeader; Ja2Data.StciSubImage[] _subImages = new Ja2Data.StciSubImage[_indexedRec.NumberOfSubImages]; int i = 0; foreach (StciIndexedSubImage _subImage in _indexedRec.StciIndexedSubImage) { _subImages[i] = this.DownloadStciSubimage(_subImage); i++; } Ja2Data.StciIndexed _stciIndexed = new Ja2Data.StciIndexed(_header, _indexedRec.Palette, _subImages); byte[] _buffer = new byte[aDataLength]; using (MemoryStream _ms = new MemoryStream(_buffer)) { _stciIndexed.Save(_ms); } return(_buffer); }
private SlfRecordStci LoadStciHeader(Ja2Data.StciHeader aStciHeader) { SlfRecordStci _newStciHeader = new SlfRecordStci(); _newStciHeader.AppDataSize = (int)aStciHeader.AppDataSize; _newStciHeader.Depth = aStciHeader.Depth; _newStciHeader.Height = aStciHeader.ImageHeight; _newStciHeader.ID = aStciHeader.FormatId; _newStciHeader.OriginalSize = aStciHeader.OriginalImageSize; _newStciHeader.StoredSize = aStciHeader.CompressedImageSize; _newStciHeader.TransparentValue = aStciHeader.TransparentColorIndex; _newStciHeader.Unused = aStciHeader.Unused; _newStciHeader.Width = aStciHeader.ImageWidth; _newStciHeader.UserId = this.FUserId; _newStciHeader.DateCreated = DateTime.Now; var _flags = this.FStciFlags.Where(x => (x.Mask & (byte)aStciHeader.Flags) != 0); foreach (Flag _flag in _flags) { StciRecordStciFlag _recFlag = new StciRecordStciFlag(); _recFlag.FlagId = (byte)_flag.Id; _recFlag.SlfRecordStci = _newStciHeader; this.FRecordsFlags.Add(_recFlag); } return(_newStciHeader); }
private byte[] DownloadStciRgb(SlfRecordStci aStciRecord, int aDataLength) { Ja2Data.StciHeader _header = DownloadStciHeader(aStciRecord); StciRgb _rgbRec = aStciRecord.StciRgb.First(); Ja2Data.StciRgbHeader _subHeader = new Ja2Data.StciRgbHeader(); _subHeader.AlphaDepth = _rgbRec.AlphaDepth; _subHeader.AlphaMask = (uint)_rgbRec.AlphaMask; _subHeader.BlueDepth = _rgbRec.BlueDepth; _subHeader.BlueMask = (uint)_rgbRec.BlueMask; _subHeader.GreenDepth = _rgbRec.GreenDepth; _subHeader.GreenMask = (uint)_rgbRec.GreenMask; _subHeader.RedDepth = _rgbRec.RedDepth; _subHeader.RedMask = (uint)_rgbRec.RedMask; _header.SubHeader = _subHeader; Ja2Data.StciRgb _stciRgb = new Ja2Data.StciRgb(_header); _stciRgb.ImageData = _rgbRec.UnstructuredData.Data; byte[] _buffer = new byte[aDataLength]; using (MemoryStream _ms = new MemoryStream(_buffer)) { _stciRgb.Save(_ms); } return(_buffer); }
private Ja2Data.SlfFile.Record DownloadStiRecord(long aStiRecordId) { Ja2DataEntities _context = new Ja2DataEntities(); SlfRecordStci _stiRec = _context.SlfRecordStci.First(x => x.SlfRecordId == aStiRecordId); Ja2Data.SlfFile.Record _stiFile = this.DownloadStiRecord(_stiRec); _context = null; return(_stiFile); }
private Ja2Data.SlfFile.Record DownloadStiRecord(SlfRecordStci aStciRecord) { Ja2Data.SlfFile.Record.Header _header = this.DownloadSlfRecordHeader(aStciRecord.SlfRecordHeader); Ja2Data.SlfFile.Record _rec = new Ja2Data.SlfFile.Record(_header); if (aStciRecord.StciIndexed.Count != 0) { _rec.Data = this.DownloadStiIndexed(aStciRecord, (int)_header.uiLength); } else if (aStciRecord.StciRgb.Count != 0) { _rec.Data = this.DownloadStciRgb(aStciRecord, (int)_header.uiLength); } return(_rec); }
public override int Upload(BinaryReader aReader, int aSlfFileId) { int _count = 0; foreach (Ja2Data.SlfFile.Record _file in this.FFiles) { try { aReader.BaseStream.Position = _file.Offset; SlfRecordHeader _recHeader = this.CreateSlfRecordHeader(_file); this.FHeaders.Add(_recHeader); Ja2Data.StciHeader _stciHeader = new Ja2Data.StciHeader(); _stciHeader.Read(aReader); SlfRecordStci _stciRecord = this.LoadStciHeader(_stciHeader); _stciRecord.SlfRecordHeader = _recHeader; _stciRecord.SlfFileId = aSlfFileId; this.FRecords.Add(_stciRecord); if (_stciHeader.IsIndexed) { StciIndexed _newStciIndexed = this.LoadStciIndexed(aReader, _stciHeader); _newStciIndexed.SlfRecordStci = _stciRecord; this.FRecordsIndexed.Add(_newStciIndexed); } else { StciRgb _newStciRgb = this.LoadStciRgb(aReader, _stciHeader); _newStciRgb.SlfRecordStci = _stciRecord; this.FRecordsRgb.Add(_newStciRgb); } this.AddRecordsToDataSet(); _count += this.SaveChanges(); } catch (Exception _exc) { string _excMess = String.Format("Uploading file {0} exception\n", _file.FileName); throw new Exception(_excMess, _exc); } } return(_count); }
private static Ja2Data.StciHeader DownloadStciHeader(SlfRecordStci aStciRecord) { Ja2Data.StciHeader _header = new Ja2Data.StciHeader(); _header.AppDataSize = (uint)aStciRecord.AppDataSize; _header.CompressedImageSize = aStciRecord.StoredSize; _header.Depth = aStciRecord.Depth; int _flags = 0; foreach (StciRecordStciFlag _flag in aStciRecord.StciRecordStciFlag) { _flags |= _flag.StciFlags.Mask.Value; } _header.Flags = (Ja2Data.StciFlags)_flags; _header.ImageHeight = aStciRecord.Height; _header.ImageWidth = aStciRecord.Width; _header.TransparentColorIndex = aStciRecord.TransparentValue; _header.OriginalImageSize = (uint)aStciRecord.OriginalSize; _header.Unused = aStciRecord.Unused; return(_header); }