aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortradke <tradke@eff87b29-5268-4891-90a3-a07138403961>2000-10-25 17:18:03 +0000
committertradke <tradke@eff87b29-5268-4891-90a3-a07138403961>2000-10-25 17:18:03 +0000
commitf0442a0a3a79f05014d0ef36c2fa91896b9381bf (patch)
tree032db1c093ba5bc07369c6cf34d2a3cb1995d2d9
parenta461cee644e9241187e67ef9070284a2a049cb37 (diff)
Avoid division by zero if minimum == maximum of slice to output.
git-svn-id: http://svn.cactuscode.org/arrangements/CactusIO/IOJpeg/trunk@25 eff87b29-5268-4891-90a3-a07138403961
-rw-r--r--src/JPEG.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/src/JPEG.c b/src/JPEG.c
index 588facc..990d9d1 100644
--- a/src/JPEG.c
+++ b/src/JPEG.c
@@ -229,7 +229,17 @@ void AutoColorDataSlice(int nx,int ny, /* size of the image x & y */
int i,last;
CCTK_REAL F=(CCTK_REAL)rdfac; /* cast to CCTK_REAL... don't know how the original worked at all without a cast */
for(i=0,last=nx*ny;i<last;i++,dataout+=3){
- CCTK_REAL f=bias-(*datain++ - min)/(max-min);
+ CCTK_REAL f;
+
+ /* check for division by 0 */
+ if (min == max)
+ {
+ f = bias;
+ }
+ else
+ {
+ f = bias-(*datain++ - min)/(max-min);
+ }
/* f-=(max-min); zero-center it */
/* well it can't be less than 0 */
if(f>0){