Interested Bystander
Posts: 3,725
Karma: 19728152
Join Date: Jun 2008
Device: Note 4, Kobo One
|
Cropping patch
Quick-and-dirty svn diff to enable four-sided cropping, with crop figures entered as percentages of width/height:
Index: papercrop-read-only.psm/PDFwin.cpp
================================================== =================
--- papercrop-read-only.psm/PDFwin.cpp (revision 2)
+++ papercrop-read-only.psm/PDFwin.cpp (working copy)
@@ -823,17 +823,17 @@
SummedAreaTable t(*bmp);//bmp->getWidth(), bmp->getHeight(), bmp->getDataPtr(), bmp-
>getRowSize());
- TRect domain(0,0, bmp->GetWidth(), bmp->GetHeight());
-
-
-
-
FlLayout* layout=mLayout->findLayout("Automatic segmentation");
double min_gap_percentage=layout->findSlider("MIN gap")->value();
double margin_percentage=layout->findSlider("Margin")->value();
int thr_white=layout->findSlider("white point")->value();
+ double cropT=layout->findSlider("Crop T")->value()/100.0;
+ double cropB=layout->findSlider("Crop B")->value()/100.0;
+ double cropL=layout->findSlider("Crop L")->value()/100.0;
+ double cropR=layout->findSlider("Crop R")->value()/100.0;
double max_width=1.0/layout->findSlider("N columns")->value();
+ TRect domain(cropL*bmp->GetWidth(),cropT*bmp->GetHeight(), (1-cropR)*bmp->GetWidth()
, (1-cropB)*bmp->GetHeight());
ImageSegmentation s(t, true, domain, 0, min_gap_percentage, thr_white);
s.segment();
@@ -994,4 +994,20 @@
temp.format("selected %d", mSelectedRect);
fl_draw(temp, 0,0,w(), h(), FL_ALIGN_CENTER);
*/
+
+ FlLayout* layout=mLayout->findLayout("Automatic segmentation");
+ double cropT=layout->findSlider("Crop T")->value()/100.0;
+ double cropB=layout->findSlider("Crop B")->value()/100.0;
+ double cropL=layout->findSlider("Crop L")->value()/100.0;
+ double cropR=layout->findSlider("Crop R")->value()/100.0;
+
+ int wCropL=toWindowCoord(cropL,cropT).x;
+ int wCropT=toWindowCoord(cropL,cropT).y;
+ int wCropR=toWindowCoord(cropR,cropB).x;
+ int wCropB=toWindowCoord(cropR,cropB).y;
+
+ fl_draw_box( FL_BORDER_FRAME, 0, 0, ww, wCropT, FL_BLACK);
+ fl_draw_box( FL_BORDER_FRAME, 0, hh-wCropB, ww, wCropB, FL_BLACK);
+ fl_draw_box( FL_BORDER_FRAME, 0, 0, wCropL, hh, FL_BLACK);
+ fl_draw_box( FL_BORDER_FRAME, ww-wCropR, 0, wCropR, hh, FL_BLACK);
}
Index: papercrop-read-only.psm/RightPanel.cpp
================================================== =================
--- papercrop-read-only.psm/RightPanel.cpp (revision 2)
+++ papercrop-read-only.psm/RightPanel.cpp (working copy)
@@ -61,6 +61,10 @@
double margin=L.getValue<double>("margin");
int nColumns=L.getValue<int>("N_columns");
int white_point=L.getValue<int>("white_point");
+ double cropT=L.getValue<double>("crop_T");
+ double cropB=L.getValue<double>("crop_B");
+ double cropL=L.getValue<double>("crop_L");
+ double cropR=L.getValue<double>("crop_R");
std::string option=L.getValue<std::string>("option");
FlLayout* layout=findLayout("Automatic segmentation");
@@ -68,6 +72,10 @@
layout->findSlider("Margin")->value(margin);
layout->findSlider("N columns")->value(nColumns);
layout->findSlider("white point")->value(white_point);
+ layout->findSlider("Crop T")->value(cropT);
+ layout->findSlider("Crop B")->value(cropB);
+ layout->findSlider("Crop L")->value(cropL);
+ layout->findSlider("Crop R")->value(cropR);
find<Fl_Input>("Option_Input")->value(processOption(option.c_str()));
redraw();
@@ -102,6 +110,18 @@
layout(0)->create("Value_Slider", "white point","white point");
layout(0)->slider(0)->range(230, 255);
layout(0)->slider(0)->step(1);
+ layout(0)->create("Value_Slider", "Crop T","Crop T");
+ layout(0)->slider(0)->range(0, 20);
+ layout(0)->slider(0)->step(0.1);
+ layout(0)->create("Value_Slider", "Crop B","Crop B");
+ layout(0)->slider(0)->range(0, 20);
+ layout(0)->slider(0)->step(0.1);
+ layout(0)->create("Value_Slider", "Crop L","Crop L");
+ layout(0)->slider(0)->range(0, 20);
+ layout(0)->slider(0)->step(0.1);
+ layout(0)->create("Value_Slider", "Crop R","Crop R");
+ layout(0)->slider(0)->range(0, 20);
+ layout(0)->slider(0)->step(0.1);
layout(0)->create("Button", "update","update");
layout(0)->updateLayout();
Index: papercrop-read-only.psm/presets/two-column papers (portrait).lua
================================================== =================
--- papercrop-read-only.psm/presets/two-column papers (portrait).lua (revision 2)
+++ papercrop-read-only.psm/presets/two-column papers (portrait).lua (working copy)
@@ -2,4 +2,8 @@
margin=1.45
N_columns=2
white_point=255
-option="(portrait) vertical scroll (outputs multiple images)"
\ No newline at end of file
+crop_T = 0
+crop_B = 0
+crop_L = 0
+crop_R = 0
+option="(portrait) vertical scroll (outputs multiple images)"
|