From ba86d90a009621c052e0f268bb0062932b2096f3 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Wed, 12 Jan 2022 15:17:04 +1100 Subject: [PATCH 1/2] Simplified code --- src/PIL/SpiderImagePlugin.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/PIL/SpiderImagePlugin.py b/src/PIL/SpiderImagePlugin.py index 062af9f98..061efe8ec 100644 --- a/src/PIL/SpiderImagePlugin.py +++ b/src/PIL/SpiderImagePlugin.py @@ -238,14 +238,14 @@ def makeSpiderHeader(im): if 1024 % lenbyt != 0: labrec += 1 labbyt = labrec * lenbyt - hdr = [] nvalues = int(labbyt / 4) + if nvalues < 23: + return [] + + hdr = [] for i in range(nvalues): hdr.append(0.0) - if len(hdr) < 23: - return [] - # NB these are Fortran indices hdr[1] = 1.0 # nslice (=1 for an image) hdr[2] = float(nrow) # number of rows per slice @@ -259,10 +259,7 @@ def makeSpiderHeader(im): hdr = hdr[1:] hdr.append(0.0) # pack binary data into a string - hdrstr = [] - for v in hdr: - hdrstr.append(struct.pack("f", v)) - return hdrstr + return [struct.pack("f", v) for v in hdr] def _save(im, fp, filename): From a9441a475d4c4133f161b7927352b4bda5cc9b6f Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Wed, 12 Jan 2022 17:29:25 +1100 Subject: [PATCH 2/2] Added IREC header entry for use with Bio-formats library --- src/PIL/SpiderImagePlugin.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/PIL/SpiderImagePlugin.py b/src/PIL/SpiderImagePlugin.py index 061efe8ec..11c706b4d 100644 --- a/src/PIL/SpiderImagePlugin.py +++ b/src/PIL/SpiderImagePlugin.py @@ -249,6 +249,7 @@ def makeSpiderHeader(im): # NB these are Fortran indices hdr[1] = 1.0 # nslice (=1 for an image) hdr[2] = float(nrow) # number of rows per slice + hdr[3] = float(nrow) # number of records in the image hdr[5] = 1.0 # iform for 2D image hdr[12] = float(nsam) # number of pixels per line hdr[13] = float(labrec) # number of records in file header