~ubuntu-branches/ubuntu/saucy/sane-backends/saucy

« back to all changes in this revision

Viewing changes to backend/genesys_conv.c

  • Committer: Bazaar Package Importer
  • Author(s): Robert Ancell
  • Date: 2011-02-14 14:28:56 UTC
  • mfrom: (1.2.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20110214142856-6gxjetg88q9zctid
Tags: 1.0.22-0ubuntu1
* New upstream release
* debian/control:
  - Use standards version 3.9.1
* debian/patches/allow_dll.d_symlinks.patch:
* debian/patches/fix_epson2_cancel.patch:
* debian/patches/fix_epson2_commands.patch:
* debian/patches/fix_xerox_mfp_color_mode.patch:
* debian/patches/genesys_disable_raw_data_log.patch:
* debian/patches/no_translations.patch:
* debian/patches/saned_exit_avahi_process.patch:
* debian/patches/scsi_perfection_2450.patch:
* debian/patches/scsi_scanjet_4c.patch:
* debian/patches/xerox_mfp_new_ids.patch:
  - Applied upstream
* debian/watch:
  - Dropped, the URL is not consistent between releases

Show diffs side-by-side

added added

removed removed

Lines of Context:
105
105
  int offset, addCol, dropCol;
106
106
  unsigned char mask;
107
107
  
108
 
  size_t x;
 
108
  int x;
109
109
  uint8_t min, max;
110
110
 
111
111
  /* normalize line */
193
193
{
194
194
  size_t y;
195
195
 
196
 
  DBG (DBG_io2, "genesys_gray_lineart: converting %d lines of %d pixels\n",
197
 
       lines, pixels);
 
196
  DBG (DBG_io2, "genesys_gray_lineart: converting %lu lines of %lu pixels\n",
 
197
       (unsigned long)lines, (unsigned long)pixels);
 
198
  DBG (DBG_io2, "genesys_gray_lineart: threshold=%d\n",threshold);
198
199
 
199
200
  for (y = 0; y < lines; y++)
200
201
    {
264
265
    return SANE_STATUS_GOOD;
265
266
}
266
267
 
 
268
 
 
269
/** Look in image for likely left/right/bottom paper edges, then crop image.
 
270
 * Since failing to crop isn't fatal, we always return SANE_STATUS_GOOD .
 
271
 */
 
272
static SANE_Status
 
273
genesys_crop(Genesys_Scanner *s)
 
274
{
 
275
  SANE_Status status = SANE_STATUS_GOOD;
 
276
  Genesys_Device *dev = s->dev;
 
277
  int top = 0;
 
278
  int bottom = 0;
 
279
  int left = 0;
 
280
  int right = 0;
 
281
 
 
282
  DBG (DBG_proc, "%s: start\n", __FUNCTION__);
 
283
 
 
284
  /* first find edges if any */
 
285
  status = sanei_magic_findEdges (&s->params,
 
286
                                  dev->img_buffer,
 
287
                                  dev->settings.xres,
 
288
                                  dev->settings.yres,
 
289
                                  &top,
 
290
                                  &bottom,
 
291
                                  &left,
 
292
                                  &right);
 
293
  if (status != SANE_STATUS_GOOD)
 
294
    {
 
295
      DBG (DBG_info, "%s: bad or no edges, bailing\n", __FUNCTION__);
 
296
      goto cleanup;
 
297
    }
 
298
  DBG (DBG_io, "%s: t:%d b:%d l:%d r:%d\n", __FUNCTION__, top, bottom, left,
 
299
       right);
 
300
 
 
301
  /* now crop the image */
 
302
  status =
 
303
    sanei_magic_crop (&(s->params), dev->img_buffer, top, bottom, left, right);
 
304
  if (status)
 
305
    {
 
306
      DBG (DBG_warn, "%s: failed to crop\n", __FUNCTION__);
 
307
      goto cleanup;
 
308
    }
 
309
 
 
310
  /* update counters to new image size */
 
311
  dev->total_bytes_to_read = s->params.bytes_per_line * s->params.lines;
 
312
 
 
313
cleanup:
 
314
  DBG (DBG_proc, "%s: completed\n", __FUNCTION__);
 
315
  return SANE_STATUS_GOOD;
 
316
}
 
317
 
 
318
/** Look in image for likely upper and left paper edges, then rotate
 
319
 * image so that upper left corner of paper is upper left of image.
 
320
 * @return since failure doens't prevent scanning, we always return
 
321
 * SANE_STATUS_GOOD
 
322
 */
 
323
static SANE_Status
 
324
genesys_deskew(Genesys_Scanner *s)
 
325
{
 
326
  SANE_Status status;
 
327
  Genesys_Device *dev = s->dev;
 
328
 
 
329
  int x = 0, y = 0, bg;
 
330
  double slope = 0;
 
331
 
 
332
  DBG (DBG_proc, "%s: start\n", __FUNCTION__);
 
333
 
 
334
  bg=0;
 
335
  if(s->params.format==SANE_FRAME_GRAY && s->params.depth == 1)
 
336
    {
 
337
      bg=0xff;
 
338
    }
 
339
  status = sanei_magic_findSkew (&s->params,
 
340
                                 dev->img_buffer,
 
341
                                 dev->sensor.optical_res,
 
342
                                 dev->sensor.optical_res,
 
343
                                 &x,
 
344
                                 &y,
 
345
                                 &slope);
 
346
  if (status!=SANE_STATUS_GOOD)
 
347
    {
 
348
      DBG (DBG_error, "%s: bad findSkew, bailing\n", __FUNCTION__);
 
349
      return SANE_STATUS_GOOD;
 
350
    }
 
351
  DBG(DBG_info, "%s: slope=%f => %f\n",__FUNCTION__,slope, (slope/M_PI_2)*90);
 
352
  /* rotate image slope is in [-PI/2,PI/2] 
 
353
   * positive values rotate trigonometric direction wise */
 
354
  status = sanei_magic_rotate (&s->params,
 
355
                               dev->img_buffer,
 
356
                               x,
 
357
                               y,
 
358
                               slope,
 
359
                               bg);
 
360
  if (status!=SANE_STATUS_GOOD)
 
361
    {
 
362
      DBG (DBG_error, "%s: rotate error: %s", __FUNCTION__, sane_strstatus(status));
 
363
    }
 
364
 
 
365
  DBG (DBG_proc, "%s: completed\n", __FUNCTION__);
 
366
  return SANE_STATUS_GOOD;
 
367
}
 
368
 
 
369
/** remove lone dots
 
370
 * @return since failure doens't prevent scanning, we always return
 
371
 * SANE_STATUS_GOOD
 
372
 */
 
373
static SANE_Status
 
374
genesys_despeck(Genesys_Scanner *s)
 
375
{
 
376
  if(sanei_magic_despeck(&s->params,
 
377
                         s->dev->img_buffer,
 
378
                         s->val[OPT_DESPECK].w)!=SANE_STATUS_GOOD)
 
379
  {
 
380
    DBG (DBG_error, "%s: bad despeck, bailing\n",__FUNCTION__);
 
381
  }
 
382
 
 
383
  return SANE_STATUS_GOOD;
 
384
}
 
385
 
 
386
 
 
387
/* vim: set sw=2 cino=>2se-1sn-1s{s^-1st0(0u0 smarttab expandtab: */