def METHOD_NAME(shape, num_channels, quality):
  import simplejpeg
  xshape = list(shape) + [ num_channels ]
  data = np.zeros(shape=xshape, dtype=np.uint8)
  encode_decode(data, 'jpeg', shape, num_channels, level=quality)
  encode_decode(data + 255, 'jpeg', shape, num_channels, level=quality)
  jpg = simplejpeg.decode_jpeg(
    encode(data, 'jpeg', compression_params={ "level": quality }), 
    colorspace="GRAY",
  )
  assert jpg.shape[0] == shape[1] * shape[2]
  assert jpg.shape[1] == shape[0]
  # Random jpeg won't decompress to exactly the same image
  # but it should have nearly the same average power
  random_data = np.random.randint(255, size=xshape, dtype=np.uint8)
  pre_avg = random_data.copy().flatten().mean()
  encoded = encode(random_data, 'jpeg')
  decoded = decode(encoded, 'jpeg', shape=xshape, dtype=np.uint8)
  post_avg = decoded.copy().flatten().mean()
  assert abs(pre_avg - post_avg) < 1