Exemplo n.º 1
0
void CChildView::LoadLogo()
{
	AppSettings& s = AfxGetAppSettings();
	bool bHaveLogo = false;

	CAutoLock cAutoLock(&m_csLogo);

	m_logo.Destroy();

	CString logoFName = _T("logo");

	if (m_logo.FileExists(logoFName, true)) {
		m_logo.Attach(OpenImage(logoFName));
	} else {
		if (s.fLogoExternal) {
			m_logo.Attach(OpenImage(s.strLogoFileName));
			if (m_logo) {
				bHaveLogo = true;
			}
		}

		if (!bHaveLogo) {
			s.fLogoExternal = false;
			s.strLogoFileName = "";

			if (!m_logo.LoadFromResource(s.nLogoId)) {
				m_logo.LoadFromResource(s.nLogoId = DEF_LOGO);
			}
		}
	}

	if (m_hWnd) {
		Invalidate();
	}
}
Exemplo n.º 2
0
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    connect(ui->openButton, SIGNAL(clicked()), this, SLOT(OpenImage()));
    connect(ui->saveButton, SIGNAL(clicked()), this, SLOT(SaveImage()));
    connect(ui->saveDisplayButton, SIGNAL(clicked()), this, SLOT(SaveDisplayImage()));
    connect(ui->resetButton, SIGNAL(clicked()), this, SLOT(ResetImage()));
    connect(ui->toggleButton, SIGNAL(pressed()), this, SLOT(ToggleImage()));
    connect(ui->toggleButton, SIGNAL(released()), this, SLOT(ToggleImage()));

    connect(ui->bwButton, SIGNAL(clicked()), this, SLOT(BlackWhiteImage()));
    connect(ui->noiseButton, SIGNAL(clicked()), this, SLOT(AddNoise()));
    connect(ui->meanButton, SIGNAL(clicked()), this, SLOT(MeanBlurImage()));
    connect(ui->medianButton, SIGNAL(clicked()), this, SLOT(MedianImage()));
    connect(ui->gaussianBlurButton, SIGNAL(clicked()), this, SLOT(GaussianBlurImage()));
    connect(ui->firstDerivButton, SIGNAL(clicked()), this, SLOT(FirstDerivImage()));
    connect(ui->secondDerivButton, SIGNAL(clicked()), this, SLOT(SecondDerivImage()));
    connect(ui->sharpenButton, SIGNAL(clicked()), this, SLOT(SharpenImage()));
    connect(ui->sobelButton, SIGNAL(clicked()), this, SLOT(SobelImage()));
    connect(ui->bilateralButton, SIGNAL(clicked()), this, SLOT(BilateralImage()));
    connect(ui->halfButton, SIGNAL(clicked()), this, SLOT(HalfImage()));
    connect(ui->rotateButton, SIGNAL(clicked()), this, SLOT(RotateImage()));
    connect(ui->peaksButton, SIGNAL(clicked()), this, SLOT(FindPeaksImage()));
    connect(ui->houghButton, SIGNAL(clicked()), this, SLOT(HoughImage()));
    connect(ui->crazyButton, SIGNAL(clicked()), this, SLOT(CrazyImage()));
    connect(ui->randomButton, SIGNAL(clicked()), this, SLOT(RandomSeedImage()));
    connect(ui->pixelButton, SIGNAL(clicked()), this, SLOT(PixelSeedImage()));
    connect(ui->histogramButton, SIGNAL(clicked()), this, SLOT(HistogramSeedImage()));

    connect(ui->actionOpen, SIGNAL(triggered()), this, SLOT(OpenImage()));
    connect(ui->zoomSlider, SIGNAL(valueChanged(int)), this, SLOT(Zoom(int)));
    connect(ui->brightnessSlider, SIGNAL(valueChanged(int)), this, SLOT(Brightness(int)));
    connect(ui->verticalScrollBar, SIGNAL(valueChanged(int)), this, SLOT(Scroll(int)));
    connect(ui->horizontalScrollBar, SIGNAL(valueChanged(int)), this, SLOT(Scroll(int)));

    ui->meanBox->setValue(2);
    ui->medianBox->setValue(2);
    ui->blurSpinBox->setValue(2.0);
    ui->firstDerivSpinBox->setValue(2.0);
    ui->secondDerivSpinBox->setValue(2.0);
    ui->sharpenSigmaSpinBox->setValue(2.0);
    ui->sharpenMagSpinBox->setValue(1.0);
    ui->bilateralSigmaSSpinBox->setValue(2.0);
    ui->bilateralSigmaISpinBox->setValue(20.0);
    ui->noiseSpinBox->setValue(10.0);
    ui->orientationSpinBox->setValue(10.0);
    ui->peakThresholdSpinBox->setValue(10.0);
    ui->colorNoiseCheckBox->setChecked(true);
    ui->zoomSlider->setValue(0);
    ui->brightnessSlider->setValue(0);
    ui->clusterBox->setValue(4);

    displayImage = QImage(ui->ImgDisplay->width(), ui->ImgDisplay->height(), QImage::Format_RGB32);
}
Exemplo n.º 3
0
void
PNGTests::testWriter() {
  static const int width  = 256;
  static const int height = 256;

  // create an image and fill it with random data
  auto_ptr<Image> image(CreateImage(width, height, PF_R8G8B8A8));
  setRandomBytes((byte*)image->getPixels(), width * height * 4);

  // generate filename
  char* filename = tmpnam(0);
  CPPUNIT_ASSERT_MESSAGE("opening temporary file", filename != 0);

  // save image
  CPPUNIT_ASSERT(SaveImage(filename, FF_PNG, image.get()) == true);

  // load it back
  auto_ptr<Image> img2(OpenImage(filename, PF_R8G8B8A8));
  CPPUNIT_ASSERT_MESSAGE("reloading image file", img2.get() != 0);

  AssertImagesEqual(
    "comparing saved with loaded",
    image.get(),
    img2.get());

  // force pixel format conversion (don't destroy the old image)
  auto_ptr<Image> img3(OpenImage(filename, PF_R8G8B8));
  CPPUNIT_ASSERT(SaveImage(filename, FF_PNG, img3.get()) == true);

  remove(filename);


  //== PALETTIZED SAVING TEST ==
  // disabled until loading palettized PNGs with a correct palette format
  // is implemented.
#if 0
  char* plt_filename = tmpnam(0);
  CPPUNIT_ASSERT_MESSAGE("opening temporary file (palette)", plt_filename != 0);
  auto_ptr<Image> plt(CreateImage(256, 256, PF_I8, 256, PF_R8G8B8));
  setRandomBytes((byte*)plt->getPixels(), 256 * 256);
  setRandomBytes((byte*)plt->getPalette(), 256);

  CPPUNIT_ASSERT(SaveImage(plt_filename, FF_PNG, plt.get()) == true);

  auto_ptr<Image> plt2(OpenImage(plt_filename, FF_PNG));
  CPPUNIT_ASSERT_MESSAGE("reloading palettized image", plt2.get() != 0);
  CPPUNIT_ASSERT(plt2->getPaletteSize() == 256);
  CPPUNIT_ASSERT(plt2->getPaletteFormat() == PF_R8G8B8);
  CPPUNIT_ASSERT(plt2->getFormat() == PF_I8);
  AssertImagesEqual("Comparing palettized image", plt.get(), plt2.get());

  remove(plt_filename);
#endif
}
Exemplo n.º 4
0
VOID OpenMetafile(HWND hWnd)
{
	TCHAR buffer[4 * MAX_LOADSTRING];
	OPENFILENAME openFileName = InitializeOpenFileNameStructure(hWnd, OFN_SHOWHELP | OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST, buffer);
	TCHAR szFilter[MAX_LOADSTRING];
	TCHAR szDefExt[MAX_LOADSTRING];
	TCHAR szFile[MAX_LOADSTRING];
	TCHAR szFileTitle[MAX_LOADSTRING];
	LoadString(hInst, IDS_FILTERSTRING,(LPWSTR)szFilter, sizeof(szFilter)); 
	for (int i=0; szFilter[i]!='\0'; i++) 
	{
		if (szFilter[i] == '%') 
            szFilter[i] = '\0'; 
	}
	LoadString(hInst, IDS_DEFEXTSTRING, (LPTSTR)szDefExt, sizeof(szFilter)); 

	szFile[0] = '\0'; 
	szFileTitle[0] = '\0';
	openFileName.lpstrFilter = szFilter;
	openFileName.lpstrFile = szFile;  
	openFileName.lpstrFileTitle = szFileTitle;
	openFileName.lpstrDefExt = szDefExt;

	GetOpenFileName(&openFileName);
	OpenImage(hWnd, openFileName.lpstrFile);
}
Exemplo n.º 5
0
/******************************************************************************
 *  void SaveOnFileSave(HWND hwnd)
 * 
 *  frame window File/Save menu command handler
 *
 *  parameters:
 *      hwnd - window handle of active child window or NULL of none active
 ******************************************************************************/
