I'm going to try and post a summary of the code. The class in which all the
image loading happens inherits from Fl_Group and the code is as follows:
int dvisual = 0;
int arg(int, char **argv, int &i) {
if (argv[i][1] == '8') {dvisual = 1; i++; return 1;}
return 0;
}
CBlimpVideoDisplay::CBlimpVideoDisplay(int x, int y, int w, int h, int argc,
char **argv, const char *label) : Fl_Group(x,y,w,h,label)
{
int i = 1;
fl_register_images();
Fl::args(argc,argv,i,arg);
//image width = 320 => two images and three spacings so must be at
least 2*320+3*15 = 685 wide
//image height = 240 => one image plus two spacings so must be at least
240+2*15 = 270 high
int spacing = 15;
if (w < 685 || h < 270)
{
m_OriginalFrame = new Fl_Box(x+spacing, y+spacing,
(w-3*spacing)/2, h-2*spacing,"Original Video Feed");
m_ModifiedFrame = new Fl_Box(x+(w+spacing)/2, y+spacing,
(w-3*spacing)/2, h-2*spacing,"Analysed Video Feed");
}
else
{
m_OriginalFrame = new Fl_Box(x+spacing, y+spacing, 320,
240,"Original Video Feed");
m_ModifiedFrame = new
Fl_Box(x+2*spacing+320,y+spacing,320,240,"Analysed Video Feed");
}
//Draw frames around the two boxes, align the labels with the top left
and add them to this box
m_OriginalFrame->box(FL_BORDER_BOX);
m_OriginalFrame->align(FL_ALIGN_LEFT_TOP);
add(m_OriginalFrame);
m_ModifiedFrame->box(FL_BORDER_BOX);
m_ModifiedFrame->align(FL_ALIGN_LEFT_TOP);
add(m_ModifiedFrame);
//Set the box type
box(FL_BORDER_BOX);
//Align the text to inside left
align(FL_ALIGN_INSIDE | FL_ALIGN_LEFT);
if (!dvisual) Fl::visual(FL_RGB);
}
Clearly, m_OriginalFrame and m_ModifiedFrame are both of type Fl_Box*. There
is a method for showing the images, which gets called periodically from a
different class:
bool CBlimpVideoDisplay::showImg(int i, const char* fileName)
{
if (i>1)
{
std::cerr << "VideoDisplay.cpp: invalid value of i, must be 0
or 1" << std::endl;
return false;
}
else if (i == 0)
{
if(m_OriginalImg)
{
m_OriginalImg->release();
m_OriginalImg = 0L;
}
std::cout << "About to load image" << std::endl;
m_OriginalImg = Fl_Shared_Image::get(fileName);
std::cout << "Image (" << fileName << ") drawn at (" <<
m_OriginalFrame->x() << "," << m_OriginalFrame->y() << ") and have dimensions
(" << m_OriginalImg->w() << "," << m_OriginalImg->h() << ") with depth " <<
m_OriginalImg->d() << std::endl;
if (!m_OriginalImg)
{
m_OriginalFrame->image(0);
m_OriginalFrame->redraw();
}
else
{
if (m_OriginalImg->w() > m_OriginalFrame->w() ||
m_OriginalImg->h() > m_OriginalFrame->h())
{
Fl_Image* temp;
if (m_OriginalImg->w() > m_OriginalImg->h())
temp = m_OriginalImg->copy(m_OriginalFrame->w(), m_OriginalFrame->h() *
m_OriginalImg->h() / m_OriginalImg->w());
else temp =
m_OriginalImg->copy(m_OriginalFrame->w() * m_OriginalImg->w() /
m_OriginalImg->h(), m_OriginalFrame->h());
m_OriginalImg->release();
m_OriginalImg = (Fl_Shared_Image*) temp;
}
m_OriginalFrame->image(m_OriginalImg);
m_OriginalFrame->redraw();
}
}
else
{
//m_ModifiedImg = Fl_Shared_Image::get(fileName);
//m_ModifiedFrame->image(m_ModifiedImg);
//m_ModifiedFrame->redraw();
}
return true;
}
I haven't written the code for displaying m_ModifiedImg as there is no point
until I can get the images to display properly. The code in else if(i==0) is
almost a straight copy from pixelmap_browser.
This class is instantiated in a class, CBlimpPilot, that inherits from
Fl_Window and is instantiated as follows in the constructor:
m_VidDisp = new CBlimpVideoDisplay(x(),
y()+groupHeight+connectHeight+spacing+loopFreqHeight+spacing,w(),300,argc,argv);
In this class, there is a timeout, Fl::add_timeout(0.05,ServiceC,this); which
amongst other things calls showImg, m_VidDisp->showImg(0,fileName.c_str());
This class' main method is as follows:
int main(int argc, char **argv)
{
CBlimpPilot *bp = new CBlimpPilot(500,500,argc,argv,"BlimpPilot");
//bp->end();
bp->show(argc,argv);
return Fl::run();
}
Hope this helps and is enough information.
Thanks,
Karol
>
> > I have tried the pixmap_browser demo and that displayed the
> > pictures just fine.
>
> Then, sorry to say, I'd have to suggest something is wrong with your
> code...
>
>
> > As far as I can see the code is virtually the same.
>
> I'm just guessing, but I suspect there is some key difference there you
> are not taking account of!
>
> > The only thing I can
> > see is the location of the calls to fl_register_images(),
> > Fl::args(...) and "if (!dvisual) Fl::visual(FL_RGB);". I'm
> > not really sure what these methods do and whether the point
> > at which they get called makes any difference. Maybe that
> > could be causing the problem?
>
> As long as those things are called *before* you try to load your image,
> that should not matter. They are described in the docs - I assume you
> have read them?
>
> Without more info on your code, it's hard to say where it is going awry
> - how small an example can you make that manifests the bug? Perhaps you
> could post a worked example of the fault here for others to take a look
> at?
>
> FWIW, I find that likely sources of problems are objects you use going
> out of scope - are the objects you are creating suitably persistent to
> exist when they are actually being used?
>
>
> ********************************************************************
> This email and any attachments are confidential to the intended
> recipient and may also be privileged. If you are not the intended
> recipient please delete it from your system and notify the sender.
> You should not copy it or use it for any purpose nor disclose or
> distribute its contents to any other person.
> ********************************************************************
>
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk