<!--
{
  "availability" : [
    "iOS: 7.0.0 -",
    "iPadOS: 7.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.9.0 -",
    "tvOS: 7.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Accelerate",
  "identifier" : "/documentation/Accelerate/vImageConvert_RGB16UtoRGBA16U(_:_:_:_:_:_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Function",
  "symbol" : {
    "kind" : "Function",
    "modules" : [
      "Accelerate"
    ],
    "preciseIdentifier" : "c:@F@vImageConvert_RGB16UtoRGBA16U"
  },
  "title" : "vImageConvert_RGB16UtoRGBA16U(_:_:_:_:_:_:)"
}
-->

# vImageConvert_RGB16UtoRGBA16U(_:_:_:_:_:_:)

Combines an unsigned 16-bit-per-channel, 3-channel RGB buffer and either an unsigned 16-bit alpha buffer or constant alpha value to produce an RGBA result.

```
func vImageConvert_RGB16UtoRGBA16U(_ rgbSrc: UnsafePointer<vImage_Buffer>, _ aSrc: UnsafePointer<vImage_Buffer>!, _ alpha: Pixel_16U, _ rgbaDest: UnsafePointer<vImage_Buffer>, _ premultiply: Bool, _ flags: vImage_Flags) -> vImage_Error
```

## Parameters

`rgbSrc`

The source vImage buffer that contains the red, green, and blue channels.

`aSrc`

The source vImage buffer that contains the alpha channel. Set this value to `nil` to specify that the function sets the destination alpha as the constant destination alpha value.

`alpha`

The constant destination alpha value. The function ignores this paramater if the `aSrc` parameter isn’t `nil`.

`rgbaDest`

A pointer to the destination vImage buffer structure. You’re responsible for filling out the [`height`](/documentation/Accelerate/vImage_Buffer/height), [`width`](/documentation/Accelerate/vImage_Buffer/width), and [`rowBytes`](/documentation/Accelerate/vImage_Buffer/rowBytes) fields of this structure, and for allocating a data buffer of the appropriate size. On return, the data buffer this structure points to contains the destination image data. When you no longer need the data buffer, deallocate the memory to prevent memory leaks.

`premultiply`

A Boolean value that specifes whether the function premultiplies the color channels by the alpha channel.

`flags`

The options to use when performing the operation. If your code implements its own tiling or its own multithreading, pass [`kvImageDoNotTile`](/documentation/Accelerate/kvImageDoNotTile); otherwise, pass [`kvImageNoFlags`](/documentation/Accelerate/kvImageNoFlags).

## Return Value

[`kvImageNoError`](/documentation/Accelerate/kvImageNoError); otherwise, one of the error codes in <doc://com.apple.documentation/documentation/Accelerate/data-types-and-constants>.

## Discussion

The function uses the following calculation to perform the conversion:

```c
if (aSrc != NULL)
 {
    if (premultiply)
    {
        r = (aSrc[i] * rgb[i*3+0] + 32767) / 65535
        g = (aSrc[i] * rgb[i*3+1] + 32767) / 65535
        b = (aSrc[i] * rgb[i*3+2] + 32767) / 65535
        rgbaDest[i*4+3] = aSrc[i];
        rgbaDest[i*4+0] = r;
        rgbaDest[i*4+1] = g;
        rgbaDest[i*4+2] = b;
    }
    else
    {
        rgbaDest[i*4+3] = aSrc[i];
        rgbaDest[i*4+0] = rgb[i*3+0];
        rgbaDest[i*4+1] = rgb[i*3+1];
        rgbaDest[i*4+2] = rgb[i*3+2];
    }
 }
 else
 {
    if (premultiply)
    {
        r = (alpha * rgb[i*3+0] + 32767) / 65535
        g = (alpha * rgb[i*3+1] + 32767) / 65535
        b = (alpha * rgb[i*3+2] + 32767) / 65535
        rgbaDest[i*4+3] = alpha;
        rgbaDest[i*4+0] = r;
        rgbaDest[i*4+1] = g;
        rgbaDest[i*4+1] = b;
    }
    else
    {
        rgbaDest[i*4+3] = alpha;
        rgbaDest[i*4+0] = rgb[i*3+0];
        rgbaDest[i*4+1] = rgb[i*3+1];
        rgbaDest[i*4+2] = rgb[i*3+2];
    }
 }
```

This function doesn’t operate in place.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)