Esempio n. 1
0
    box3f Cylinders::computeBounds() const
    {
      box3f bbox = bounds();

      if (bbox != box3f(empty))
        return bbox;

      if (hasChild("cylinders")) {
        auto cylinders = child("cylinders").nodeAs<DataBuffer>();

        auto *base = (byte_t*)cylinders->base();

        int cylinderBytes = 24;
        if (hasChild("bytes_per_cylinder"))
          cylinderBytes = child("bytes_per_cylinder").valueAs<int>();

        int offset_v0 = 0;
        if (hasChild("offset_v0"))
          offset_v0 = child("offset_v0").valueAs<int>();

        int offset_v1 = 12;
        if (hasChild("offset_v1"))
          offset_v1 = child("offset_v1").valueAs<int>();

        int offset_radius = -1;
        if (hasChild("offset_radius"))
          offset_radius = child("offset_radius").valueAs<int>();

        float radius = 0.01f;
        if (hasChild("radius"))
          radius = child("radius").valueAs<float>();

        for (size_t i = 0; i < cylinders->numBytes(); i += cylinderBytes) {
          vec3f &v0 = *(vec3f*)(base + i + offset_v0);
          vec3f &v1 = *(vec3f*)(base + i + offset_v1);
          if (offset_radius >= 0)
            radius = *(float*)(base + i + offset_radius);
          // TODO less conservative bbox
          box3f cylinderBounds(ospcommon::min(v0, v1) - radius,
                               ospcommon::max(v0, v1) + radius);
          bbox.extend(cylinderBounds);
        }
      }

      child("bounds") = bbox;

      return bbox;
    }
Esempio n. 2
0
void DImg::putImageData(uchar* const data, bool copyData)
{
    if (!data)
    {
        delete [] m_priv->data;
        m_priv->data = nullptr;
        m_priv->null = true;
    }
    else if (copyData)
    {
        memcpy(m_priv->data, data, numBytes());
    }
    else
    {
        m_priv->data = data;
    }
}
Esempio n. 3
0
sys::SSize_T net::ssl::SSLConnection::read(sys::byte* b, sys::Size_T len)
{
    sys::SSize_T numBytes(0);
    int val(0);
    if (len == 0) return -1;
    
    numBytes = SSL_read(mSSL, (char*)b, len);
    
#if defined(__DEBUG_SOCKET)	
    std::cout << "======= READ FROM SECURE CONNECTION =========" << std::endl;
#endif
    
    if (((val = SSL_get_error(mSSL, numBytes)) != SSL_ERROR_NONE) || 
                        (numBytes == -1 && (NATIVE_SOCKET_GETLASTERROR() != 
                        NATIVE_SOCKET_ERROR(WOULDBLOCK))))
    {
#if defined(__DEBUG_SOCKET)
        std::cout << " Error on read!!!" << std::endl;
        std::cout << "=============================================" << std::endl << std::endl;
#endif

        throw net::ssl::SSLException(Ctxt(FmtX("When receiving %d bytes",
                                               len)) );
    }
    else if (numBytes == 0) 
    {
#if defined(__DEBUG_SOCKET)
        std::cout << " Zero byte read (End of connection)" << std::endl;
        std::cout << "=============================================" << std::endl << std::endl;
#endif
        return -1;
    }
#if defined(__DEBUG_SOCKET)
    std::cout << FmtX("Read %d bytes from socket:", numBytes) << std::endl;
    std::cout << "---------------------------------------------" << std::endl;
    std::cout << std::string(b, numBytes) << std::endl;
    std::cout << "---------------------------------------------" << std::endl;
    std::cout << "=============================================" << std::endl << std::endl;
#endif

    return numBytes;
}
Esempio n. 4
0
Utf8Codec::result Utf8Codec::do_in(MBState& s, const char* fromBegin, const char* fromEnd, const char*& fromNext,
                                   Char* toBegin, Char* toEnd, Char*& toNext) const
{
    Utf8Codec::result retstat = ok;
    fromNext = fromBegin;
    toNext = toBegin;

    // check for empty input
    if (fromEnd == fromBegin)
        return ok;

    // check for incomplete byte order mark:
    if (numBytes(s, fromBegin, fromEnd) < 3)
    {
        if (getByte(s, fromBegin, fromEnd, 0) == '\xef')
        {
            while (fromNext < fromEnd)
                s.value.mbytes[s.n++] = *fromNext++;
            return ok;
        }
    }
    else
    {
        // skip byte order mark
        if (getByte(s, fromBegin, fromEnd, 0) == '\xef'
            && getByte(s, fromBegin, fromEnd, 1) == '\xbb'
            && getByte(s, fromBegin, fromEnd, 2) == '\xbf')
        {
            if (s.n <= 3)
            {
                fromNext += 3 - s.n;
                s.n = 0;
            }
            else
            {
                std::memmove(s.value.mbytes, s.value.mbytes + 3, s.n - 3);
                s.n -= 3;
            }
        }
    }

    while (fromNext < fromEnd)
    {
        if (toNext >= toEnd)
        {
            retstat = partial;
            break;
        }

        if (s.n < sizeof(s.value.mbytes))
        {
            s.value.mbytes[s.n++] = *fromNext++;
        }

        uint8_t* fnext = reinterpret_cast<uint8_t *>(&s.value.mbytes[0]);
        uint8_t* fend = fnext + s.n;

        const size_t extraBytesToRead = trailingBytesForUTF8[*fnext];
        if (fnext + extraBytesToRead >= fend)
        {
            retstat = partial;
            break;
        }

        if( !isLegalUTF8( fnext, extraBytesToRead + 1 ) )
        {
            retstat = error;
            break;
        }

        *toNext = Char(0);
        switch (extraBytesToRead)
        {
            case 5: *toNext = Char((toNext->value() + *fnext++) << 6); // We should never get this for legal UTF-8
            case 4: *toNext = Char((toNext->value() + *fnext++) << 6); // We should never get this for legal UTF-8
            case 3: *toNext = Char((toNext->value() + *fnext++) << 6);
            case 2: *toNext = Char((toNext->value() + *fnext++) << 6);
            case 1: *toNext = Char((toNext->value() + *fnext++) << 6);
            case 0: *toNext = Char((toNext->value() + *fnext++));
        }

        *toNext = Char(toNext->value() - offsetsFromUTF8[extraBytesToRead]);

        // UTF-16 surrogate values are illegal in UTF-32, and anything
        // over Plane 17 (> 0x10FFFF) is illegal.
        if (*toNext > MaxLegalUtf32)
        {
            *toNext = ReplacementChar;
        }
        else if(*toNext >= SurHighStart && *toNext <= SurLowEnd)
        {
            *toNext = ReplacementChar;
        }

        s.n = 0;
        ++toNext;
    }

    return retstat;
}