/* Check if the decoder can decode the image from this camera */ /* A RawDecoderException will be thrown if the camera isn't supported */ /* Unknown cameras does NOT generate any specific feedback */ /* This function must be overridden by actual decoders */ void decodeUncompressed(ref TiffIFD rawIFD, BitOrder order) { UInt32 nslices = rawIFD.getEntry(STRIPOFFSETS).count; TiffEntry* offsets = rawIFD.getEntry(STRIPOFFSETS); TiffEntry* counts = rawIFD.getEntry(STRIPBYTECOUNTS); UInt32 yPerSlice = rawIFD.getEntry(ROWSPERSTRIP).getInt(); UInt32 width = rawIFD.getEntry(IMAGEWIDTH).getInt(); UInt32 height = rawIFD.getEntry(IMAGELENGTH).getInt(); UInt32 bitPerPixel = rawIFD.getEntry(BITSPERSAMPLE).getInt(); vector<RawSlice> slices; UInt32 offY = 0; for (UInt32 s = 0; s < nslices; s++) { RawSlice slice; slice.offset = offsets.getInt(s); slice.count = counts.getInt(s); if (offY + yPerSlice > height) slice.h = height - offY; else slice.h = yPerSlice; offY += yPerSlice; if (mFile.isValid(slice.offset, slice.count)) // Only decode if size is valid slices.push_back(slice); } if (0 == slices.size()) ThrowRDE("RAW Decoder: No valid slices found. File probably truncated."); mRaw.dim = iPoint2D(width, offY); mRaw.createData(); mRaw.whitePoint = (1 << bitPerPixel) - 1; offY = 0; for (UInt32 i = 0; i < slices.size(); i++) { RawSlice slice = slices[i]; ByteStream in(mFile, slice.offset, slice.count); iPoint2D size(width, slice.h); iPoint2D pos(0, offY); bitPerPixel = (int)((UInt64)((UInt64)slice.count * 8u) / (slice.h * width)); try { readUncompressedRaw(in, size, pos, width * bitPerPixel / 8, bitPerPixel, order); } catch (RawDecoderException &e) { if (i > 0) mRaw.setError(e.what()); else throw; } catch (IOException &e) {
protected void DecodeUncompressed(IFD rawIFD, BitOrder order) { uint nslices = rawIFD.GetEntry(TagType.STRIPOFFSETS).dataCount; Tag offsets = rawIFD.GetEntry(TagType.STRIPOFFSETS); Tag counts = rawIFD.GetEntry(TagType.STRIPBYTECOUNTS); if (counts.dataCount != offsets.dataCount) { throw new RawDecoderException("Byte count number does not match strip size: count:" + counts.dataCount + ", strips:" + offsets.dataCount); } uint yPerSlice = rawIFD.GetEntry(TagType.ROWSPERSTRIP).GetUInt(0); uint width = rawIFD.GetEntry(TagType.IMAGEWIDTH).GetUInt(0); uint height = rawIFD.GetEntry(TagType.IMAGELENGTH).GetUInt(0); ushort bitPerPixel = rawIFD.GetEntry(TagType.BITSPERSAMPLE).GetUShort(0); rawImage.fullSize.ColorDepth = bitPerPixel; uint offY = 0; List <RawSlice> slices = new List <RawSlice>(); for (int s = 0; s < nslices; s++) { RawSlice slice = new RawSlice() { offset = offsets.GetUInt(s), count = counts.GetUInt(s), offsetY = offY }; if (offY + yPerSlice > height) { slice.h = height - offY; } else { slice.h = yPerSlice; } offY += yPerSlice; if (reader.IsValid(slice.offset, slice.count)) // Only decode if size is valid { slices.Add(slice); } } if (0 == slices.Count) { throw new RawDecoderException("RAW Decoder: No valid slices found. File probably truncated."); } rawImage.fullSize.dim = new Point2D(width, offY); rawImage.whitePoint = (ushort)((1 << bitPerPixel) - 1); offY = 0; for (int i = 0; i < slices.Count; i++) { RawSlice slice = slices[i]; reader.BaseStream.Position = slice.offset; bitPerPixel = (ushort)(slice.count * 8u / (slice.h * width)); RawDecompressor.ReadUncompressedRaw(reader, new Point2D(width, slice.h), new Point2D(0, slice.offsetY), rawImage.fullSize.cpp * width * bitPerPixel / 8, bitPerPixel, order, rawImage); offY += slice.h; } }