MCPcopy Create free account
hub / github.com/creatale/node-dv / Crop

Method Crop

deps/tesseract/cube/bmp_8.cpp:318–359  ·  view source on GitHub ↗

crop the bitmap returning new dimensions

Source from the content-addressed store, hash-verified

316
317// crop the bitmap returning new dimensions
318void Bmp8::Crop(int *xst, int *yst, int *wid, int *hgt) {
319 (*xst) = 0;
320 (*yst) = 0;
321
322 int xend = wid_ - 1;
323 int yend = hgt_ - 1;
324
325 while ((*xst) < (wid_ - 1) && (*xst) <= xend) {
326 // column is not empty
327 if (!IsBlankColumn((*xst))) {
328 break;
329 }
330 (*xst)++;
331 }
332
333 while (xend > 0 && xend >= (*xst)) {
334 // column is not empty
335 if (!IsBlankColumn(xend)) {
336 break;
337 }
338 xend--;
339 }
340
341 while ((*yst) < (hgt_ - 1) && (*yst) <= yend) {
342 // column is not empty
343 if (!IsBlankRow((*yst))) {
344 break;
345 }
346 (*yst)++;
347 }
348
349 while (yend > 0 && yend >= (*yst)) {
350 // column is not empty
351 if (!IsBlankRow(yend)) {
352 break;
353 }
354 yend--;
355 }
356
357 (*wid) = xend - (*xst) + 1;
358 (*hgt) = yend - (*yst) + 1;
359}
360
361// generates a scaled bitmap with dimensions the new bmp will have the
362// same aspect ratio and will be centered in the box

Callers 2

CharSampleMethod · 0.45
CharBoxMethod · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected