|
22 | 22 | #import "genericvector.h" |
23 | 23 | #import "strngs.h" |
24 | 24 |
|
| 25 | +NSInteger const kG8DefaultResolution = 72; |
| 26 | +NSInteger const kG8MinCredibleResolution = 70; |
| 27 | +NSInteger const kG8MaxCredibleResolution = 2400; |
| 28 | + |
25 | 29 | namespace tesseract { |
26 | 30 | class TessBaseAPI; |
27 | 31 | }; |
@@ -110,7 +114,7 @@ - (id)initWithLanguage:(NSString *)language |
110 | 114 | _engineMode = engineMode; |
111 | 115 | _pageSegmentationMode = G8PageSegmentationModeSingleBlock; |
112 | 116 | _variables = [NSMutableDictionary dictionary]; |
113 | | - _sourceResolution = 300; |
| 117 | + _sourceResolution = kG8DefaultResolution; |
114 | 118 | _rect = CGRectZero; |
115 | 119 |
|
116 | 120 | _monitor = new ETEXT_DESC(); |
@@ -393,7 +397,6 @@ - (void)setImage:(UIImage *)image |
393 | 397 | pixDestroy(&pix); |
394 | 398 |
|
395 | 399 | _image = image; |
396 | | - _sourceResolution = 300; |
397 | 400 | _rect = (CGRect){CGPointZero, self.imageSize}; |
398 | 401 |
|
399 | 402 | [self resetFlags]; |
@@ -439,6 +442,15 @@ - (void)setRect:(CGRect)rect |
439 | 442 | - (void)setSourceResolution:(NSInteger)sourceResolution |
440 | 443 | { |
441 | 444 | if (_sourceResolution != sourceResolution) { |
| 445 | + if (sourceResolution > kG8MaxCredibleResolution) { |
| 446 | + NSLog(@"Source resolution is too big: %ld > %ld", (long)sourceResolution, (long)kG8MaxCredibleResolution); |
| 447 | + sourceResolution = kG8MaxCredibleResolution; |
| 448 | + } |
| 449 | + else if (sourceResolution < kG8MinCredibleResolution) { |
| 450 | + NSLog(@"Source resolution is too small: %ld < %ld", (long)sourceResolution, (long)kG8MinCredibleResolution); |
| 451 | + sourceResolution = kG8MinCredibleResolution; |
| 452 | + } |
| 453 | + |
442 | 454 | _sourceResolution = sourceResolution; |
443 | 455 |
|
444 | 456 | _tesseract->SetSourceResolution((int)sourceResolution); |
@@ -801,7 +813,7 @@ - (Pix *)pixForImage:(UIImage *)image |
801 | 813 | default: |
802 | 814 | NSLog(@"Cannot convert image to Pix with bpp = %d", bpp); |
803 | 815 | } |
804 | | - pixSetYRes(pix, 300); |
| 816 | + pixSetYRes(pix, (l_int32)self.sourceResolution); |
805 | 817 |
|
806 | 818 | CFRelease(imageData); |
807 | 819 |
|
|
0 commit comments