From 37ab0353702bd90efeae15ff1126be9c8a1b790c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Wed, 19 Feb 2025 20:54:39 +0100 Subject: [PATCH] Image, Audio, Pygame --- README.md | 6 +++--- index.html | 6 +++--- parse.js | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 879c3a0..d3321c7 100644 --- a/README.md +++ b/README.md @@ -2799,7 +2799,7 @@ from PIL import Image ### Modes * **`'L'` - Lightness (greyscale image). Each pixel is an int between 0 and 255.** * **`'RGB'` - Red, green, blue (true color image). Each pixel is a tuple of three ints.** -* **`'RGBA'` - RGB with alpha. Low alpha (i.e. forth int) makes pixels more transparent.** +* **`'RGBA'` - RGB with alpha. Low alpha (i.e. forth int) makes pixel more transparent.** * **`'HSV'` - Hue, saturation, value. Three ints representing color in HSV color space.** @@ -2874,7 +2874,7 @@ import wave = .getnchannels() # Returns number of samples per frame. = .getsampwidth() # Returns number of bytes per sample. = .getparams() # Returns namedtuple of all parameters. - = .readframes(nframes) # Returns next n frames (-1 returns all). + = .readframes(nframes) # Returns all frames if -1 is passed. ``` ```python @@ -2919,7 +2919,7 @@ def read_wav_file(filename): def write_to_wav_file(filename, samples_f, p=None, nchannels=1, sampwidth=2, framerate=44100): def get_bytes(a_float): a_float = max(-1, min(1 - 2e-16, a_float)) - a_float += p.sampwidth == 1 + a_float += (p.sampwidth == 1) a_float *= pow(2, (p.sampwidth * 8) - 1) return int(a_float).to_bytes(p.sampwidth, 'little', signed=(p.sampwidth != 1)) if p is None: diff --git a/index.html b/index.html index eaeee48..13d8668 100644 --- a/index.html +++ b/index.html @@ -2290,7 +2290,7 @@ right = np.array([[0.1, Modes
  • 'L' - Lightness (greyscale image). Each pixel is an int between 0 and 255.
  • 'RGB' - Red, green, blue (true color image). Each pixel is a tuple of three ints.
  • -
  • 'RGBA' - RGB with alpha. Low alpha (i.e. forth int) makes pixels more transparent.
  • +
  • 'RGBA' - RGB with alpha. Low alpha (i.e. forth int) makes pixel more transparent.
  • 'HSV' - Hue, saturation, value. Three ints representing color in HSV color space.

Examples

Creates a PNG image of a rainbow gradient:

WIDTH, HEIGHT = 100, 100
 n_pixels = WIDTH * HEIGHT
@@ -2352,7 +2352,7 @@ imageio.mimsave('test.gif', frames, duration=# Returns number of samples per frame.
 <int>   = <Wave>.getsampwidth()       # Returns number of bytes per sample.
 <tuple> = <Wave>.getparams()          # Returns namedtuple of all parameters.
-<bytes> = <Wave>.readframes(nframes)  # Returns next n frames (-1 returns all).
+<bytes> = <Wave>.readframes(nframes)  # Returns all frames if -1 is passed.
 
<Wave> = wave.open('<path>', 'wb')    # Creates/truncates a file for writing.
 <Wave>.setframerate(<int>)            # Pass 44100 for CD, 48000 for video.
@@ -2390,7 +2390,7 @@ imageio.mimsave('test.gif', frames, duration=

Write Float Samples to WAV File

def write_to_wav_file(filename, samples_f, p=None, nchannels=1, sampwidth=2, framerate=44100):
     def get_bytes(a_float):
         a_float = max(-1, min(1 - 2e-16, a_float))
-        a_float += p.sampwidth == 1
+        a_float += (p.sampwidth == 1)
         a_float *= pow(2, (p.sampwidth * 8) - 1)
         return int(a_float).to_bytes(p.sampwidth, 'little', signed=(p.sampwidth != 1))
     if p is None:
diff --git a/parse.js b/parse.js
index ec7fa74..7a1a3fd 100755
--- a/parse.js
+++ b/parse.js
@@ -215,7 +215,7 @@ const AUDIO_1 =
   'def write_to_wav_file(filename, samples_f, p=None, nchannels=1, sampwidth=2, framerate=44100):\n' +
   '    def get_bytes(a_float):\n' +
   '        a_float = max(-1, min(1 - 2e-16, a_float))\n' +
-  '        a_float += p.sampwidth == 1\n' +
+  '        a_float += (p.sampwidth == 1)\n' +
   '        a_float *= pow(2, (p.sampwidth * 8) - 1)\n' +
   '        return int(a_float).to_bytes(p.sampwidth, \'little\', signed=(p.sampwidth != 1))\n' +
   '    if p is None:\n' +