Skip to content
This repository has been archived by the owner on Jun 10, 2024. It is now read-only.

Commit

Permalink
Merging from master into on_gpu_buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
rarzumanyan committed Sep 20, 2021
2 parents 4abd97c + b896bef commit dc64956
Show file tree
Hide file tree
Showing 6 changed files with 528 additions and 9 deletions.
74 changes: 73 additions & 1 deletion PyNvCodec/TC/inc/MemoryInterfaces.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/*
* Copyright 2019 NVIDIA Corporation
* Copyright 2021 Videonetics Technology Private Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
Expand Down Expand Up @@ -31,6 +33,8 @@ enum Pixel_Format {
BGR = 6,
YCBCR = 7,
YUV444 = 8,
RGB_32F = 9,
RGB_32F_PLANAR = 10,
};

enum ColorSpace {
Expand Down Expand Up @@ -565,4 +569,72 @@ class DllExport SurfaceYUV444 : public SurfaceRGBPlanar {
bool DllExport CheckAllocationCounters();
#endif

} // namespace VPF
/* 32-bit float RGB image;
*/
class DllExport SurfaceRGB32F : public Surface {
public:
~SurfaceRGB32F();

SurfaceRGB32F();
SurfaceRGB32F(const SurfaceRGB32F &other);
SurfaceRGB32F(uint32_t width, uint32_t height, CUcontext context);
SurfaceRGB32F &operator=(const SurfaceRGB32F &other);

Surface *Clone() override;
Surface *Create() override;

uint32_t Width(uint32_t planeNumber = 0U) const override;
uint32_t WidthInBytes(uint32_t planeNumber = 0U) const override;
uint32_t Height(uint32_t planeNumber = 0U) const override;
uint32_t Pitch(uint32_t planeNumber = 0U) const override;
uint32_t HostMemSize() const override;

CUdeviceptr PlanePtr(uint32_t planeNumber = 0U) override;
Pixel_Format PixelFormat() const override { return RGB_32F; }
uint32_t NumPlanes() const override { return 1; }
virtual uint32_t ElemSize() const override { return sizeof(float); }
bool Empty() const override { return 0UL == plane.GpuMem(); }

void Update(const SurfacePlane &newPlane);
bool Update(SurfacePlane *pPlanes, size_t planesNum) override;
SurfacePlane *GetSurfacePlane(uint32_t planeNumber = 0U) override;

protected:
SurfacePlane plane;
};

