[Kst] extragear/graphics/kst/kst/datasources/dirfile

George Staikos staikos at kde.org
Wed Nov 9 05:47:29 CET 2005


SVN commit 479081 by staikos:

apply getdata patch by Don
BUG: 115645


 M  +42 -15    getdata.c  


--- trunk/extragear/graphics/kst/kst/datasources/dirfile/getdata.c #479080:479081
@@ -1155,7 +1155,7 @@
   struct LincomEntryType *L;
   void *tmpbuf;
   int i;
-  int spf1, spf2;
+  int spf1, spf2, num_samp2, first_samp2;
   int n_read2;
 
   /******* binary search for the field *******/
@@ -1173,6 +1173,8 @@
   spf1 = GetSPF(L->in_fields[0], F, error_code);
   if (*error_code != GD_E_OK) return(1);
 
+  /* read and scale the first field and record the number of samples
+   * returned */
   *n_read = DoField(F, L->in_fields[0],
       first_frame, first_samp,
       num_frames, num_samp,
@@ -1187,28 +1189,37 @@
     for (i=1; i<L->n_infields; i++) {
       recurse_level++;
 
+      /* find the samples per frame of the next field */
       spf2 = GetSPF(L->in_fields[i], F, error_code);
       if (*error_code != GD_E_OK) return(1);
 
-      tmpbuf = AllocTmpbuff(return_type, *n_read * (int)ceil((double)spf2 / spf1));
+      /* calculate the first sample and number of samples to read of the
+       * next field */
+      num_samp2 = (int)ceil((double)*n_read * spf2 / spf1);
+      first_samp2 = (first_frame * spf2 + first_samp * spf2 / spf1);
+
+      /* Allocate a temporary buffer for the next field */
+      tmpbuf = AllocTmpbuff(return_type, num_samp2);
       if (!tmpbuf && return_type != 'n') {
         return(0);
       }
 
-      num_samp = (*n_read * spf2 / spf1) % spf2;
-
+      /* read the next field */
       n_read2 = DoField(F, L->in_fields[i],
-            first_frame, first_samp,
-            0, *n_read * spf2 / spf1,
-            return_type, tmpbuf,
-            error_code);
+          0, first_samp2,
+          0, num_samp2,
+          return_type, tmpbuf,
+          error_code);
+      recurse_level--;
+      if (*error_code != GD_E_OK)
+        return(1);
 
+      ScaleData(tmpbuf, return_type, n_read2, L->m[i], L->b[i]);
+
       if (n_read2 > 0 && n_read2 * spf1 != *n_read * spf2) {
         *n_read = n_read2 * spf1 / spf2;
       }
 
-      recurse_level--;
-      ScaleData(tmpbuf, return_type, *n_read, L->m[i], L->b[i]);
       AddData(data_out, spf1, tmpbuf, spf2, return_type, *n_read);
 
       free(tmpbuf);
@@ -1231,7 +1242,7 @@
   struct MultiplyEntryType tM;
   struct MultiplyEntryType *M;
   void *tmpbuf;
-  int spf1, spf2;
+  int spf1, spf2, num_samp2, first_samp2;
   int n_read2;
 
   /******* binary search for the field *******/
@@ -1246,9 +1257,13 @@
   /** if we got here, we found the field! **/
   /** read into dataout and scale the first element **/
   recurse_level++;
+
+  /* find the samples per frame of the first field */
   spf1 = GetSPF(M->in_fields[0], F, error_code);
   if (*error_code != GD_E_OK) return(1);
 
+  /* read the first field and record the number of samples
+   * returned */
   *n_read = DoField(F, M->in_fields[0],
       first_frame, first_samp,
       num_frames, num_samp,
@@ -1259,23 +1274,35 @@
   if (*error_code != GD_E_OK) return(1);
 
   recurse_level++;
+
+  /* find the samples per frame of the second field */
   spf2 = GetSPF(M->in_fields[1], F, error_code);
   if (*error_code != GD_E_OK) return(1);
 
-  tmpbuf = AllocTmpbuff(return_type, *n_read * (int)ceil((double)spf2 / spf1));
+  /* calculate the first sample and number of samples to read of the
+   * second field */
+  num_samp2 = (int)ceil((double)*n_read * spf2 / spf1);
+  first_samp2 = (first_frame * spf2 + first_samp * spf2 / spf1);
+
+  /* Allocate a temporary buffer for the second field */
+  tmpbuf = AllocTmpbuff(return_type, num_samp2);
   if (!tmpbuf && return_type != 'n') {
     return(0);
   }
 
+  /* read the second field */
   n_read2 = DoField(F, M->in_fields[1],
-      first_frame, first_samp,
-      0, *n_read * spf2 / spf1,
+      0, first_samp2,
+      0, num_samp2,
       return_type, tmpbuf,
       error_code);
+  recurse_level--;
+  if (*error_code != GD_E_OK)
+    return(1);
+
   if (n_read2 > 0 && n_read2 * spf1 < *n_read * spf2) {
     *n_read = n_read2 * spf1 / spf2;
   }
-  recurse_level--;
   MultiplyData(data_out, spf1, tmpbuf, spf2, return_type, *n_read);
   free(tmpbuf);
 


More information about the Kst mailing list