mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-05-21 06:45:39 -06:00
Bazaar:Leptonica - some bug fixes
git-svn-id: svn://ultimatepp.org/upp/trunk@1556 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
05bbc36045
commit
a5ad08c0e1
5 changed files with 551 additions and 397 deletions
File diff suppressed because it is too large
Load diff
|
|
@ -180,9 +180,10 @@ class PixRaster : public Raster
|
|||
void operator+=(Raster &raster) { Load(raster, true, PIXRASTER_COPY); }
|
||||
|
||||
// file I/O
|
||||
void Load(String fileName, bool Append = false);
|
||||
void Save(String fileName, int page = PIXRASTER_CURPAGE); // @@ to do - add compression and type handling
|
||||
void SaveAll(String fileName);
|
||||
bool Load(FileIn &fs, bool Append = false);
|
||||
bool Load(String fileName, bool Append = false);
|
||||
bool Save(String fileName, int page = PIXRASTER_CURPAGE); // @@ to do - add compression and type handling
|
||||
bool SaveAll(String fileName);
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
///////////////////////////////////////// LEPTONICA OPERATIONS //////////////////////////////////////////
|
||||
|
|
|
|||
|
|
@ -174,22 +174,40 @@ Appends [%-*@3 raster]`'s content at the end of Pixraster`'s one&]
|
|||
[ {{10000F(128)G(128)@1 [s0;%% [* File I/O]]}}&]
|
||||
[s3;%% &]
|
||||
[s4; &]
|
||||
[s5;:PixRaster`:`:Load`(String`,bool`): [@(0.0.255) void]_Load([_^String^ String]_[@3 fileN
|
||||
[s5;:PixRaster`:`:Load`(FileIn`&`,bool`): [@(0.0.255) bool]_Load([_^FileIn^ FileIn]_`&[@3 f
|
||||
s], [@(0.0.255) bool]_[@3 Append]_`=_[@(0.0.255) false])&]
|
||||
[s2;%% Loads images from stream [%-*@3 fs][%- ,] [%-*@3 Append][%- ing them
|
||||
to current PixRaster`'s content if required].&]
|
||||
[s2;%% [* WARNING], it seems that don`'t support 8 bit alpha channel
|
||||
images.&]
|
||||
[s0;%% &]
|
||||
[s2;%% Returns [%-@(0.0.255) true] on success, [%-@(0.0.255) false] otherwise.&]
|
||||
[s3;%% &]
|
||||
[s4; &]
|
||||
[s5;:PixRaster`:`:Load`(String`,bool`): [@(0.0.255) bool]_Load([_^String^ String]_[@3 fileN
|
||||
ame], [@(0.0.255) bool]_[@3 Append]_`=_[@(0.0.255) false])&]
|
||||
[s2;%% Loads images from [%-*@3 fileName ][%- named file,] [%-*@3 Append][%- ing
|
||||
them to current PixRaster`'s content if required].&]
|
||||
[s2;%% [* WARNING], it seems that don`'t support 8 bit alpha channel
|
||||
images.&]
|
||||
[s0;%% &]
|
||||
[s2;%% Returns [%-@(0.0.255) true] on success, [%-@(0.0.255) false] otherwise.&]
|
||||
[s3;%% &]
|
||||
[s4; &]
|
||||
[s5;:PixRaster`:`:Save`(String`,int`): [@(0.0.255) void]_Save([_^String^ String]_[@3 fileNa
|
||||
[s5;:PixRaster`:`:Save`(String`,int`): [@(0.0.255) bool]_Save([_^String^ String]_[@3 fileNa
|
||||
me], [@(0.0.255) int]_[@3 page]_`=_PIXRASTER`_CURPAGE)&]
|
||||
[s2;%% Stores a single [%-*@3 page ][%- of PixRaster to] [%-*@3 fileName]
|
||||
named file.&]
|
||||
[s0;%% &]
|
||||
[s2;%% Returns [%-@(0.0.255) true] on success, [%-@(0.0.255) false] otherwise.&]
|
||||
[s3;%% &]
|
||||
[s4; &]
|
||||
[s5;:PixRaster`:`:SaveAll`(String`): [@(0.0.255) void]_SaveAll([_^String^ String]_[@3 fileN
|
||||
[s5;:PixRaster`:`:SaveAll`(String`): [@(0.0.255) bool]_SaveAll([_^String^ String]_[@3 fileN
|
||||
ame])&]
|
||||
[s2;%% Stores all pages of PixRaster to a [%-*@3 fileName] named file;
|
||||
choosen file format must support multiple pages.&]
|
||||
[s0;%% &]
|
||||
[s2;%% Returns [%-@(0.0.255) true] on success, [%-@(0.0.255) false] otherwise.&]
|
||||
[s3;%% &]
|
||||
[s0; &]
|
||||
[ {{10000F(128)G(128)@1 [s0;%% [* Page handling functions]]}}&]
|
||||
|
|
|
|||
|
|
@ -2,34 +2,8 @@
|
|||
|
||||
#include <plugin/tif/tif.h>
|
||||
|
||||
void TestLeptonica::onLineRemoval()
|
||||
static void RemoveLines(PixRaster &pixRaster)
|
||||
{
|
||||
String fileName;
|
||||
FileSelector fs;
|
||||
PIX *pix;
|
||||
|
||||
if(!PromptYesNo(
|
||||
"[= [* Line removal demo]&&"
|
||||
"Please select the 'dave-orig.png' image on TestLeptonica folder&"
|
||||
"or some equivalent GrayScale image with horizontal stripes on it&&"
|
||||
"[* CONTINUE ??]]"
|
||||
))
|
||||
return;
|
||||
|
||||
fs.ReadOnlyOption();
|
||||
if(fs.ExecuteOpen("Please select image for line removal:"))
|
||||
{
|
||||
FileIn s;
|
||||
if(!s.Open(~fs))
|
||||
{
|
||||
PromptOK("Error opening image");
|
||||
return;
|
||||
}
|
||||
One<StreamRaster>streamRaster = StreamRaster::OpenAny(s);
|
||||
|
||||
// Loads pixraster from source raster
|
||||
pixRaster.Load(*streamRaster);
|
||||
|
||||
// gets source image page
|
||||
int source = pixRaster.GetActivePage();
|
||||
|
||||
|
|
@ -88,6 +62,42 @@ void TestLeptonica::onLineRemoval()
|
|||
// created before to fill just the stripes and leave the rest of image unchanged
|
||||
CHECKR(pixRaster.CombineMasked(grayAdded, opened2, thresh4), "CombineMasked error");
|
||||
int final = pixRaster.GetActivePage();
|
||||
}
|
||||
|
||||
void TestLeptonica::onLineRemoval()
|
||||
{
|
||||
String fileName;
|
||||
FileSelector fs;
|
||||
PIX *pix;
|
||||
|
||||
if(!PromptYesNo(
|
||||
"[= [* Line removal demo]&&"
|
||||
"Please select the 'dave-orig.png' image on TestLeptonica folder&"
|
||||
"or some equivalent GrayScale image with horizontal stripes on it&&"
|
||||
"[* CONTINUE ??]]"
|
||||
))
|
||||
return;
|
||||
|
||||
fs.ReadOnlyOption();
|
||||
if(fs.ExecuteOpen("Please select image for line removal:"))
|
||||
{
|
||||
FileIn s;
|
||||
if(!s.Open(~fs))
|
||||
{
|
||||
PromptOK("Error opening image");
|
||||
s.Close();
|
||||
return;
|
||||
}
|
||||
// One<StreamRaster>streamRaster = StreamRaster::OpenAny(s);
|
||||
|
||||
// Loads pixraster from source raster
|
||||
CHECKR(pixRaster.Load(s), "Error loading image");
|
||||
s.Close();
|
||||
|
||||
int ctc = pixRaster.GetPaletteCount();
|
||||
|
||||
// apply line removal algothithm
|
||||
RemoveLines(pixRaster);
|
||||
|
||||
// refresh the PixRasterCtrl control with the new image contents
|
||||
pixRasterCtrl.Reload();
|
||||
|
|
|
|||
|
|
@ -1,136 +0,0 @@
|
|||
#include "TestLeptonica.h"
|
||||
|
||||
#include <plugin/tif/tif.h>
|
||||
|
||||
void TestLeptonica::onOpen()
|
||||
{
|
||||
String fileName;
|
||||
FileSelector fs;
|
||||
PIX *pix;
|
||||
|
||||
/*
|
||||
FileIn s;
|
||||
if(!s.Open("/home/massimo/tmp/TestLept2.tif"))
|
||||
{
|
||||
PromptOK("Error creating first image file");
|
||||
return;
|
||||
}
|
||||
One<StreamRaster>streamRaster = StreamRaster::OpenAny(s);
|
||||
|
||||
Raster::Info info = streamRaster->GetInfo();
|
||||
pixRaster.Load(*streamRaster);
|
||||
*/
|
||||
int bpp = 32;
|
||||
int wh = 1024;
|
||||
pix = pixCreate(wh, wh, bpp);
|
||||
memset(pixGetData(pix), 0x0, pixGetHeight(pix)*pixGetWpl(pix)*4);
|
||||
|
||||
/*
|
||||
PIXCMAP *colorMap = pixcmapCreateLinear(bpp, 1 << bpp);
|
||||
pixSetColormap(pix, colorMap);
|
||||
*/
|
||||
/*
|
||||
PIXCMAP *colorMap = pixcmapCreate(bpp);
|
||||
pixcmapAddColor(colorMap, 0x00, 0x00, 0xff);
|
||||
pixcmapAddColor(colorMap, 0xff, 0x00, 0x00);
|
||||
*/
|
||||
|
||||
pixRaster.AddPIX(pix);
|
||||
|
||||
if(bpp < 16)
|
||||
{
|
||||
int thick = wh / (1 << bpp);
|
||||
l_uint32 nColors = 1 << bpp;
|
||||
l_uint32 iColor = 0;
|
||||
int iThick = 0;
|
||||
for(int i = 0; i < wh; i++)
|
||||
{
|
||||
for(int j = 0; j < wh; j++)
|
||||
{
|
||||
pixSetPixel(pix, i, j, iColor);
|
||||
pixSetPixel(pix, j, i, iColor);
|
||||
}
|
||||
iThick++;
|
||||
if(iThick >= thick)
|
||||
{
|
||||
iThick = 0;
|
||||
iColor++;
|
||||
}
|
||||
}
|
||||
} // if bpp < 16
|
||||
else
|
||||
{
|
||||
l_uint32 r = 0, g = 0, b = 0;
|
||||
for(int y = 0; y < wh; y++)
|
||||
{
|
||||
for(int x = 0; x < wh; x++)
|
||||
{
|
||||
r = x * 256 / wh;
|
||||
g = y * 256 / wh;
|
||||
b = sqrt((x * 256 / wh) * (y * 256 / wh));
|
||||
pixSetPixel(pix, x, y, (r << 24) | (g << 16) | (b << 8));
|
||||
}
|
||||
}
|
||||
r = b;
|
||||
}
|
||||
pixDestroy(&pix);
|
||||
|
||||
int width = pixRaster.GetWidth();
|
||||
pix = pixRaster;
|
||||
pixWrite("/home/massimo/tmp/TestLeptOut.tif", pix, IFF_TIFF);
|
||||
FileOut of;
|
||||
if(!of.Open("/home/massimo/tmp/TestLeptOut2.tif"))
|
||||
{
|
||||
PromptOK("Error creating second image file");
|
||||
return;
|
||||
}
|
||||
TIFEncoder enc(pixRaster.GetInfo().bpp);
|
||||
enc.SetStream(of);
|
||||
enc.Create(pixRaster.GetSize(), pixRaster);
|
||||
enc.SetDots(Size(1024,1024));
|
||||
const RGBA *pal = enc.GetPalette();
|
||||
enc.Save(of, pixRaster);
|
||||
int pc = enc.GetPaletteCount();
|
||||
|
||||
return;
|
||||
|
||||
|
||||
/*
|
||||
fs.ReadOnlyOption();
|
||||
if(fs.ExecuteOpen("Please select a graphic file to view:"))
|
||||
{
|
||||
FileIn s;
|
||||
if(!s.Open(~fs))
|
||||
{
|
||||
PromptOK("Error opening image");
|
||||
return;
|
||||
}
|
||||
One<StreamRaster>streamRaster = StreamRaster::OpenAny(s);
|
||||
pixRaster.Load(*streamRaster);
|
||||
PIX *pix = pixRaster;
|
||||
pixWrite("/home/massimo/out.tif", pix, IFF_UNKNOWN);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
void TestLeptonica::onQuit()
|
||||
{
|
||||
Break();
|
||||
}
|
||||
|
||||
TestLeptonica::TestLeptonica()
|
||||
{
|
||||
CtrlLayout(*this, "Window title");
|
||||
|
||||
// connects button handlers
|
||||
OpenButton <<= THISBACK(onOpen);
|
||||
QuitButton <<= THISBACK(onQuit);
|
||||
}
|
||||
|
||||
GUI_APP_MAIN
|
||||
{
|
||||
TestLeptonica testLept;
|
||||
|
||||
testLept.Run();
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue