| 1557 | |
| 1558 | #if SDL_HAVE_YUV |
| 1559 | static int |
| 1560 | SDL_UpdateTextureYUVPlanar(SDL_Texture * texture, const SDL_Rect * rect, |
| 1561 | const Uint8 *Yplane, int Ypitch, |
| 1562 | const Uint8 *Uplane, int Upitch, |
| 1563 | const Uint8 *Vplane, int Vpitch) |
| 1564 | { |
| 1565 | SDL_Texture *native = texture->native; |
| 1566 | SDL_Rect full_rect; |
| 1567 | |
| 1568 | if (SDL_SW_UpdateYUVTexturePlanar(texture->yuv, rect, Yplane, Ypitch, Uplane, Upitch, Vplane, Vpitch) < 0) { |
| 1569 | return -1; |
| 1570 | } |
| 1571 | |
| 1572 | full_rect.x = 0; |
| 1573 | full_rect.y = 0; |
| 1574 | full_rect.w = texture->w; |
| 1575 | full_rect.h = texture->h; |
| 1576 | rect = &full_rect; |
| 1577 | |
| 1578 | if (!rect->w || !rect->h) { |
| 1579 | return 0; /* nothing to do. */ |
| 1580 | } |
| 1581 | |
| 1582 | if (texture->access == SDL_TEXTUREACCESS_STREAMING) { |
| 1583 | /* We can lock the texture and copy to it */ |
| 1584 | void *native_pixels = NULL; |
| 1585 | int native_pitch = 0; |
| 1586 | |
| 1587 | if (SDL_LockTexture(native, rect, &native_pixels, &native_pitch) < 0) { |
| 1588 | return -1; |
| 1589 | } |
| 1590 | SDL_SW_CopyYUVToRGB(texture->yuv, rect, native->format, |
| 1591 | rect->w, rect->h, native_pixels, native_pitch); |
| 1592 | SDL_UnlockTexture(native); |
| 1593 | } else { |
| 1594 | /* Use a temporary buffer for updating */ |
| 1595 | const int temp_pitch = (((rect->w * SDL_BYTESPERPIXEL(native->format)) + 3) & ~3); |
| 1596 | const size_t alloclen = rect->h * temp_pitch; |
| 1597 | if (alloclen > 0) { |
| 1598 | void *temp_pixels = SDL_malloc(alloclen); |
| 1599 | if (!temp_pixels) { |
| 1600 | return SDL_OutOfMemory(); |
| 1601 | } |
| 1602 | SDL_SW_CopyYUVToRGB(texture->yuv, rect, native->format, |
| 1603 | rect->w, rect->h, temp_pixels, temp_pitch); |
| 1604 | SDL_UpdateTexture(native, rect, temp_pixels, temp_pitch); |
| 1605 | SDL_free(temp_pixels); |
| 1606 | } |
| 1607 | } |
| 1608 | return 0; |
| 1609 | } |
| 1610 | #endif /* SDL_HAVE_YUV */ |
| 1611 | |
| 1612 | int SDL_UpdateYUVTexture(SDL_Texture * texture, const SDL_Rect * rect, |
no test coverage detected