void SaveOnFileSave(HWND hwnd)
{
    CHILDINSTANCEDATA PICFAR* pInstance = ChildGetInstanceData(hwnd);
    BYTE PICHUGE* pSavedImage;
    DWORD dwSavedLen;
    SAVEOP *pSaveOp;
    char szFilename[_MAX_PATH + 1];

    if ( hwnd == NULL || pInstance == NULL || !ChildIsModified(hwnd) )
        return; /* File/Save should have been grayed */
    
    pSaveOp = pInstance->pOpenOp->pSaveOp;
    lstrcpy(szFilename, pInstance->pszFilename);        
    if ( pSaveOp == 0 || pSaveOp->nFoundParmVer == 0 || pInstance->bFormatModified )
        {
        if ( !SaveGetSaveAs(szFilename, &pSaveOp) )
            return;
        }

    /* save the image, then reopen the image into the same window so the
        user can see the result of the save options */
    if ( SaveImage(hwnd, szFilename, pSaveOp, &pSavedImage, &dwSavedLen) )
        /* re-open from saved image into same window */
        OpenImage(hwnd, szFilename, pSavedImage, dwSavedLen, OP_SILENT | OP_INISETTINGS);
}
SuperPixelSegmentationGUI::SuperPixelSegmentationGUI(const std::string& imageFileName)
{
  DefaultConstructor();
  this->SourceImageFileName = imageFileName;
  
  OpenImage(this->SourceImageFileName);
}
Exemplo n.º 7
0
void OpenDropedFile(HWND hWnd, HDROP hDropInfo)
{
	TCHAR szFileName[MAX_PATH];
	DragQueryFile (hDropInfo, 0, szFileName, MAX_PATH);
	OpenImage(hWnd, szFileName);
	HDC windowDC = GetDC(hWnd);
	BitBlt(windowDC, 0, 0, rect.right, rect.bottom, memoryDC, 0, 0, SRCCOPY);
	ReleaseDC(hWnd, windowDC); 
}
void SuperPixelSegmentationGUI::on_actionOpenImage_activated()
{
  QString fileName = QFileDialog::getOpenFileName(this,
                    "OpenFile", ".", "All Files (*.*)");

  if(!fileName.isEmpty())
    {
    OpenImage(fileName.toStdString());
    }
}
Exemplo n.º 9
0
bool CDocCommands::FileTab(CString& strCommand)
{
	if (strCommand == "OPEN")
		return OpenImage();
	if (strCommand == "CLOSE")
		return CloseImage();
	if (strCommand == "SAVE")
		return SaveImage();

	return false;
}
Exemplo n.º 10
0
void MainWindow::createActions()
{
	mOpenImageAction = new QAction(tr("&Open image..."), this);
	connect(mOpenImageAction, SIGNAL(triggered()), this, SLOT(OpenImage()));

	mOpenFiltrationFormAction = new QAction(tr("&Open filtration form..."), this);
	connect(mOpenFiltrationFormAction, SIGNAL(triggered()), this, SLOT(OpenFiltrationForm()));

	mOpenSegmentationFormAction = new QAction(tr("&Open segmentation form..."), this);
	connect(mOpenSegmentationFormAction, SIGNAL(triggered()), this, SLOT(OpenSegmentationForm()));

	mOpenPerceptronFormAction = new QAction(tr("&Open perceptron form..."), this);
	connect(mOpenPerceptronFormAction, SIGNAL(triggered()), this, SLOT(OpenPerceptronForm()));
}
Exemplo n.º 11
0
void Window::dropEvent(QDropEvent *event)
{
    QList<QUrl> urls = event->mimeData()->urls();

    foreach(QUrl url, urls)
    {
        QString path = url.toLocalFile();
        QFileInfo fileInfo(path);
        if(fileInfo.isFile())
            OpenImage(path.toStdString());
        else if(fileInfo.isDir())
            OpenSeries(path.toStdString());
        else
            std::cout<<"Unknown drop"<<std::endl;
    }
Exemplo n.º 12
0
void drawGraphic( CGContextRef context, float x, float y )
{
    static GWorldPtr imageGW = NULL;
    static CGImageRef imageRef = NULL;
    static CGDataProviderRef dataProviderRef = NULL;

    Rect bounds;
    static size_t width;
    static size_t height;
    size_t bitsPerComponent;
    size_t bitsPerPixel;
    size_t bytesPerRow;
    PixMapHandle pmh;    
    
    //	Load the image if we haven't already
    if ( NULL == imageGW )
    {
        //	Load and create the GWorld
        imageGW = OpenImage();
        
        if ( imageGW != NULL )
        {
            
            GetPortBounds( imageGW, &bounds );
            width = bounds.right - bounds.left;
            height = bounds.bottom - bounds.top;
            
            pmh = GetPortPixMap( imageGW );
            bitsPerComponent = (**pmh).cmpSize;
            bitsPerPixel = (**pmh).pixelSize;
            bytesPerRow = GetPixRowBytes( pmh );
            
            LockPixels( pmh );
            
            dataProviderRef = CGDataProviderCreateWithData( NULL, GetPixBaseAddr( pmh ), height * bytesPerRow, releaseData );
            
            
            //	Create the imageRef for that GWorld
            imageRef = CGImageCreate( width, height, bitsPerComponent, bitsPerPixel, bytesPerRow, CGColorSpaceCreateDeviceRGB(), kCGImageAlphaPremultipliedFirst/*kCGImageAlphaNone*/, dataProviderRef, NULL, 0, kCGRenderingIntentDefault );
        }
    }
    
    
    //	Draw the image at 0,0
    CGContextDrawImage( context, CGRectMake( x - 20, y, 40, 40 * height / width ), imageRef );
    
}
Exemplo n.º 13
0
MainWindow::MainWindow(QWidget *parent) :
  QMainWindow(parent),
  ui(new Ui::MainWindow),
  last_canvas_selected_(NULL)
{
  ui->setupUi(this);

  LoadSettings();

  edit_mode_buttons_[EDIT_MODE_IMAGE] = ui->actionEditModeImage;
  edit_mode_buttons_[EDIT_MODE_GRID] = ui->actionEditModeGrid;
  edit_mode_buttons_[EDIT_MODE_VOXEL] = ui->actionEditModeVoxel;

  if(edit_mode_buttons_.contains(Options::instance()->current_edit_mode_)){
    current_edit_mode_button_ = edit_mode_buttons_[Options::instance()->current_edit_mode_];
    current_edit_mode_button_->setChecked(true);
  }

  tool_buttons_[TOOL_SELECTION] = ui->actionSelection_Tool;
  tool_buttons_[TOOL_ZOOM] = ui->actionZoom_Tool;
  tool_buttons_[TOOL_PENCIL] = ui->actionPencil_Tool;
  tool_buttons_[TOOL_FILL] = ui->actionFill_Tool;
  tool_buttons_[TOOL_LINE] = ui->actionLine_Tool;
  tool_buttons_[TOOL_RECTANGLE] = ui->actionRectangle_Tool;
  tool_buttons_[TOOL_ELIPSE] = ui->actionElipse_Tool;

  if(tool_buttons_.contains(Options::instance()->current_tool_)){
    current_tool_button_ = tool_buttons_[Options::instance()->current_tool_];
    current_tool_button_->setChecked(true);
  }

  // Menu Actions
  connect(ui->actionOpen,SIGNAL(triggered()),this,SLOT(OpenImage()));
  connect(ui->actionSave,SIGNAL(triggered()),this,SLOT(SaveImage()));
  connect(ui->actionTile_Size,SIGNAL(triggered()),this,SLOT(SetCursorSize()));
  connect(ui->actionNew,SIGNAL(triggered()),this,SLOT(NewImage()));

  // Tool Actions
  connect(ui->actionSelection_Tool,SIGNAL(triggered()),this,SLOT(SelectSelectionTool()));
  connect(ui->actionFill_Tool,SIGNAL(triggered()),this,SLOT(SelectFillTool()));
  connect(ui->actionPencil_Tool,SIGNAL(triggered()),this,SLOT(SelectSelectionTool()));

  connect(ui->mdiArea,SIGNAL(subWindowActivated(QMdiSubWindow*)),this,SLOT(CurrentWindowChanged(QMdiSubWindow*)));
}
Exemplo n.º 14
0
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    connect(ui->openButton, SIGNAL(clicked()), this, SLOT(OpenImage()));
    connect(ui->saveButton, SIGNAL(clicked()), this, SLOT(SaveImage()));
    connect(ui->harrisButton, SIGNAL(clicked()), this, SLOT(HarrisCornerImage()));
    connect(ui->matchButton, SIGNAL(clicked()), this, SLOT(MatchImages()));
    connect(ui->RANSACButton, SIGNAL(clicked()), this, SLOT(RANSAC()));
    connect(ui->stitchButton, SIGNAL(clicked()), this, SLOT(StitchImages()));

    ui->harrisSpinBox->setValue(2.0);
    ui->harrisThresSpinBox->setValue(50.0);
    ui->RANSACThresSpinBox->setValue(5.0);
    ui->iterationsBox->setValue(200);

    ui->tabWidget->setCurrentIndex(0);
}
Exemplo n.º 15
0
void ClusterDivider2D::GetDividedCluster(std::vector<ObjectCluster>& divided_objects)
{
    /* 获取mask_的边缘 */
    cv::Mat contour = ~mask_;
    std::vector<std::vector<cv::Point> > contours;
    cv::findContours( contour, contours, CV_RETR_CCOMP , CV_CHAIN_APPROX_NONE);

    for (int idx=0; idx<contours.size(); ++idx)
    {
        /* 面积初判 */
        double cont_size = cv::contourArea(contours[idx]);
        if (cont_size>20000 || cont_size<80) continue;
         
        /* 尝试生成目标 */
        cv::Mat sub_mask(mask_.size(), CV_8UC1, cv::Scalar(0));
        cv::drawContours(sub_mask, contours, idx, cv::Scalar(255), CV_FILLED, 4);
        OpenImage(sub_mask, 0, 1, 0);
        ObjectCluster object_cluster( GetCloudFromMask(sub_mask, cloud_));
        if (object_cluster.isValid())
            divided_objects.push_back(object_cluster);        
    }
}
Exemplo n.º 16
0
void
PNGTests::testLoader() {
  static const string base = "images/pngsuite/";

  static const char* good[] = {
    "basi0g01.png",
    "basi0g02.png",
    "basi0g04.png",
    "basi0g08.png",
    "basi0g16.png",
    "basi2c08.png",
    "basi2c16.png",
    "basi3p01.png",
    "basi3p02.png",
    "basi3p04.png",
    "basi3p08.png",
    "basi4a08.png",
    "basi4a16.png",
    "basi6a08.png",
    "basi6a16.png",
    "basn0g01.png",
    "basn0g02.png",
    "basn0g04.png",
    "basn0g08.png",
    "basn0g16.png",
    "basn2c08.png",
    "basn2c16.png",
    "basn3p01.png",
    "basn3p02.png",
    "basn3p04.png",
    "basn3p08.png",
    "basn4a08.png",
    "basn4a16.png",
    "basn6a08.png",
    "basn6a16.png",
    "bgai4a08.png",
    "bgai4a16.png",
    "bgan6a08.png",
    "bgan6a16.png",
    "bgbn4a08.png",
    "bggn4a16.png",
    "bgwn6a08.png",
    "bgyn6a16.png",
    "ccwn2c08.png",
    "ccwn3p08.png",
    "cdfn2c08.png",
    "cdhn2c08.png",
    "cdsn2c08.png",
    "cdun2c08.png",
    "ch1n3p04.png",
    "ch2n3p08.png",
    "cm0n0g04.png",
    "cm7n0g04.png",
    "cm9n0g04.png",
    "cs3n2c16.png",
    "cs3n3p08.png",
    "cs5n2c08.png",
    "cs5n3p08.png",
    "cs8n2c08.png",
    "cs8n3p08.png",
    "ct0n0g04.png",
    "ct1n0g04.png",
    "ctzn0g04.png",
    "f00n0g08.png",
    "f00n2c08.png",
    "f01n0g08.png",
    "f01n2c08.png",
    "f02n0g08.png",
    "f02n2c08.png",
    "f03n0g08.png",
    "f03n2c08.png",
    "f04n0g08.png",
    "f04n2c08.png",
    "g03n0g16.png",
    "g03n2c08.png",
    "g03n3p04.png",
    "g04n0g16.png",
    "g04n2c08.png",
    "g04n3p04.png",
    "g05n0g16.png",
    "g05n2c08.png",
    "g05n3p04.png",
    "g07n0g16.png",
    "g07n2c08.png",
    "g07n3p04.png",
    "g10n0g16.png",
    "g10n2c08.png",
    "g10n3p04.png",
    "g25n0g16.png",
    "g25n2c08.png",
    "g25n3p04.png",
    "oi1n0g16.png",
    "oi1n2c16.png",
    "oi2n0g16.png",
    "oi2n2c16.png",
    "oi4n0g16.png",
    "oi4n2c16.png",
    "oi9n0g16.png",
    "oi9n2c16.png",
    "pngsuite_logo.png",
    "pp0n2c16.png",
    "pp0n6a08.png",
    "ps1n0g08.png",
    "ps1n2c16.png",
    "ps2n0g08.png",
    "ps2n2c16.png",
    "s01i3p01.png",
    "s01n3p01.png",
    "s02i3p01.png",
    "s02n3p01.png",
    "s03i3p01.png",
    "s03n3p01.png",
    "s04i3p01.png",
    "s04n3p01.png",
    "s05i3p02.png",
    "s05n3p02.png",
    "s06i3p02.png",
    "s06n3p02.png",
    "s07i3p02.png",
    "s07n3p02.png",
    "s08i3p02.png",
    "s08n3p02.png",
    "s09i3p02.png",
    "s09n3p02.png",
    "s32i3p04.png",
    "s32n3p04.png",
    "s33i3p04.png",
    "s33n3p04.png",
    "s34i3p04.png",
    "s34n3p04.png",
    "s35i3p04.png",
    "s35n3p04.png",
    "s36i3p04.png",
    "s36n3p04.png",
    "s37i3p04.png",
    "s37n3p04.png",
    "s38i3p04.png",
    "s38n3p04.png",
    "s39i3p04.png",
    "s39n3p04.png",
    "s40i3p04.png",
    "s40n3p04.png",
    "tbbn1g04.png",
    "tbbn2c16.png",
    "tbbn3p08.png",
    "tbgn2c16.png",
    "tbgn3p08.png",
    "tbrn2c08.png",
    "tbwn1g16.png",
    "tbwn3p08.png",
    "tbyn3p08.png",
    "tp0n1g08.png",
    "tp0n2c08.png",
    "tp0n3p08.png",
    "tp1n3p08.png",
    "z00n2c08.png",
    "z03n2c08.png",
    "z06n2c08.png",
    "z09n2c08.png",
  };
  static const int good_length = sizeof(good) / sizeof(*good);

  static const char* bad[] = {
    "x00n0g01.png",
    "xcrn0g04.png",
    "xlfn0g04.png",
  };
  static const int bad_length = sizeof(bad) / sizeof(*bad);

    
  for (int i = 0; i < good_length; ++i) {
    string fn = base + good[i];
    auto_ptr<Image> image(OpenImage(fn.c_str()));
    CPPUNIT_ASSERT_MESSAGE("should work - opening " + fn, image.get() != 0);
  }

  for (int i = 0; i < bad_length; ++i) {
    string fn = base + bad[i];
    auto_ptr<Image> image(OpenImage(fn.c_str()));
    CPPUNIT_ASSERT_MESSAGE("should fail - opening " + fn, image.get() == 0);
  }
}
Exemplo n.º 17
0
void OpenImage(const std::string& filename, ImageData& img)
{
	img.data = OpenImage(filename, img.w, img.h, img.d);
}
Exemplo n.º 18
0
int main()
{
	/*----------------------------Part 1------------------------------------*/
	int ysize = 342;
	int xsize = 546;
	int padding = 1;


	float	**inImage = ImageInit(xsize, ysize);
	float	**padImage = ImageInit(xsize + 2*padding, ysize + 2*padding);
	float	**sobelImage = ImageInit(xsize, ysize);
	float	**threshImage = ImageInit(xsize, ysize);

	
	OpenImage("porsche", xsize, ysize, inImage);
	PadImage(inImage, padImage, xsize, ysize, padding);
	Sobel(padImage, sobelImage, xsize + 2*padding, ysize + 2*padding);
	SaveImage("porsche", "_sobel", xsize, ysize, sobelImage);
	BinThresh(sobelImage, threshImage, xsize, ysize, 60);
	SaveImage("porsche", "_thresh60", xsize, ysize, threshImage);


	ysize = 256;
	xsize = 256;
	OpenImage("mri", xsize, ysize, inImage);
	PadImage(inImage, padImage, xsize, ysize, padding);
	Sobel(padImage, sobelImage, xsize + 2 * padding, ysize + 2 * padding);
	SaveImage("mri", "_sobel", xsize, ysize, sobelImage);
	BinThresh(sobelImage, threshImage, xsize, ysize, 50);
	SaveImage("mri", "_thresh50", xsize, ysize, threshImage);

	free(inImage);
	free(padImage);
	free(sobelImage);
	free(threshImage);

	/*----------------------------Part 2------------------------------------*/
	xsize = ysize = 256;
	float	**circImage = ImageInit(xsize, ysize);
	float	**padCirc = ImageInit(xsize + 2 * padding, ysize + 2 * padding);
	float	**sobelCirc = ImageInit(xsize, ysize);
	float	**threshCirc = ImageInit(xsize, ysize);
	float	**noiseCirc = ImageInit(xsize, ysize);
	float	**padNoiseCirc = ImageInit(xsize + 2 * padding, ysize + 2 * padding);
	float	**sobelNoiseCirc = ImageInit(xsize, ysize);
	float	**noiseGaussCirc = ImageInit(xsize, ysize);
	float	**padNoiseGaussCirc = ImageInit(xsize + 2 * padding, ysize + 2 * padding);
	float	**sobelNoiseGaussCirc = ImageInit(xsize, ysize);
	float	**sobelNoiseGaussThreshCirc = ImageInit(xsize, ysize);

	float **test = ImageInit(xsize + 2, ysize +2);

	int c = 256 / 2 - 1;
	CreateCircle(circImage, ysize, xsize, c, c, 50, 60);
	CreateCircle(circImage, ysize, xsize, c, c, 50, 40);
	CreateCircle(circImage, ysize, xsize, c, c, 50, 20);


	SaveImage("circles", "", xsize, ysize, circImage);
	PadImage(circImage, padCirc, xsize, ysize, padding);
	Sobel(padCirc, sobelCirc, xsize + 2 * padding, ysize + 2 * padding);
	SaveImage("circles", "_sobel", xsize, ysize, sobelCirc);

	BinThresh(sobelCirc, threshCirc, xsize, ysize, 100);
	SaveImage("circles", "_thresh100", xsize, ysize, threshCirc);

	// Noise = 10
	AddUniNoise(circImage, noiseCirc, xsize, ysize, 10);
	SaveImage("circles", "_noise10", xsize, ysize, noiseCirc);

	PadImage(noiseCirc, padNoiseCirc, xsize, ysize, padding);
	Sobel(padNoiseCirc, sobelNoiseCirc, xsize + 2 * padding, ysize + 2 * padding);
	BinThresh(sobelNoiseCirc, sobelNoiseCirc, xsize, ysize, 100);
	SaveImage("circles", "_noise_sobel10", xsize, ysize, sobelNoiseCirc);
	AccuracyReport(threshCirc, sobelNoiseCirc, xsize, ysize);

	GaussianSmooth(padNoiseCirc, noiseGaussCirc, xsize + 2 * padding, ysize + 2 * padding);
	SaveImage("circles", "_noise_gauss10", xsize, ysize, noiseGaussCirc);
	PadImage(noiseGaussCirc, padNoiseGaussCirc, xsize, ysize, padding);
	Sobel(padNoiseGaussCirc, sobelNoiseGaussCirc, xsize + 2 * padding, ysize + 2 * padding);
	BinThresh(sobelNoiseGaussCirc, sobelNoiseGaussThreshCirc, xsize, ysize, 100);
	SaveImage("circles", "_noise_sobel_gauss_thresh10", xsize, ysize, sobelNoiseGaussThreshCirc);
	AccuracyReport(threshCirc, sobelNoiseGaussThreshCirc, xsize, ysize);

	// Noise = 50
	AddUniNoise(circImage, noiseCirc, xsize, ysize, 50);
	SaveImage("circles", "_noise50", xsize, ysize, noiseCirc);

	PadImage(noiseCirc, padNoiseCirc, xsize, ysize, padding);
	Sobel(padNoiseCirc, sobelNoiseCirc, xsize + 2 * padding, ysize + 2 * padding);
	BinThresh(sobelNoiseCirc, sobelNoiseCirc, xsize, ysize, 100);
	SaveImage("circles", "_noise_sobel50", xsize, ysize, sobelNoiseCirc);
	AccuracyReport(threshCirc, sobelNoiseCirc, xsize, ysize);

	GaussianSmooth(padNoiseCirc, noiseGaussCirc, xsize + 2 * padding, ysize + 2 * padding);
	SaveImage("circles", "_noise_gauss50", xsize, ysize, noiseGaussCirc);
	PadImage(noiseGaussCirc, padNoiseGaussCirc, xsize, ysize, padding);
	Sobel(padNoiseGaussCirc, sobelNoiseGaussCirc, xsize + 2 * padding, ysize + 2 * padding);
	BinThresh(sobelNoiseGaussCirc, sobelNoiseGaussThreshCirc, xsize, ysize, 100);
	SaveImage("circles", "_noise_sobel_gauss_thresh50", xsize, ysize, sobelNoiseGaussThreshCirc);
	AccuracyReport(threshCirc, sobelNoiseGaussThreshCirc, xsize, ysize);


	// Noise = 100
	AddUniNoise(circImage, noiseCirc, xsize, ysize, 100);
	SaveImage("circles", "_noise100", xsize, ysize, noiseCirc);

	PadImage(noiseCirc, padNoiseCirc, xsize, ysize, padding);
	Sobel(padNoiseCirc, sobelNoiseCirc, xsize + 2 * padding, ysize + 2 * padding);
	BinThresh(sobelNoiseCirc, sobelNoiseCirc, xsize, ysize, 100);
	SaveImage("circles", "_noise_sobel100", xsize, ysize, sobelNoiseCirc);
	AccuracyReport(threshCirc, sobelNoiseCirc, xsize, ysize);

	GaussianSmooth(padNoiseCirc, noiseGaussCirc, xsize + 2 * padding, ysize + 2 * padding);
	SaveImage("circles", "_noise_gauss100", xsize, ysize, noiseGaussCirc);
	PadImage(noiseGaussCirc, padNoiseGaussCirc, xsize, ysize, padding);
	Sobel(padNoiseGaussCirc, sobelNoiseGaussCirc, xsize + 2 * padding, ysize + 2 * padding);
	BinThresh(sobelNoiseGaussCirc, sobelNoiseGaussThreshCirc, xsize, ysize, 100);
	SaveImage("circles", "_noise_sobel_gauss_thresh100", xsize, ysize, sobelNoiseGaussThreshCirc);
	AccuracyReport(threshCirc, sobelNoiseGaussThreshCirc, xsize, ysize);


	free(circImage);
	free(padCirc);
	free(sobelCirc);
	free(threshCirc);
	free(noiseCirc);
	free(padNoiseCirc);
	free(sobelNoiseCirc);
	free(noiseGaussCirc);
	free(padNoiseGaussCirc);
	free(sobelNoiseGaussCirc);
	free(sobelNoiseGaussThreshCirc);

	return 0;
}
Exemplo n.º 19
0
/*
 * ImgEdFrameProc - handle messages for the image editor application
 */
