Ejemplo n.º 1
0
    static WinString ToCanvasTrimmingDelimiter(uint32_t value)
    {
        // TODO #1658: Do the unicode conversion properly.
        // http://www.unicode.org/faq/utf_bom.html#utf16-3.  This code needs its
        // own set of tests.

        WinStringBuilder builder;

        if (value == 0)
        {
            return WinString();
        }
        else if (value <= 0x0000FFFF)
        {
            auto buffer = builder.Allocate(1);
            buffer[0] = static_cast<wchar_t>(value);
        }
        else
        {
            auto buffer = builder.Allocate(2);
            *(reinterpret_cast<uint32_t*>(buffer)) = value;
        }

        return builder.Get();
    }
Ejemplo n.º 2
0
 static WinString GetLocaleName(IDWriteTextFormat* format)
 {
     WinStringBuilder stringBuilder;
     auto length = format->GetLocaleNameLength() + 1;
     auto buffer = stringBuilder.Allocate(length);
     ThrowIfFailed(format->GetLocaleName(buffer, length));
     return stringBuilder.Get();
 }
Ejemplo n.º 3
0
    void SetPixelColorsImpl(
        ComPtr<ID2D1Bitmap1> const& d2dBitmap,
        D2D1_RECT_U const& subRectangle,
        uint32_t valueCount,
        Color *valueElements)
    {
        CheckInPointer(valueElements);

        VerifyWellFormedSubrectangle(subRectangle, d2dBitmap->GetPixelSize());

        const unsigned int subRectangleWidth = subRectangle.right - subRectangle.left;
        const unsigned int subRectangleHeight = subRectangle.bottom - subRectangle.top;

        const uint32_t expectedArraySize = subRectangleWidth * subRectangleHeight;
        if (valueCount != expectedArraySize)
        {
            WinStringBuilder message;
            message.Format(Strings::WrongArrayLength, expectedArraySize, valueCount);
            ThrowHR(E_INVALIDARG, message.Get());
        }

        if (d2dBitmap->GetPixelFormat().format != DXGI_FORMAT_B8G8R8A8_UNORM)
        {
            ThrowHR(E_INVALIDARG, Strings::PixelColorsFormatRestriction);
        }

        ScopedBitmapMappedPixelAccess bitmapPixelAccess(d2dBitmap.Get(), D3D11_MAP_WRITE, &subRectangle);

        const unsigned int destSizeInPixels = subRectangleWidth * subRectangleHeight;
        ComArray<Color> array(destSizeInPixels);

        byte* destRowStart = static_cast<byte*>(bitmapPixelAccess.GetLockedData());

        for (unsigned int y = 0; y < subRectangleHeight; y++)
        {
            for (unsigned int x = 0; x < subRectangleWidth; x++)
            {
                uint32_t* destPixel = reinterpret_cast<uint32_t*>(&destRowStart[x * 4]);
                Color& sourceColor = valueElements[y * subRectangleWidth + x];
                *destPixel = 
                    (static_cast<uint32_t>(sourceColor.B) << 0) | 
                    (static_cast<uint32_t>(sourceColor.G) << 8) |
                    (static_cast<uint32_t>(sourceColor.R) << 16) |
                    (static_cast<uint32_t>(sourceColor.A) << 24);
            }
            destRowStart += bitmapPixelAccess.GetStride();
        }
    }
Ejemplo n.º 4
0
    void SetPixelBytesImpl(
        ComPtr<ID2D1Bitmap1> const& d2dBitmap,
        D2D1_RECT_U const& subRectangle,
        uint32_t valueCount,
        uint8_t* valueElements)
    {
        CheckInPointer(valueElements);

        VerifyWellFormedSubrectangle(subRectangle, d2dBitmap->GetPixelSize());

        const unsigned int subRectangleWidth = subRectangle.right - subRectangle.left;
        const unsigned int subRectangleHeight = subRectangle.bottom - subRectangle.top;

        const unsigned int bytesPerPixel = GetBytesPerPixel(d2dBitmap->GetPixelFormat().format);
        const unsigned int bytesPerRow = bytesPerPixel * subRectangleWidth;
        uint32_t expectedArraySize = subRectangleWidth * subRectangleHeight * bytesPerPixel;
        if (valueCount != expectedArraySize)
        {
            WinStringBuilder message;
            message.Format(Strings::WrongArrayLength, expectedArraySize, valueCount);
            ThrowHR(E_INVALIDARG, message.Get());
        }

        ScopedBitmapMappedPixelAccess bitmapPixelAccess(d2dBitmap.Get(), D3D11_MAP_WRITE, &subRectangle);

        byte* destRowStart = static_cast<byte*>(bitmapPixelAccess.GetLockedData());
        byte* sourceRowStart = valueElements;

        for (unsigned int y = subRectangle.top; y < subRectangle.bottom; y++)
        {
            const unsigned int byteCount = (subRectangle.right - subRectangle.left) * bytesPerPixel;
            const unsigned int positionInBuffer = static_cast<unsigned int>(sourceRowStart - valueElements);
            const unsigned int bytesLeftInBuffer = valueCount - positionInBuffer;

            memcpy_s(destRowStart, bytesLeftInBuffer, sourceRowStart, byteCount);

            destRowStart += bitmapPixelAccess.GetStride();
            sourceRowStart += bytesPerRow;
        }
    }