ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/util/cmatrix.c
(Generate patch)

Comparing ray/src/util/cmatrix.c (file contents):
Revision 2.12 by greg, Wed Jul 22 04:29:56 2015 UTC vs.
Revision 2.17 by greg, Thu Aug 18 00:52:48 2016 UTC

# Line 8 | Line 8 | static const char RCSid[] = "$Id$";
8   */
9  
10   #include <ctype.h>
11 + #include "platform.h"
12   #include "standard.h"
13   #include "cmatrix.h"
14   #include "platform.h"
15 < #include "rtprocess.h"
15 > #include "paths.h"
16   #include "resolu.h"
17  
18   const char      *cm_fmt_id[] = {
# Line 148 | Line 149 | cm_getheader(int *dt, int *nr, int *nc, FILE *fp)
149   CMATRIX *
150   cm_load(const char *inspec, int nrows, int ncols, int dtype)
151   {
152 <        FILE    *fp = stdin;
153 <        CMATRIX *cm;
152 >        const int       ROWINC = 2048;
153 >        FILE            *fp = stdin;
154 >        CMATRIX         *cm;
155  
156          if (inspec == NULL)
157                  inspec = "<stdin>";
# Line 218 | Line 220 | cm_load(const char *inspec, int nrows, int ncols, int
220                  int     r, c;
221                  for (r = 0; r < maxrow; r++) {
222                      if (r >= cm->nrows)                 /* need more space? */
223 <                        cm = cm_resize(cm, 2*cm->nrows);
223 >                        cm = cm_resize(cm, cm->nrows+ROWINC);
224                      for (c = 0; c < ncols; c++) {
225                          COLORV  *cv = cm_lval(cm,r,c);
226 <                        if (fscanf(fp, COLSPEC, cv, cv+1, cv+2) != 3)
226 >                        if (fscanf(fp, COLSPEC, cv, cv+1, cv+2) != 3) {
227                                  if ((nrows <= 0) & (r > 0) & !c) {
228                                          cm = cm_resize(cm, maxrow=r);
229                                          break;
230                                  } else
231                                          goto EOFerror;
232 +                        }
233                      }
234                  }
235                  while ((c = getc(fp)) != EOF)
# Line 241 | Line 244 | cm_load(const char *inspec, int nrows, int ncols, int
244                  if (sizeof(COLOR) == cm_elem_size[dtype]) {
245                          int     nread = 0;
246                          do {                            /* read all we can */
247 <                                nread += fread(cm->cmem + 3*nread,
247 >                                nread += getbinary(cm->cmem + 3*nread,
248                                                  sizeof(COLOR),
249                                                  cm->nrows*cm->ncols - nread,
250                                                  fp);
251                                  if (nrows <= 0) {       /* unknown length */
252                                          if (nread == cm->nrows*cm->ncols)
253                                                          /* need more space? */
254 <                                                cm = cm_resize(cm, 2*cm->nrows);
254 >                                                cm = cm_resize(cm, cm->nrows+ROWINC);
255                                          else if (nread && !(nread % cm->ncols))
256                                                          /* seem to be  done */
257                                                  cm = cm_resize(cm, nread/cm->ncols);
# Line 266 | Line 269 | cm_load(const char *inspec, int nrows, int ncols, int
269                          if (n <= 0)
270                                  goto not_handled;
271                          while (n--) {
272 <                                if (fread(dc, sizeof(double), 3, fp) != 3)
272 >                                if (getbinary(dc, sizeof(double), 3, fp) != 3)
273                                          goto EOFerror;
274                                  copycolor(cvp, dc);
275                                  cvp += 3;
# Line 279 | Line 282 | cm_load(const char *inspec, int nrows, int ncols, int
282                          if (n <= 0)
283                                  goto not_handled;
284                          while (n--) {
285 <                                if (fread(fc, sizeof(float), 3, fp) != 3)
285 >                                if (getbinary(fc, sizeof(float), 3, fp) != 3)
286                                          goto EOFerror;
287                                  copycolor(cvp, fc);
288                                  cvp += 3;
# Line 432 | Line 435 | cm_write(const CMATRIX *cm, int dtype, FILE *fp)
435                  if (sizeof(COLOR) == cm_elem_size[dtype]) {
436                          r = cm->ncols*cm->nrows;
437                          while (r > 0) {
438 <                                c = fwrite(mp, sizeof(COLOR), r, fp);
438 >                                c = putbinary(mp, sizeof(COLOR), r, fp);
439                                  if (c <= 0)
440                                          return(0);
441                                  mp += 3*c;
# Line 443 | Line 446 | cm_write(const CMATRIX *cm, int dtype, FILE *fp)
446                          r = cm->ncols*cm->nrows;
447                          while (r--) {
448                                  copycolor(dc, mp);
449 <                                if (fwrite(dc, sizeof(double), 3, fp) != 3)
449 >                                if (putbinary(dc, sizeof(double), 3, fp) != 3)
450                                          return(0);
451                                  mp += 3;
452                          }
# Line 452 | Line 455 | cm_write(const CMATRIX *cm, int dtype, FILE *fp)
455                          r = cm->ncols*cm->nrows;
456                          while (r--) {
457                                  copycolor(fc, mp);
458 <                                if (fwrite(fc, sizeof(float), 3, fp) != 3)
458 >                                if (putbinary(fc, sizeof(float), 3, fp) != 3)
459                                          return(0);
460                                  mp += 3;
461                          }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines