Lines Matching refs:ph

1177 {PROCDATA_HANDLE *ph = sanei_hp_alloc (sizeof (PROCDATA_HANDLE));
1180 if (ph == NULL) return NULL;
1182 memset (ph, 0, sizeof (*ph));
1183 memcpy (&(ph->procdata), procdata, sizeof (*procdata));
1184 procdata = &(ph->procdata);
1187 ph->tmp_buf = sanei_hp_alloc (tsz);
1188 if (ph->tmp_buf == NULL)
1190 sanei_hp_free (ph);
1193 ph->tmp_buf_size = tsz;
1194 ph->tmp_buf_len = 0;
1196 ph->map = map;
1197 ph->outfd = outfd;
1203 ph->image_ptr = ph->image_buf = sanei_hp_alloc (tsz);
1204 if ( !ph->image_buf )
1207 ph->image_buf_size = 0;
1211 ph->image_buf_size = tsz;
1214 ph->wr_ptr = ph->wr_buf;
1215 ph->wr_buf_size = ph->wr_left = sizeof (ph->wr_buf);
1217 return ph;
1222 process_data_write (PROCDATA_HANDLE *ph, unsigned char *data, int nbytes)
1226 if (ph == NULL) return SANE_STATUS_INVAL;
1229 ncopy = ph->wr_left;
1232 memcpy (ph->wr_ptr, data, ncopy);
1233 ph->wr_ptr += ncopy;
1234 ph->wr_left -= ncopy;
1238 if ( ph->wr_left > 0 ) /* Did not fill up the write buffer ? Finished */
1241 DBG(12, "process_data_write: write %d bytes\n", ph->wr_buf_size);
1244 || (write (ph->outfd, ph->wr_buf, ph->wr_buf_size) != ph->wr_buf_size))
1250 ph->wr_ptr = ph->wr_buf;
1251 ph->wr_left = ph->wr_buf_size;
1254 while ( nbytes > ph->wr_buf_size )
1257 || (write (ph->outfd, data, ph->wr_buf_size) != ph->wr_buf_size))
1263 nbytes -= ph->wr_buf_size;
1264 data += ph->wr_buf_size;
1269 memcpy (ph->wr_ptr, data, nbytes);
1270 ph->wr_ptr += nbytes;
1271 ph->wr_left -= nbytes;
1277 process_scanline (PROCDATA_HANDLE *ph, unsigned char *linebuf,
1283 if (ph == NULL) return SANE_STATUS_INVAL;
1284 procdata = &(ph->procdata);
1286 if ( ph->map )
1287 hp_data_map (ph->map, bytes_per_line, linebuf);
1308 if ( ph->image_buf )
1312 if ( ph->image_ptr+out_bytes_per_line-1
1313 <= ph->image_buf+ph->image_buf_size-1 )
1315 memcpy(ph->image_ptr, linebuf, out_bytes_per_line);
1316 ph->image_ptr += out_bytes_per_line;
1326 RETURN_IF_FAIL ( process_data_write (ph, linebuf, out_bytes_per_line) );
1333 process_data (PROCDATA_HANDLE *ph, unsigned char *read_ptr, int nread)
1339 if (ph == NULL) return SANE_STATUS_INVAL;
1341 if ( ph->tmp_buf_len > 0 ) /* Something left ? */
1343 bytes_left = ph->tmp_buf_size - ph->tmp_buf_len;
1346 memcpy (ph->tmp_buf+ph->tmp_buf_len, read_ptr, nread);
1347 ph->tmp_buf_len += nread;
1350 memcpy (ph->tmp_buf+ph->tmp_buf_len, read_ptr, bytes_left);
1353 RETURN_IF_FAIL ( process_scanline (ph, ph->tmp_buf, ph->tmp_buf_size) );
1354 ph->tmp_buf_len = 0;
1358 if (nread >= ph->tmp_buf_size)
1360 RETURN_IF_FAIL ( process_scanline (ph, read_ptr, ph->tmp_buf_size) );
1361 read_ptr += ph->tmp_buf_size;
1362 nread -= ph->tmp_buf_size;
1366 memcpy (ph->tmp_buf, read_ptr, nread);
1367 ph->tmp_buf_len = nread;
1376 process_data_flush (PROCDATA_HANDLE *ph)
1385 if (ph == NULL) return SANE_STATUS_INVAL;
1387 if ( ph->tmp_buf_len > 0 )
1388 process_scanline (ph, ph->tmp_buf, ph->tmp_buf_len);
1390 if ( ph->wr_left != ph->wr_buf_size ) /* Something in write buffer ? */
1392 nbytes = ph->wr_buf_size - ph->wr_left;
1393 if ( signal_caught || (write (ph->outfd, ph->wr_buf, nbytes) != nbytes))
1399 ph->wr_ptr = ph->wr_buf;
1400 ph->wr_left = ph->wr_buf_size;
1403 procdata = &(ph->procdata);
1404 if ( ph->image_buf )
1408 image_len = (size_t) (ph->image_ptr - ph->image_buf);
1416 image_data = ph->image_buf + (num_lines-1) * bytes_per_line;
1420 || (write(ph->outfd, image_data, bytes_per_line) != bytes_per_line))
1433 image_data = ph->image_buf;
1437 || (write(ph->outfd, image_data, bytes_per_line) != bytes_per_line))
1454 process_data_finish (PROCDATA_HANDLE *ph)
1459 if (ph == NULL) return;
1461 if (ph->image_buf != NULL) sanei_hp_free (ph->image_buf);
1463 sanei_hp_free (ph->tmp_buf);
1464 sanei_hp_free (ph);
1525 PROCDATA_HANDLE *ph = NULL;
1586 ph = process_data_init (procdata, map, outfd, enable_image_buffering);
1588 if ( ph == NULL )
1648 status = process_data (ph, (unsigned char *)req->data, (int)req->len);
1693 status = process_data (ph, (unsigned char *)read_buf, (int)nread);
1703 process_data_flush (ph);
1707 process_data_finish (ph);