Esempio n. 1
0
ByteStream BuiltinProtocolHandlersLocal::read(size_t nbytes)
{
    if (d->m_fd == -1) {
        return ByteStream();
    }
    ichar resBuffer[nbytes];
    const size_t bytesRead = ::read(d->m_fd, resBuffer, nbytes);
    if (bytesRead) {
        return ByteStream(resBuffer, bytesRead);
    }
    return ByteStream();
}
Esempio n. 2
0
ByteStream BuiltinProtocolHandlersHttp::read(size_t nbytes)
{
    if (d->m_sockfd == -1) {
        return ByteStream();
    }
    ichar *buf = (ichar*) calloc(d->m_bufferSize + 1, sizeof(ichar));
    const ssize_t bytesRead = recv(d->m_sockfd, buf, d->m_bufferSize, 0);
    if (bytesRead > 0) {
        ByteStream res(buf, bytesRead);
        free(buf);
        return res;
    }
    free(buf);
    return ByteStream();
}
Esempio n. 3
0
RawImage PefDecoder::decodeRawInternal() {
  auto raw = mRootIFD->getIFDWithTag(STRIPOFFSETS);

  int compression = raw->getEntry(COMPRESSION)->getU32();

  if (1 == compression || compression == 32773) {
    decodeUncompressed(raw, BitOrder_MSB);
    return mRaw;
  }

  if (65535 != compression)
    ThrowRDE("Unsupported compression");

  TiffEntry *offsets = raw->getEntry(STRIPOFFSETS);
  TiffEntry *counts = raw->getEntry(STRIPBYTECOUNTS);

  if (offsets->count != 1) {
    ThrowRDE("Multiple Strips found: %u", offsets->count);
  }
  if (counts->count != offsets->count) {
    ThrowRDE(
        "Byte count number does not match strip size: count:%u, strips:%u ",
        counts->count, offsets->count);
  }
  if (!mFile->isValid(offsets->getU32(), counts->getU32()))
    ThrowRDE("Truncated file.");

  uint32 width = raw->getEntry(IMAGEWIDTH)->getU32();
  uint32 height = raw->getEntry(IMAGELENGTH)->getU32();

  mRaw->dim = iPoint2D(width, height);
  mRaw->createData();
  try {
    PentaxDecompressor::decompress(
        mRaw, ByteStream(mFile, offsets->getU32(), counts->getU32()),
        getRootIFD());
  } catch (IOException &e) {
    mRaw->setError(e.what());
    // Let's ignore it, it may have delivered somewhat useful data.
  }

  return mRaw;
}