WPI_MRESULT CALLBACK ImgEdFrameProc( HWND hwnd, WPI_MSG msg,
                                 WPI_PARAM1 wparam, WPI_PARAM2 lparam )
{
    static BOOL         window_destroyed = FALSE;
    static HMENU        hmenu;
    ctl_id              cmdid;
    img_node            *node;
    WPI_RECT            rcmain;
#ifndef __OS2_PM__
    about_info          ai;
#endif
    WPI_RECTDIM         left, top;

    if( !window_destroyed ) {
        enableMainItems( hmenu );
    }

    switch( msg ) {
    case UM_EXIT:
        _wpi_sendmessage( hwnd, WM_COMMAND, IMGED_CLOSEALL, 0L );
        /* fall through */

    case UM_EXIT_NO_SAVE:
        if( _wpi_getfirstchild( _wpi_getclient( ClientWindow ) ) != NULL ) {
            break;
        }
#ifndef __OS2_PM__
        _wpi_destroywindow( _wpi_getframe( hwnd ) );
#else
        _wpi_sendmessage( hwnd, WM_CLOSE, 0, 0 );
#endif

        break;

    case UM_SAVE_ALL:
        SaveAllImages();
        break;

    case WM_CREATE:
        hmenu = _wpi_getmenu( _wpi_getframe( hwnd ) );
#ifndef __OS2_PM__
        createClientWindow( hwnd );
#endif
        if( !InitStatusLine( hwnd ) ) {
            return( -1 );
        }

        InitFunctionBar( hwnd );
        InitIconInfo();
        InitializeCursors();

        /*
         * Set values from profile information ...
         */
        if( ImgedConfigInfo.brush_size <= 5 && ImgedConfigInfo.brush_size >= 2 ) {
            checkBrushItem( hmenu, IMGED_2x2 - 2 + ImgedConfigInfo.brush_size );
        }
        if( ImgedConfigInfo.grid_on ) {
            CheckGridItem( hmenu );
        }
        if( ImgedConfigInfo.square_grid ) {
            CheckSquareGrid( hmenu );
        }
        if( ImgedConfigInfo.show_state & SET_SHOW_VIEW ) {
            CheckViewItem( hmenu );
        }

        _wpi_enablemenuitem( hmenu, IMGED_CRESET, FALSE, FALSE );
        _wpi_enablemenuitem( hmenu, IMGED_RCOLOR, FALSE, FALSE );
#ifndef __OS2_PM__
        // not necessary for PM
        InitMenus( hmenu );
#endif
        SetHintText( IEAppTitle );
        return( 0 );
#ifdef __NT__
    case WM_DROPFILES:
        OpenImage( (HANDLE)wparam );
        break;
#endif
    case WM_MOVE:
        _wpi_getwindowrect( hwnd, &rcmain );
        if( !ImgedConfigInfo.ismaximized ) {
            ImgedConfigInfo.last_xpos = ImgedConfigInfo.x_pos;
            ImgedConfigInfo.last_ypos = ImgedConfigInfo.y_pos;
            _wpi_getrectvalues( rcmain, &left, &top, NULL, NULL );
            ImgedConfigInfo.x_pos = (short)left;
            ImgedConfigInfo.y_pos = (short)top;
        }
        return( 0 );

    case WM_SIZE:
        ResizeFunctionBar( lparam );
        ResizeStatusBar( lparam );
#ifndef __OS2_PM__
        if( ClientWindow != NULL ) {
            setClientSize( hwnd );
        }
#else
        resizeClientArea( lparam );
#endif

        if( !_imgwpi_issizeminimized( wparam ) && !_imgwpi_issizemaximized( wparam ) ) {
            _wpi_getwindowrect( hwnd, &rcmain );
            ImgedConfigInfo.width = (short)_wpi_getwidthrect( rcmain );
            ImgedConfigInfo.height = (short)_wpi_getheightrect( rcmain );
            ImgedConfigInfo.ismaximized = FALSE;
        } else {
            ImgedConfigInfo.x_pos = ImgedConfigInfo.last_xpos;
            ImgedConfigInfo.y_pos = ImgedConfigInfo.last_ypos;
            ImgedConfigInfo.ismaximized = _imgwpi_issizemaximized( wparam );
        }
        return( FALSE );

    case WM_MENUSELECT:
#ifndef __OS2_PM__
        if( GET_WM_MENUSELECT_FLAGS( wparam, lparam ) & MF_SEPARATOR ) {
            break;
        }
        if( GET_WM_MENUSELECT_FLAGS( wparam, lparam ) & MF_SYSMENU ) {
            PrintHintTextByID( WIE_SYSMENUOPERATIONS, NULL );
            break;
        }
#endif
        ShowHintText( LOWORD( wparam ) );
        break;

    case WM_COMMAND:
        cmdid = LOWORD( wparam );
        if( !IEIsMenuIDValid( hmenu, cmdid ) ) {
            break;
        }
        switch( cmdid ) {
        case IMGED_NEW:
            if( !ImgedIsDDE ) {
                if( !NewImage( UNDEF_IMG, NULL ) ) {
                    PrintHintTextByID( WIE_NEIMAGENOTCREATED, NULL );
                }
            }
            break;

        case IMGED_CLOSE:
            node = GetCurrentNode();
            if( node != NULL ) {
                _wpi_sendmessage( node->hwnd, WM_CLOSE, 0, 0L );
            }
            break;

        case IMGED_CLOSEALL:
            CloseAllImages();
            break;

        case IMGED_HELP:
            IEHelpRoutine();
            break;

        case IMGED_HELP_SEARCH:
            IEHelpSearchRoutine();
            break;

        case IMGED_HELP_ON_HELP:
            IEHelpOnHelpRoutine();
            break;

        case IMGED_ABOUT:
#ifndef __OS2_PM__
            ai.owner = hwnd;
            ai.inst = Instance;
            ai.name = IEAllocRCString( WIE_ABOUTTEXT );
            ai.version = IEAllocRCString( WIE_ABOUTVERSION );
            ai.title = IEAllocRCString( WIE_ABOUTTITLE );
            DoAbout( &ai );
            if( ai.name != NULL ) {
                IEFreeRCString( ai.name );
            }
            if( ai.version != NULL ) {
                IEFreeRCString( ai.version );
            }
            if( ai.title != NULL ) {
                IEFreeRCString( ai.title );
            }
#endif
            break;

#ifndef __OS2_PM__
        case IMGED_DDE_UPDATE_PRJ:
            IEUpdateDDEEditSession();
            break;
#endif

        case IMGED_SAVE_AS:
            SaveFile( SB_SAVE_AS );
            break;

        case IMGED_SAVE:
            SaveFile( SB_SAVE );
            break;

        case IMGED_OPEN:
            if( !ImgedIsDDE ) {
                OpenImage( NULL );
            }
            break;

        case IMGED_CLEAR:
            ClearImage();
            break;

        case IMGED_NEWIMG:
            AddNewIcon();
            break;

        case IMGED_SELIMG:
            SelectIconImg();
            break;

        case IMGED_DELIMG:
            DeleteIconImg();
            break;

        case IMGED_UNDO:
            UndoOp();
            break;

        case IMGED_REDO:
            RedoOp();
            break;

        case IMGED_REST:
            RestoreImage();
            break;

        case IMGED_SNAP:
#ifndef __OS2_PM__
            SnapPicture();
#endif
            break;

        case IMGED_RIGHT:
        case IMGED_LEFT:
        case IMGED_UP:
        case IMGED_DOWN:
            ShiftImage( cmdid );
            break;

        case IMGED_FLIPHORZ:
        case IMGED_FLIPVERT:
            FlipImage( cmdid );
            break;

        case IMGED_ROTATECC:
        case IMGED_ROTATECL:
            RotateImage( cmdid );
            break;

        case IMGED_PASTE:
            PlaceAndPaste();
            break;

        case IMGED_COPY:
            IECopyImage();
            break;

        case IMGED_CUT:
            CutImage();
            break;

        case IMGED_COLOR:
            CheckPaletteItem( hmenu );
            break;

        case IMGED_VIEW:
            CheckViewItem( hmenu );
            break;

        case IMGED_TOOLBAR:
            CheckToolbarItem( hmenu );
            break;

        case IMGED_SQUARE:
            CheckSquareGrid( hmenu );
            break;

        case IMGED_SIZE:
            ChangeImageSize();
            break;

        case IMGED_GRID:
            CheckGridItem( hmenu );
            break;

        case IMGED_MAXIMIZE:
            MaximizeCurrentChild();
            break;

        case IMGED_SETTINGS:
            SelectOptions();
            break;

        case IMGED_2x2:
        case IMGED_3x3:
        case IMGED_4x4:
        case IMGED_5x5:
            checkBrushItem( hmenu, cmdid );
            break;

        case IMGED_CEDIT:
#ifndef __OS2_PM__
            EditColors();
#endif
            break;

        case IMGED_CRESET:
#ifndef __OS2_PM__
            RestoreColors();
#endif
            break;

        case IMGED_CSCREEN:
            ChooseBkColor();
            break;

        case IMGED_SCOLOR:
#ifndef __OS2_PM__
            SaveColorPalette();
#endif
            break;

        case IMGED_LCOLOR:
#ifndef __OS2_PM__
            if( LoadColorPalette() ) {
                _wpi_enablemenuitem( hmenu, IMGED_RCOLOR, TRUE, FALSE );
            }
#endif
            break;

        case IMGED_RCOLOR:
            RestoreColorPalette();
            break;

        case IMGED_FREEHAND:
        case IMGED_LINE:
        case IMGED_RECTO:
        case IMGED_RECTF:
        case IMGED_CIRCLEO:
        case IMGED_CIRCLEF:
        case IMGED_FILL:
        case IMGED_BRUSH:
        case IMGED_CLIP:
        case IMGED_HOTSPOT:
            SetToolType( cmdid );
            PushToolButton( cmdid );
            break;

        case IMGED_ARRANGE:
#ifndef __OS2_PM__
            SendMessage( ClientWindow, WM_MDIICONARRANGE, 0, 0L );
#endif
            break;

        case IMGED_TILE:
#ifndef __OS2_PM__
            SendMessage( ClientWindow, WM_MDITILE, MDITILE_VERTICAL, 0L );
#endif
            break;

        case IMGED_CASCADE:
#ifndef __OS2_PM__
            SendMessage( ClientWindow, WM_MDICASCADE, MDITILE_SKIPDISABLED, 0L );
#endif
            break;

        case IMGED_EXIT:
            _wpi_sendmessage( hwnd, WM_COMMAND, IMGED_CLOSEALL, 0L );

            if( _wpi_getfirstchild( _wpi_getclient( ClientWindow ) ) != NULL ) {
                break;
            }
#ifndef __OS2_PM__
            _wpi_destroywindow( _wpi_getframe( hwnd ) );
#else
            _wpi_sendmessage( hwnd, WM_CLOSE, 0, 0 );
#endif
            break;

        default:
#if 1
            return( _imgwpi_defframeproc( hwnd, ClientWindow, msg, wparam, lparam ) );
#else
            return( 0 );
#endif
        }
        return( 0 );

#ifndef __OS2_PM__
    case WM_COMPACTING:
        RelieveUndos();
        return 0;
#endif

    case WM_QUERYENDSESSION:
        if( _wpi_isiconic( _wpi_getframe( hwnd ) ) ) {
            if( ImgedConfigInfo.ismaximized ) {
                _wpi_maximizewindow( _wpi_getframe( hwnd ) );
            } else {
                _wpi_showwindow( _wpi_getframe( hwnd ), SW_SHOWNORMAL );
            }
        }
        _wpi_sendmessage( hwnd, WM_COMMAND, IMGED_CLOSEALL, 0L );

        if( _wpi_getfirstchild( _wpi_getclient( ClientWindow ) ) != NULL ) {
            return( 0 );
        }
        return( (WPI_MRESULT)1 );

    case WM_CLOSE:
        // wParam is non-zero if the DDE connection died
        if( !wparam && !ImgEdEnableMenuInput ) {
            // this prevents the user from closing the editor during
            // DDE initialization
            return( 0 );
        }
        _wpi_sendmessage( hwnd, WM_COMMAND, IMGED_CLOSEALL, 0L );
#ifdef __OS2_PM__
        return( _wpi_defwindowproc( hwnd, msg, wparam, lparam ) );
#else

        if( _wpi_getfirstchild( _wpi_getclient( ClientWindow ) ) != NULL ) {
            return( 0 );
        }
        window_destroyed = TRUE;
        _wpi_destroywindow( _wpi_getframe( hwnd ) );
        return( 0 );
#endif

    case WM_DESTROY:
#ifndef __OS2_PM__
        WWinHelp( HMainWindow, "resimg.hlp", HELP_QUIT, 0 );
#endif
        FiniStatusLine();
        CleanupClipboard();
        CleanupCursors();
        CloseToolBar();
        CloseFunctionBar();
        _wpi_deletefont( SmallFont );
        _wpi_postquitmessage( 0 );
        return( 0 );
    default:
        break;
    }
    return( _imgwpi_defframeproc( hwnd, ClientWindow, msg, wparam, lparam ) );

} /* ImgEdFrameProc */
Exemplo n.º 20
0
//---------------------------------------------------------------------------
void __fastcall TForm1::JPEGClick(TObject *Sender)
{
        OpenImage(1);        
}
Exemplo n.º 21
0
//---------------------------------------------------------------------------
void __fastcall TForm1::BMPClick(TObject *Sender)
{
        OpenImage(0);
}
Exemplo n.º 22
0
void OpenDropedFile(HWND hWnd, HDROP hDropInfo)
{
	TCHAR szFileName[MAX_PATH];
	DragQueryFile (hDropInfo, 0, szFileName, MAX_PATH);
	OpenImage(hWnd, szFileName);
}
Exemplo n.º 23
0
void FiletypeEditor(void)
{
	filetype_ed_data *data=0;
	IPCData *ipc;
	short success=0,pending_quit=0;
	BOOL change_flag=0;

	// Do startup
	if (!(ipc=Local_IPC_ProcStartup((ULONG *)&data, (APTR)&_filetypeed_init)))
		return;

	// Create App stuff
	if ((data->app_port=CreateMsgPort()))
	{
		data->app_window=AddAppWindowA(0,0,data->window,data->app_port,0);
	}

	// Get icon image
	if (data->type->icon_path)
	{
#ifdef USE_DRAWICONSTATE
		{
			char *path_copy;
			data->icon_image=NULL;
			if ((path_copy=AllocMemH(0,strlen(data->type->icon_path)+1)))
			{
				// icon_path is guaranteed to have a .info at the end
				stccpy(path_copy,data->type->icon_path,strlen(data->type->icon_path)-4);
				data->icon_image=GetCachedDiskObject(path_copy,0);
				FreeMemH(path_copy);
			}
		}
#else
		data->icon_image=OpenImage(data->type->icon_path,0);
#endif
		// Show icon image
		filetypeed_show_icon(data);
	}

	// Launch class editor immediately?
	if (data->edit_flag) filetypeed_edit_definition(data);

	// Message loop
	FOREVER
	{
		IPCMessage *msg;
		struct IntuiMessage *imsg;
		short break_flag=0;

		// Check drag
		if (config_drag_check(&data->drag))
		{
			// End drag
			filetypeed_end_drag(data,0);
		}

		// Task message?
		while ((msg=(IPCMessage *)GetMsg(ipc->command_port)))
		{
			switch (msg->command)
			{
				// Close message?
				case IPC_QUIT:
					if (!pending_quit)
					{
						success=msg->flags;
						break_flag=1;
					}
					break;


				// Activate
				case IPC_ACTIVATE:
					if (data->window)
					{
						WindowToFront(data->window);
						ActivateWindow(data->window);
					}
					break;


				// Editor saying goodbye
				case IPC_GOODBYE:
					{
						ULONG which;

						// What's just gone?
						which=IPC_GetGoodbye(msg);

						// Class editor?
						if (which==(ULONG)-1) data->class_editor=0;

						// Icon menu editor?
						else
						if (which>15)
						{
							Att_Node *node;

							// Go through icon list
							for (node=(Att_Node *)data->icon_list->list.lh_Head;
								node->node.ln_Succ;
								node=(Att_Node *)node->node.ln_Succ)
							{
								// Match function
								if (((func_node *)node->data)->func==(Cfg_Function *)which)
								{
									// Clear editor pointer
									((func_node *)node->data)->editor=0;

									// Check for invalid function
									if (filetypeed_check_iconmenu(data,node,FALSE))
										change_flag=1;
									break;
								}
							}
						}

						// Normal filetype editor
						else data->editor[which]=0;
					}
					break;


				// Editor returning a function
				case FUNCTIONEDIT_RETURN:
					{
						short ret;

						if ((ret=filetypeed_receive_edit(
							data,
							(FunctionReturn *)msg->data)))
						{
							change_flag=1;
							filetypeed_update_actions(data);
							if (ret==2) filetypeed_update_iconmenu(data);
						}
					}
					break;


				// Class editor returning
				case CLASSEDIT_RETURN:
					filetypeed_receive_class(data,(Cfg_Filetype *)msg->data);
					change_flag=1;
					break;


				// Get a copy of a button
				case BUTTONEDIT_CLIP_BUTTON:

					// Handle this button
					if (filetypeed_get_button(data,(Cfg_Button *)msg->data,(Point *)msg->data_free))
						change_flag=1;
					break;
			}

			// Reply the message
			IPC_Reply(msg);
		}

		// Intuimessage
		if (data->window)
		{
			while ((imsg=GetWindowMsg(data->window->UserPort)))
			{
				struct IntuiMessage msg_copy;
				struct Gadget *gadget;
				struct TagItem *tags;

				// Copy message
				msg_copy=*imsg;

				// Don't reply to IDCMPUPDATE messages just yet
				if (imsg->Class!=IDCMP_IDCMPUPDATE)
				{
					ReplyWindowMsg(imsg);
					imsg=0;
				}

				// Get gadget and tag pointers
				gadget=(struct Gadget *)msg_copy.IAddress;
				tags=(struct TagItem *)gadget;

				// Look at message
				switch (msg_copy.Class)
				{
					// Close window
					case IDCMP_CLOSEWINDOW:
						if (!pending_quit) break_flag=1;
						break;


					// Gadget
					case IDCMP_GADGETUP:
						switch (gadget->GadgetID)
						{
							// Use
							case GAD_FILETYPEED_USE:
								success=1;

							// Cancel
							case GAD_FILETYPEED_CANCEL:
								if (!pending_quit) break_flag=1;
								break;


							// Select a function
							case GAD_FILETYPEED_ACTION_LIST:
								{
									Att_Node *node;

									// Get selected node
									if (!(node=Att_FindNode(data->action_list,msg_copy.Code)))
										break;

									// Enable edit action button
									DisableObject(data->objlist,GAD_FILETYPES_EDIT_ACTION,FALSE);

									// Double-click?
									if (!(DoubleClick(data->last_sec,data->last_mic,msg_copy.Seconds,msg_copy.Micros)) ||
										node!=data->last_sel)
									{
										data->last_sec=msg_copy.Seconds;
										data->last_mic=msg_copy.Micros;
										data->last_sel=node;
										data->last_icon=0;
										break;
									}
								}

								// Fall through

							case GAD_FILETYPES_EDIT_ACTION:

								// No current selection?
								if (!data->last_sel) break;

								// Is editor already up for this action?	
								if (data->editor[data->last_sel->data])
									IPC_Command(data->editor[data->last_sel->data],IPC_ACTIVATE,0,0,0,0);

								// Need to launch editor
								else filetypeed_edit_action(data,data->last_sel->data,data->last_sel->node.ln_Name);
								break;


							// Delete action
							case GAD_FILETYPES_DEL_ACTION:

								// No current selection?
								if (!data->last_sel) break;

								// Is editor up for this action?	
								if (data->editor[data->last_sel->data])
									IPC_Command(data->editor[data->last_sel->data],IPC_QUIT,0,0,0,0);

								// Delete it
								if (filetypeed_del_action(data,data->last_sel->data))
									change_flag=1;
								break;


							// Edit filetype definition
							case GAD_FILETYPEED_EDIT_CLASS:

								// Is class editor already up for this action?	
								if (data->class_editor)
									IPC_Command(data->class_editor,IPC_ACTIVATE,0,0,0,0);

								// Need to launch editor
								else filetypeed_edit_definition(data);
								break;


							// Select icon
							case GAD_FILETYPEED_SELECT_ICON:
								if (filetypeed_pick_icon(data))
									change_flag=1;
								break;


							// Add to icon menu
							case GAD_FILETYPES_ADD_ICON_MENU:
								filetypeed_add_iconmenu(data);
								break;


							// Select an icon menu
							case GAD_FILETYPES_ICON_MENU:
								{
									Att_Node *last=data->last_icon;

									// Handle selection
									if (!(filetypeed_sel_icon(data,msg_copy.Code))) break;

									// Double-click?
									if (data->last_icon!=last ||
										!(DoubleClick(
											data->last_sec,
											data->last_mic,
											msg_copy.Seconds,
											msg_copy.Micros)))
									{
										data->last_sec=msg_copy.Seconds;
										data->last_mic=msg_copy.Micros;
										data->last_sel=0;
										break;
									}
								}

								// Fall through

							case GAD_FILETYPES_EDIT_ICON_MENU:

								// No current selection?
								if (!data->last_icon) break;

								// Edit it
								filetypeed_edit_iconmenu(data,data->last_icon);
								break;


							// Delete from icon menu
							case GAD_FILETYPES_DEL_ICON_MENU:

								// No current selection?
								if (!data->last_icon) break;

								// Delete function
								if (filetypeed_check_iconmenu(data,data->last_icon,TRUE))
									change_flag=1;
								break;
						}
						break;


					// BOOPSI message
					case IDCMP_IDCMPUPDATE:
						{
							short item;

							// Icon list?
							if (GetTagData(GA_ID,0,tags)!=GAD_FILETYPES_ICON_MENU) break;

							// Get item
							if ((item=GetTagData(DLV_DragNotify,-1,tags))!=-1)
							{
								// Handle selection
								filetypeed_sel_icon(data,item);

								// Start the drag
								config_drag_start(&data->drag,data->icon_list,item,tags,TRUE);
							}
						}
						break;


					// Ticks
					case IDCMP_INTUITICKS:
						++data->drag.tick_count;
						break;


					// Mouse move
					case IDCMP_MOUSEMOVE:

						// Handle drag move
						config_drag_move(&data->drag);
						break;


					// Mouse buttons
					case IDCMP_MOUSEBUTTONS:

						// Valid drag info?
						if (data->drag.drag)
						{
							short ok=-1;

							// Dropped ok?
							if (msg_copy.Code==SELECTUP)
							{
								// Remember last position
								data->drag.drag_x=data->window->WScreen->MouseX;
								data->drag.drag_y=data->window->WScreen->MouseY;
								ok=1;
							}

							// Aborted
							else
							if (msg_copy.Code==MENUDOWN) ok=0;

							// End drag?
							if (ok!=-1 && filetypeed_end_drag(data,ok)) change_flag=1;
						}
						break;


					// Key press
					case IDCMP_RAWKEY:

						// Help?
						if (msg_copy.Code==0x5f &&
							!(msg_copy.Qualifier&VALID_QUALIFIERS))
						{
							// Set busy pointer
							SetWindowBusy(data->window);

							// Send help command
							IPC_Command(data->func_startup.main_owner,IPC_HELP,(1<<31),"File Type Editor",0,REPLY_NO_PORT);

							// Clear busy pointer
							ClearWindowBusy(data->window);
						}
						break;
				}

				// Reply to outstanding messages
				if (imsg) ReplyWindowMsg(imsg);
			}

			// Check break flag
			if (break_flag || pending_quit)
			{
				// See if all the editors are gone
				if (IsListEmpty(&data->proc_list.list))
					break;

				// Send quit?
				if (break_flag)
				{
					IPC_ListQuit(&data->proc_list,0,success,FALSE);
					SetWindowBusy(data->window);
				}
				pending_quit=1;
			}
		}

		// AppMessage
		if (data->app_window)
		{
			struct AppMessage *msg;

			while ((msg=(struct AppMessage *)GetMsg(data->app_port)))
			{
				// Got an argument?
				if (msg->am_NumArgs>0)
				{
					char name[256];
					short len;
					APTR image;

					// Get full name
					NameFromLock(msg->am_ArgList[0].wa_Lock,name,256);
					if (msg->am_ArgList[0].wa_Name &&
						*msg->am_ArgList[0].wa_Name)
						AddPart(name,msg->am_ArgList[0].wa_Name,256);

					// Add .info
					if ((len=strlen(name))<6 ||
						stricmp(name+len-5,".info")!=0) strcat(name,".info");

					// Try to get image
#ifdef USE_DRAWICONSTATE
					{
						char *path_copy;
						image=NULL;
						if ((path_copy=AllocMemH(0,strlen(name)+1)))
						{
							// icon_path is guaranteed to have a .info at the end
							stccpy(path_copy,name,strlen(name)-4);
							image=GetCachedDiskObject(path_copy,0);
							FreeMemH(path_copy);
						}
					}
#else
					image=OpenImage(name,0);
#endif

					if (image)
					{
						// Store path
						FreeMemH(data->type->icon_path);
						if ((data->type->icon_path=AllocMemH(0,strlen(name)+1)))
							strcpy(data->type->icon_path,name);

						// Free existing image
#ifdef USE_DRAWICONSTATE
						FreeCachedDiskObject(data->icon_image);
#else
						CloseImage(data->icon_image);
#endif
						data->icon_image=image;

						// Show new image
						filetypeed_show_icon(data);
						change_flag=1;
					}
				}

				// Reply message
				ReplyMsg((struct Message *)msg);
			}
		}

		Wait(1<<ipc->command_port->mp_SigBit|
			1<<data->drag.timer->port->mp_SigBit|
			((data->window)?(1<<data->window->UserPort->mp_SigBit):0)|
			((data->app_window)?(1<<data->app_port->mp_SigBit):0));
	}

	// End any drag in progress
	filetypeed_end_drag(data,0);

	// Need to send button back?
	if (success==1 && change_flag)
	{
		if (IPC_Command(
			data->owner_ipc,
			FILETYPEEDIT_RETURN,
			(ULONG)data->type,
			data->node,
			0,
			REPLY_NO_PORT))
		{
			data->node=0;
		}
	}

	// Free edit filetype
	FreeFiletype(data->type);

	// Remove AppWindow
	RemoveAppWindow(data->app_window);

	// Close window
	CloseConfigWindow(data->window);

	// Close app port
	if (data->app_port)
	{
		struct Message *msg;
		while ((msg=GetMsg(data->app_port)))
			ReplyMsg(msg);
		DeleteMsgPort(data->app_port);
	}

	// Say goodbye
	IPC_Goodbye(ipc,data->owner_ipc,(success==-1)?0:(ULONG)data->node);

	// Free icon image
#ifdef USE_DRAWICONSTATE
	FreeCachedDiskObject(data->icon_image);
#else
	CloseImage(data->icon_image);
#endif

	// Close timer
	FreeTimer(data->drag.timer);

	// Free data
	IPC_Free(ipc);
	Att_RemList(data->action_list,0);
	Att_RemList(data->icon_list,REMLIST_FREEDATA);
	FreeVec(data);
}
Exemplo n.º 24
0
void
JPEGTests::testIncomplete() {
  auto_ptr<Image> image(OpenImage("images/jpeg/jack-incomplete.jpeg"));
  CPPUNIT_ASSERT(image.get() != 0);
}
Exemplo n.º 25
0
/* ----------------------------- MNI Header -----------------------------------
@NAME       : 
@INPUT      : 
@OUTPUT     : 
@RETURNS    : 
@DESCRIPTION: 
@METHOD     : 
@GLOBAL     : 
@CALLS      : 
@CREATED    : 
@MODIFIED   : 
---------------------------------------------------------------------------- */
int main (int argc, char *argv [])
{
   ImageInfoRec   ImInfo;
   long        Slice[MAX_WRITEABLE];
   long        Frame[MAX_WRITEABLE];
   long        NumSlices;
   long        NumFrames;
   FILE        *InFile;
   int         Result;
#ifdef DEBUG
   int         i;               /* loop to print out all slices and */
                                /* frames selected */
   ncopts = 0;
#endif

   ncopts = NC_VERBOSE;
   ErrMsg = (char *) malloc (256);

/* strcpy (ErrMsg, "Hello! I am an error message!"); */

   if (argc != NUM_ARGS + 1)        /* +1 because argv[0] counts! */
   {
      ErrAbort ("Incorrect number of arguments", TRUE, ERR_ARGS);
   }

#ifdef DEBUG
   printf ("Passing slice list %s to GetVector\n", SLICE_VECTOR);
   printf ("Passing frame list %s to GetVector\n", FRAME_VECTOR);
#endif

   /*
    * Parse the two lists of numbers first off
    */

   NumSlices = GetVector (SLICE_VECTOR, Slice, MAX_WRITEABLE);
   if (NumSlices < 0)
   {
      GVErrMsg (ErrMsg, "slices", NumSlices);
      ErrAbort (ErrMsg, TRUE, ERR_ARGS);
   }

   NumFrames = GetVector (FRAME_VECTOR, Frame, MAX_WRITEABLE);
   if (NumFrames < 0)
   {
      GVErrMsg (ErrMsg, "frames", NumFrames);
      ErrAbort (ErrMsg, TRUE, ERR_ARGS);
   }

#ifdef DEBUG
   printf ("Slices specified: ");
   for (i = 0; i < NumSlices; i++)
   {
      printf ("%8ld", Slice[i]);
   }
   printf ("\n");
   
   printf ("Frames specified: ");
   for (i = 0; i < NumFrames; i++)
   {
/*      printf ("i = %d, &(Frame) = %p, &(Frame[d]) = %p\n",
	      i, &Frame, &(Frame[i]));  */
      printf ("%8ld", Frame[i]); 
   }
   printf ("\n");
#endif

   if ((NumSlices > 1) && (NumFrames > 1))
   {
      ErrAbort ("Cannot specify both multiple frames and multiple slices", 
                TRUE, ERR_ARGS);
   }

   Result = OpenImage (MINC_FILE, &ImInfo, NC_WRITE, CreateNaN());
   if (Result != ERR_NONE)
   {
      ErrAbort (ErrMsg, TRUE, Result);
   }

   if (!CheckBounds (Slice, Frame, NumSlices, NumFrames, &ImInfo))
   {
      ErrAbort (ErrMsg, TRUE, ERR_ARGS);
   }

   if ((ImInfo.MaxID == MI_ERROR) || (ImInfo.MinID == MI_ERROR))
   {
      sprintf (ErrMsg, "Missing image-max or image-min variable in file %s", 
               MINC_FILE);
      ErrAbort (ErrMsg, TRUE, ERR_IN_MINC);
   }

   InFile = OpenTempFile (TEMP_FILE);
   if (InFile == NULL)
   {
      ErrAbort (ErrMsg, TRUE, ERR_IN_TEMP);
   }

   Result = WriteImages (InFile, &ImInfo, Slice, Frame, NumSlices, NumFrames);
   if (Result != ERR_NONE)
   {
      ErrAbort (ErrMsg, TRUE, Result);
   }

   fclose (InFile);

   miicv_free (ImInfo.ICV);
   ncclose (ImInfo.CDF);
   return (ERR_NONE);

}     /* main */
Exemplo n.º 26
0
int OpenImage (int nFlags, LONG lParam)
{
    FARPROC   lpfnOpenDlg;
    int       hInFile = 0;                   
    int       nError = EC_ERROR;             
    int       nFileType;                
    OFSTRUCT  Of;
    ATOM  Atom;
    WORD  wBytes;
    int         hTempFile;
    int         nErr = FALSE;

    /*  First get szOpenFileName filled in   */

    switch (nFlags)
    {
        case SCAN_OPEN:
            CleanFiles ();
            Atom = (ATOM) LOWORD (lParam);
            wBytes = GlobalGetAtomName (Atom, szOpenFileName, 128);
            GlobalDeleteAtom (Atom);
            GetNameFromPath ((LPSTR) szImageName, (LPSTR) szOpenFileName);
            bIsCurrTemp = FALSE;
            bImageModified = FALSE;
        break;

        case USER_OPEN:
    //      CleanFiles ();  BUG HERE????
            lpfnOpenDlg = MakeProcInstance ((FARPROC)OpenDlgProc, hInstIP);
            hInFile = DialogBox (hInstIP, "FILEDLG", hWndIP, lpfnOpenDlg);
            FreeProcInstance (lpfnOpenDlg);
            if (hInFile)
            {
                CleanFiles ();          // Put here instead of before call to dialog
                _lclose (hInFile);      // Kludge..

                /*  Always get image name from path.  Optionally also update the szOpenDir  */

                GetNameFromPath ((LPSTR) szImageName, (LPSTR) szOpenFileName);

                if (szOpenFileName [1] == ':')  // Look for A: or B:, if neither, remember open drive/directory
                {
                    if (! (szOpenFileName [0] == 'A' || szOpenFileName[0] == 'B' || szOpenFileName[0] == 'a' || szOpenFileName[0] == 'b'))
                    {
                        SeparateFile ((LPSTR) szOpenDir, (LPSTR) szImageName, (LPSTR)szOpenFileName);
                        _fstrcpy ((LPSTR) szSaveDir, (LPSTR) szOpenDir);
                    }
                }

                bIsCurrTemp = FALSE;


            }
            else
                nErr = USER_ABANDON;
            bImageModified = FALSE;
        break;

        case COMMAND_LINE_OPEN:
            CleanFiles ();
            _fstrcpy ((LPSTR)szOpenFileName, (LPSTR) lParam);
            GetNameFromPath ((LPSTR) szImageName, (LPSTR) szOpenFileName);
            bIsCurrTemp = FALSE;
            bImageModified = FALSE;
        break;

        case TOOLS_OPEN:
            _fstrcpy ((LPSTR)szOpenFileName, (LPSTR) lParam);
            bIsCurrTemp = TRUE;
        break;

        case OIC_OPEN:
        case AUTO_CONVERT_OPEN:
            _fstrcpy ((LPSTR)szOpenFileName, (LPSTR) lParam);
            bIsCurrTemp = TRUE;
            bImageModified = FALSE;
        break;

        case CLIPBOARD_OPEN:
            CleanFiles ();
            Atom = (ATOM) LOWORD (lParam);
            wBytes = GlobalGetAtomName (Atom, szOpenFileName, 128);
            GlobalDeleteAtom (Atom);
            _fstrcpy ((LPSTR) szImageName, (LPSTR) "Untitled");
            bIsCurrTemp = TRUE;
            bImageModified = FALSE;
        break;

        case GENERIC_OPEN:
        case UNDO_OPEN:
            _fstrcpy ((LPSTR)szOpenFileName, (LPSTR) lParam);
        break;

    }

    if (nErr != 0)
        return (nErr);

    hInFile = OpenFile ((LPSTR)szOpenFileName, (LPOFSTRUCT)&Of, OF_READWRITE);

    if (hInFile <= 0)
    {
        if (hInFile == 0)
        hInFile = IDCANCEL;
        nError = hInFile;
        return (nError);
    }

    /* Identify and Import File    */

    if (image_active)
    {
        _fstrcpy ((LPSTR) szTempPath,  (LPSTR) szOpenFileName);     // Store it somewhere

        SendMessage (hWndDisplay, WM_CLOSE, 0, 0);    // Close that baby down!

        if (nFlags == USER_OPEN)                      // So we don't re-display dialog
            nFlags = COMMAND_LINE_OPEN;
        else
            if (nFlags == CLIPBOARD_OPEN)
                nFlags = GENERIC_OPEN;                   

        _lclose (hInFile);

        PostMessage (hWndIP, WM_SHOWIMAGE, nFlags, (LONG) (LPSTR) szTempPath); // Re-prime the pump

        return (0);
    }

    _fstrcpy ((LPSTR) szCurrFileName, (LPSTR) szOpenFileName);  // For having UNDO cap.  5/91

    _llseek (hInFile, 0L, 0);

    nFileType = IdentFormat (hInFile, (LPSTR) szOpenFileName);
    if (nFileType < 0)
    {
        /* File type unknown    */

        _lclose (hInFile);
        hImportFile = 0; 
        return (nFileType);
    }

        switch (nFileType)
        {
            case IDFMT_CCPI:
            {
                char Buffer [128];

                GetTempFileName (0, (LPSTR) "OIC", 0, (LPSTR) Buffer);
                #ifndef DECIPHER
                /* If file type is compressed cpi, decompress first, then re-open     */
                hTempFile = DecompressCPI (hInFile ,(LPSTR) Buffer);
                if (hTempFile > 0)
                {
                    _lclose (hInFile);
                    return (OpenImage (OIC_OPEN, (LONG) (LPSTR) Buffer));
                }
                else
                    return (hTempFile);
    
            }
                #else
            return (EC_UFILETYPE);
                #endif
            break;
    
            case IDFMT_WMF:
            {
                char Buffer [128];
                WORD Retval;

                wUserImportType = (WORD) nFileType;
                GetTempFileName (0, (LPSTR) "WMF", 0, (LPSTR) Buffer);
                Retval = wmfImportMetaFile (hWndIP, hInFile, (LPSTR) Buffer);
                if (Retval == 0)
                {
                    _lclose (hInFile);
                    return (OpenImage (OIC_OPEN, (LONG) (LPSTR) Buffer));
                }
                else
                    return (USER_ABANDON);
    
            }
            break;

            case IDFMT_CPI:
            break;
    
            default:
    
            if (bDoDisplay)           // If we are going to actually display the thing, we may need to do some stuff first..
            if (bAutoConvert)
            {
                /*  Now if opened image is not CPI, save as CPI and re-open as CPI  */
    
                if (wImportType != IDFMT_CPI)
                    if (bAutoConvert)
                    {
                        wUserImportType = (WORD) nFileType;
                        hImportFile = hInFile;
                        SetState (IMPORT_TYPE, nFileType);  
                        nError = ImportFile();
                        if (nError != 0)
                            return (nError);
                        else
                            return (DoSave (SAVE_TO_CPI)); 
                    }
            }
            break;
        }

    hImportFile = hInFile;      
    SetState (IMPORT_TYPE, nFileType);  
    if (! wUserImportType)
        wUserImportType = wImportType;
    nError = ImportFile();

    if (nError >= 0)
        if (! bDoDisplay)
            PostMessage (hWndIP, WM_COMMAND, IDM_SAVE, 0L);

    return (nError);
}