/* 32-bit float planar RGB image;
*/
class DllExport SurfaceRGB32FPlanar : public Surface {
public:
~SurfaceRGB32FPlanar();

SurfaceRGB32FPlanar();
SurfaceRGB32FPlanar(const SurfaceRGB32FPlanar &other);
SurfaceRGB32FPlanar(uint32_t width, uint32_t height, CUcontext context);
SurfaceRGB32FPlanar &operator=(const SurfaceRGB32FPlanar &other);

virtual Surface *Clone() override;
virtual Surface *Create() override;

uint32_t Width(uint32_t planeNumber = 0U) const override;
uint32_t WidthInBytes(uint32_t planeNumber = 0U) const override;
uint32_t Height(uint32_t planeNumber = 0U) const override;
uint32_t Pitch(uint32_t planeNumber = 0U) const override;
uint32_t HostMemSize() const override;

CUdeviceptr PlanePtr(uint32_t planeNumber = 0U) override;
Pixel_Format PixelFormat() const override { return RGB_32F_PLANAR; }
uint32_t NumPlanes() const override { return 3; }
virtual uint32_t ElemSize() const override { return sizeof(float); }
bool Empty() const override { return 0UL == plane.GpuMem(); }

void Update(const SurfacePlane &newPlane);
bool Update(SurfacePlane *pPlanes, size_t planesNum) override;
SurfacePlane *GetSurfacePlane(uint32_t planeNumber = 0U) override;

protected:
SurfacePlane plane;
};

} // namespace VPF
166 changes: 166 additions & 0 deletions PyNvCodec/TC/src/MemoryInterfaces.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/*
* Copyright 2019 NVIDIA Corporation
* Copyright 2021 Videonetics Technology Private Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
Expand Down Expand Up @@ -498,6 +500,10 @@ Surface *Surface::Make(Pixel_Format format) {
return new SurfaceYCbCr;
case YUV444:
return new SurfaceYUV444;
case RGB_32F:
return new SurfaceRGB32F;
case RGB_32F_PLANAR:
return new SurfaceRGB32FPlanar;
default:
return nullptr;
}
Expand All @@ -522,6 +528,10 @@ Surface *Surface::Make(Pixel_Format format, uint32_t newWidth,
return new SurfaceYCbCr(newWidth, newHeight, context);
case YUV444:
return new SurfaceYUV444(newWidth, newHeight, context);
case RGB_32F:
return new SurfaceRGB32F(newWidth, newHeight, context);
case RGB_32F_PLANAR:
return new SurfaceRGB32FPlanar(newWidth, newHeight, context);
default:
return nullptr;
}
Expand Down Expand Up @@ -1070,3 +1080,159 @@ SurfaceYUV444::SurfaceYUV444(uint32_t width, uint32_t height, CUcontext context)
Surface *VPF::SurfaceYUV444::Clone() { return new SurfaceYUV444(*this); }

Surface *VPF::SurfaceYUV444::Create() { return new SurfaceYUV444; }

SurfaceRGB32F::~SurfaceRGB32F() = default;

SurfaceRGB32F::SurfaceRGB32F() = default;

SurfaceRGB32F::SurfaceRGB32F(const SurfaceRGB32F &other) : plane(other.plane) {}

SurfaceRGB32F::SurfaceRGB32F(uint32_t width, uint32_t height, CUcontext context)
: plane(width * 3, height, ElemSize(), context) {}

SurfaceRGB32F &SurfaceRGB32F::operator=(const SurfaceRGB32F &other) {
plane = other.plane;
return *this;
}

Surface *SurfaceRGB32F::Clone() { return new SurfaceRGB32F(*this); }

Surface *SurfaceRGB32F::Create() { return new SurfaceRGB32F; }

uint32_t SurfaceRGB32F::Width(uint32_t planeNumber) const {
if (planeNumber < NumPlanes()) {
return plane.Width() / 3;
}

throw invalid_argument("Invalid plane number");
}

uint32_t SurfaceRGB32F::WidthInBytes(uint32_t planeNumber) const {
if (planeNumber < NumPlanes()) {
return plane.Width() * plane.ElemSize();
}

throw invalid_argument("Invalid plane number");
}

uint32_t SurfaceRGB32F::Height(uint32_t planeNumber) const {
if (planeNumber < NumPlanes()) {
return plane.Height();
}

throw invalid_argument("Invalid plane number");
}

uint32_t SurfaceRGB32F::Pitch(uint32_t planeNumber) const {
if (planeNumber < NumPlanes()) {
return plane.Pitch();
}

throw invalid_argument("Invalid plane number");
}

uint32_t SurfaceRGB32F::HostMemSize() const { return plane.GetHostMemSize(); }

CUdeviceptr SurfaceRGB32F::PlanePtr(uint32_t planeNumber) {
if (planeNumber < NumPlanes()) {
return plane.GpuMem();
}

throw invalid_argument("Invalid plane number");
}

void SurfaceRGB32F::Update(const SurfacePlane &newPlane) { plane = newPlane; }

bool SurfaceRGB32F::Update(SurfacePlane *pPlanes, size_t planesNum) {
if (pPlanes && 1 == planesNum && !plane.OwnMemory()) {
plane = *pPlanes;
return true;
}

return false;
}

SurfacePlane *SurfaceRGB32F::GetSurfacePlane(uint32_t planeNumber) {
return planeNumber ? nullptr : &plane;
}

SurfaceRGB32FPlanar::~SurfaceRGB32FPlanar() = default;

SurfaceRGB32FPlanar::SurfaceRGB32FPlanar() = default;

SurfaceRGB32FPlanar::SurfaceRGB32FPlanar(const SurfaceRGB32FPlanar &other)
: plane(other.plane) {}

SurfaceRGB32FPlanar::SurfaceRGB32FPlanar(uint32_t width, uint32_t height,
CUcontext context)
: plane(width, height * 3, ElemSize(), context) {}

SurfaceRGB32FPlanar &SurfaceRGB32FPlanar::operator=(const SurfaceRGB32FPlanar &other) {
plane = other.plane;
return *this;
}

Surface *SurfaceRGB32FPlanar::Clone() { return new SurfaceRGB32FPlanar(*this); }

Surface *SurfaceRGB32FPlanar::Create() { return new SurfaceRGB32FPlanar; }

uint32_t SurfaceRGB32FPlanar::Width(uint32_t planeNumber) const {
if (planeNumber < NumPlanes()) {
return plane.Width();
}

throw invalid_argument("Invalid plane number");
}

uint32_t SurfaceRGB32FPlanar::WidthInBytes(uint32_t planeNumber) const {
if (planeNumber < NumPlanes()) {
return plane.Width() * plane.ElemSize();
}

throw invalid_argument("Invalid plane number");
}

uint32_t SurfaceRGB32FPlanar::Height(uint32_t planeNumber) const {
if (planeNumber < NumPlanes()) {
return plane.Height() / 3;
}

throw invalid_argument("Invalid plane number");
}

uint32_t SurfaceRGB32FPlanar::Pitch(uint32_t planeNumber) const {
if (planeNumber < NumPlanes()) {
return plane.Pitch();
}

throw invalid_argument("Invalid plane number");
}

uint32_t SurfaceRGB32FPlanar::HostMemSize() const {
return plane.GetHostMemSize();
}

CUdeviceptr SurfaceRGB32FPlanar::PlanePtr(uint32_t planeNumber) {
if (planeNumber < NumPlanes()) {
return plane.GpuMem() + planeNumber * Height() * plane.Pitch();
}

throw invalid_argument("Invalid plane number");
}

void SurfaceRGB32FPlanar::Update(const SurfacePlane &newPlane) {
plane = newPlane;
}

bool SurfaceRGB32FPlanar::Update(SurfacePlane *pPlanes, size_t planesNum) {
if (pPlanes && 1 == planesNum && !plane.OwnMemory()) {
plane = *pPlanes;
return true;
}

return false;
}

SurfacePlane *SurfaceRGB32FPlanar::GetSurfacePlane(uint32_t planeNumber) {
return planeNumber ? nullptr : &plane;
}
Loading

0 comments on commit dc64956

Please sign in to comment.