PyTurboJPEG 2.2.0__tar.gz → 2.3.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: PyTurboJPEG
3
- Version: 2.2.0
3
+ Version: 2.3.0
4
4
  Summary: A Python wrapper of libjpeg-turbo for decoding and encoding JPEG image.
5
5
  Home-page: https://github.com/lilohuang/PyTurboJPEG
6
6
  Author: Lilo Huang
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: PyTurboJPEG
3
- Version: 2.2.0
3
+ Version: 2.3.0
4
4
  Summary: A Python wrapper of libjpeg-turbo for decoding and encoding JPEG image.
5
5
  Home-page: https://github.com/lilohuang/PyTurboJPEG
6
6
  Author: Lilo Huang
@@ -2,7 +2,7 @@ import io
2
2
  from setuptools import setup, find_packages
3
3
  setup(
4
4
  name='PyTurboJPEG',
5
- version='2.2.0',
5
+ version='2.3.0',
6
6
  description='A Python wrapper of libjpeg-turbo for decoding and encoding JPEG image.',
7
7
  author='Lilo Huang',
8
8
  author_email='kuso.cc@gmail.com',
@@ -23,7 +23,7 @@
23
23
  # SOFTWARE.
24
24
 
25
25
  __author__ = 'Lilo Huang <kuso.cc@gmail.com>'
26
- __version__ = '2.2.0'
26
+ __version__ = '2.3.0'
27
27
 
28
28
  from ctypes import *
29
29
  from ctypes.util import find_library
@@ -305,12 +305,12 @@ def fill_background(coeffs_ptr, arrayRegion, planeRegion, componentID, transform
305
305
  min(arrayRegion.y+arrayRegion.h, background_data.h)
306
306
  - arrayRegion.y
307
307
  )
308
- for x in range(background_data.w//MCU_WIDTH, planeRegion.w//MCU_WIDTH):
309
- for y in range(
310
- left_start_row//MCU_HEIGHT,
311
- left_end_row//MCU_HEIGHT
312
- ):
313
- coeffs[y][x][0] = background_data.lum
308
+ y_start = left_start_row // MCU_HEIGHT
309
+ y_end = left_end_row // MCU_HEIGHT
310
+ x_start = background_data.w // MCU_WIDTH
311
+ x_end = planeRegion.w // MCU_WIDTH
312
+ if y_end > y_start and x_end > x_start:
313
+ coeffs[y_start:y_end, x_start:x_end, 0] = background_data.lum
314
314
 
315
315
  # fill mcus under image
316
316
  bottom_start_row = (
@@ -320,12 +320,11 @@ def fill_background(coeffs_ptr, arrayRegion, planeRegion, componentID, transform
320
320
  max(arrayRegion.y+arrayRegion.h, background_data.h)
321
321
  - arrayRegion.y
322
322
  )
323
- for x in range(0, planeRegion.w//MCU_WIDTH):
324
- for y in range(
325
- bottom_start_row//MCU_HEIGHT,
326
- bottom_end_row//MCU_HEIGHT
327
- ):
328
- coeffs[y][x][0] = background_data.lum
323
+ y_start = bottom_start_row // MCU_HEIGHT
324
+ y_end = bottom_end_row // MCU_HEIGHT
325
+ x_end = planeRegion.w // MCU_WIDTH
326
+ if y_end > y_start and x_end > 0:
327
+ coeffs[y_start:y_end, 0:x_end, 0] = background_data.lum
329
328
 
330
329
  return 1
331
330
 
@@ -1311,6 +1310,8 @@ class TurboJPEG(object):
1311
1310
 
1312
1311
  # Define crop transforms from cropping_regions
1313
1312
  crop_transforms = (TransformStruct * number_of_operations)()
1313
+ # Pre-compute luminance coefficient once for all crops
1314
+ lum_coefficient = None
1314
1315
  for i, crop_region in enumerate(crop_regions):
1315
1316
  # The fill_background callback is slow, only use it if needed
1316
1317
  if self.__need_fill_background(
@@ -1318,14 +1319,16 @@ class TurboJPEG(object):
1318
1319
  (image_width, image_height),
1319
1320
  background_luminance
1320
1321
  ):
1322
+ if lum_coefficient is None:
1323
+ lum_coefficient = self.__map_luminance_to_dc_dct_coefficient(
1324
+ bytearray(jpeg_buf),
1325
+ background_luminance
1326
+ )
1321
1327
  # Use callback to fill in background post-transform
1322
1328
  callback_data = BackgroundStruct(
1323
1329
  image_width,
1324
1330
  image_height,
1325
- self.__map_luminance_to_dc_dct_coefficient(
1326
- bytearray(jpeg_buf),
1327
- background_luminance
1328
- )
1331
+ lum_coefficient
1329
1332
  )
1330
1333
  callback = CUSTOMFILTER(fill_background)
1331
1334
  crop_transforms[i] = TransformStruct(
@@ -1350,7 +1353,6 @@ class TurboJPEG(object):
1350
1353
 
1351
1354
  def buffer_size(self, img_array, jpeg_subsample=TJSAMP_422):
1352
1355
  """Get maximum number of bytes of compressed jpeg data"""
1353
- img_array = np.ascontiguousarray(img_array)
1354
1356
  height, width = img_array.shape[:2]
1355
1357
  return self.__buffer_size(width, height, jpeg_subsample)
1356
1358
 
File without changes
File without changes
File without changes