Skip to content

Commit

Permalink
将Y轴修改为并行处理
Browse files Browse the repository at this point in the history
  • Loading branch information
Puiching-Memory committed Feb 2, 2025
1 parent 6a6445f commit 94bb7a7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
include_dirs=["./libde265/build/", "./libde265/libde265/", np.get_include()],
library_dirs=["./libde265/build/libde265/Release/"],
libraries=["de265"],
extra_compile_args=["/openmp"] # only for Windows
)
]

Expand Down
15 changes: 12 additions & 3 deletions src/pylibde265/pyde265.pyx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from libc.stdint cimport uint32_t,int64_t,uint8_t
from libc.stdio cimport printf
from cython.parallel import prange
import numpy as np
cimport numpy as cnp
from scipy.ndimage import zoom
Expand Down Expand Up @@ -53,6 +54,7 @@ cdef class decoder(object):
cdef const uint8_t* bufferCr = NULL
cdef int ystride = 0, cstride = 0
cdef cnp.ndarray image
cdef unsigned char[:, :, ::1] image_view
cdef int i, j

while more > 0:
Expand Down Expand Up @@ -92,14 +94,21 @@ cdef class decoder(object):
bufferCb = pyde265.de265_get_image_plane(image_ptr,1,&cstride)
bufferCr = pyde265.de265_get_image_plane(image_ptr,2,&cstride)

planeY = np.frombuffer(bufferY[0:self.h*self.w], dtype='uint8').reshape((self.h, self.w))
image = np.empty((self.h, self.w, 3), dtype=np.uint8)
image_view = image

for i in prange(self.h, nogil=True,schedule='guided'):
for j in range(self.w):
image_view[i, j, 0] = bufferY[i * ystride + j]

# planeY = np.frombuffer(bufferY[0:self.h*self.w], dtype='uint8').reshape((self.h, self.w))
planeCb = np.frombuffer(bufferCb[0:self.hC*self.wC], dtype='uint8').reshape((self.hC, self.wC))
planeCb = zoom(planeCb,(self.w//self.wC,self.h//self.hC),order=0)
planeCr = np.frombuffer(bufferCr[0:self.hC*self.wC], dtype='uint8').reshape((self.hC, self.wC))
planeCr = zoom(planeCr,(self.w//self.wC,self.h//self.hC),order=0)

image = np.empty((self.h, self.w, 3), dtype=np.uint8)
image[:, :, 0] = planeY

# image[:, :, 0] = planeY
image[:, :, 1] = planeCb
image[:, :, 2] = planeCr

Expand Down

0 comments on commit 94bb7a7

Please sign in to comment.