예제 #1
0
void Frequencies::contextMenuRequest(QPoint pos)
{
  QMenu *menu = new QMenu(this);
  menu->setAttribute(Qt::WA_DeleteOnClose);
  menu->addAction("Save PNG", this, SLOT(savePNG()));
  menu->popup(m_customPlot->mapToGlobal(pos));
}
예제 #2
0
void GBOamView::save()
{
  CString captureBuffer;

  if(theApp.captureFormat == 0)
    captureBuffer = _T("oam.png");
  else
    captureBuffer = _T("oam.bmp");

  LPCTSTR exts[] = {_T(".png"), _T(".bmp") };

  CString filter = theApp.winLoadFilter(IDS_FILTER_PNG);
  CString title = winResLoadString(IDS_SELECT_CAPTURE_NAME);

  FileDlg dlg(this,
              captureBuffer,
              filter,
              theApp.captureFormat ? 2 : 1,
              theApp.captureFormat ? _T("BMP") : _T("PNG"),
              exts,
              _T(""),
              title,
              true);

  if(dlg.DoModal() == IDCANCEL) {
    return;
  }
  captureBuffer = dlg.GetPathName();

  if(dlg.getFilterIndex() == 2)
    saveBMP(captureBuffer);
  else
    savePNG(captureBuffer);
}
예제 #3
0
_XBool savePngRGBA2RGB(const char *fileName,
			const unsigned char * data,
			int w,int h,
			int compression)
{
	if(data == NULL) return XFalse;
	//将数据保存成图片
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
	SDL_Surface * picArm = SDL_CreateRGBSurface(SDL_SWSURFACE,w,h,24,0xff000000, 0x00ff0000, 0x0000ff00, 0x00000000);
#else
	SDL_Surface * picArm = SDL_CreateRGBSurface(SDL_SWSURFACE,w,h,24,0x000000ff, 0x0000ff00, 0x00ff0000, 0x00000000);
#endif
	//这里可以考虑保存成24位色提升效率
	unsigned char *pData1 = (unsigned char *)picArm->pixels;
	//int tempData1 = 0;
	int maxIndex = w * h;
	for(int i = 0,id = 0,is = 0;i < maxIndex;++ i,id += 3,is += 4)
	{
		*(pData1 + id + 0) = *(data + is + 0);
		*(pData1 + id + 1) = *(data + is + 1);
		*(pData1 + id + 2) = *(data + is + 2);
	}
	savePNG(fileName,picArm,compression);
	//释放资源
	SDL_FreeSurface(picArm);
	picArm = NULL;
	return XTrue;
}
예제 #4
0
void TileViewer::save()
{
    char captureBuffer[2048];

    if(captureFormat == 0)
        strcpy(captureBuffer, "tiles.png");
    else
        strcpy(captureBuffer, "tiles.bmp");

    char *exts[] = {".png", ".bmp" };

    FileDlg dlg(getHandle(),
                (char *)captureBuffer,
                (int)sizeof(captureBuffer),
                (char *)winLoadFilter(IDS_FILTER_PNG),
                captureFormat ? 2 : 1,
                captureFormat ? "BMP" : "PNG",
                exts,
                (char *)NULL,
                (char *)winResLoadString(IDS_SELECT_CAPTURE_NAME),
                TRUE);

    BOOL res = dlg.DoModal();
    if(res == FALSE) {
        DWORD res = CommDlgExtendedError();
        return;
    }

    if(captureFormat)
        saveBMP(captureBuffer);
    else
        savePNG(captureBuffer);
}
예제 #5
0
void GBMapView::OnSave()
{
  CString filename;

  if(theApp.captureFormat == 0)
    filename = "map.png";
  else
    filename = "map.bmp";

  LPCTSTR exts[] = {".png", ".bmp" };
  CString title = winResLoadString(IDS_SELECT_CAPTURE_NAME);
  CString filter = theApp.winLoadFilter(IDS_FILTER_PNG);

  FileDlg dlg(this,
              filename,
              filter,
              theApp.captureFormat ? 2 : 1,
              theApp.captureFormat ? "BMP" : "PNG",
              exts,
              "",
              title,
              true);

  if(dlg.DoModal() == IDCANCEL) {
    return;
  }

  if(dlg.getFilterIndex() == 2)
    saveBMP(dlg.GetPathName());
  else
    savePNG(dlg.GetPathName());
}
예제 #6
0
 bool writeResource(VirtualFile* file, ResourceDatabase* resource) const
 {
   bool ok = true;
   for(unsigned i=0; i<resource->count<Image>(); ++i)
     ok &= savePNG(resource->get<Image>(i), file, compression());
   return ok;
 }
예제 #7
0
 bool writeResource(const String& path, ResourceDatabase* resource) const
 {
   bool ok = true;
   for(unsigned i=0; i<resource->count<Image>(); ++i)
     ok &= savePNG(resource->get<Image>(i), path, compression());
   return ok;
 }
예제 #8
0
bool convertTGA (char * filename) {
	char * oldName = joinStrings (filename, "");
	filename[strlen (filename) - 3] = 's';
	filename[strlen (filename) - 2] = 'l';
	filename[strlen (filename) - 1] = getDither() ? '2' : 'x';
	int i, j;

	if (newerFile (oldName, filename)) {
		backdrop32 = false;
		setCompilerText (COMPILER_TXT_ITEM, "Compressing image");
		i = loadBackDropForCompiler (oldName);
		if (! i) return false;
		if (backdrop32) {
			j = savePNG (filename, HORZ_RES, VERT_RES, backDrop32Image);
			delete backDrop32Image;

			if (! j) return false;
		} else {
			j = saveHSI (filename);
			for (int a = 0; a < VERT_RES; a ++) delete backDropImage[a];
			delete backDropImage;

			if (! j) return false;
		}
		setCompilerText (COMPILER_TXT_ITEM, "");
	}
	delete oldName;
	return true;
}
예제 #9
0
void GBTileView::OnSave() 
{
  CString captureBuffer;

  if(theApp.captureFormat == 0)
    captureBuffer = "tiles.png";
  else
    captureBuffer = "tiles.bmp";

  LPCTSTR exts[] = {".png", ".bmp" };

  CString filter = theApp.winLoadFilter(IDS_FILTER_PNG);
  CString title = winResLoadString(IDS_SELECT_CAPTURE_NAME);

  FileDlg dlg(this,
              captureBuffer,
              filter,
              theApp.captureFormat ? 2 : 1,
              theApp.captureFormat ? "BMP" : "PNG",
              exts,
              "",
              title,
              true);

  if(dlg.DoModal() == IDCANCEL) {
    return;
  }

  captureBuffer = dlg.GetPathName();

  if(theApp.captureFormat)
    saveBMP(captureBuffer);
  else
    savePNG(captureBuffer);  
}
예제 #10
0
/**
 * Saves a snapshot of the graph to file.
 * initSnapshot() must be run first.
 */
void Graph::snapshot()
{
    std::stringstream ss;
    ss << picNum;
    string newName = picName + ss.str();
    savePNG(newName);
    ++picNum;
}
예제 #11
0
파일: pixmap.cpp 프로젝트: wzugang/3DUI
bool Pixmap::savePNG ( const char* filename, unsigned int compressionLevel ) const
{
    std::ofstream fp;
    fp.open ( filename, std::ios::out | std::ios::binary );
    if ( !fp.is_open() )
        return SetError ( "Unable to open the file for writing" );
    return savePNG ( fp );
}
예제 #12
0
파일: minutor.cpp 프로젝트: hidroto/minutor
void Minutor::save()
{
	QFileDialog fileDialog(this);
	fileDialog.setDefaultSuffix("png");
	QString filename = fileDialog.getSaveFileName(this,tr("Save world as PNG"),QString(),"*.png");
	
	savePNG( filename, false, false, false );
}
예제 #13
0
파일: FileManager.cpp 프로젝트: cxcfan/IPE
bool FileManager::saveImage(const QString &fileName, const byte fileType)
{
	QString eName = getExtensionName(fileName);
	if(eName.toLower() == "bmp")
	{
		return saveBMP(fileName, fileType);
	}
	else if(eName.toLower() == "png")
	{
		return savePNG(fileName);
	}
	return false;
}
예제 #14
0
파일: texture.cpp 프로젝트: KPWhiver/DimLib
void Texture<GLubyte>::save(string filename) const
{
    if(filename == "")
        filename = d_filename;

    // open file
    std::ofstream file(filename.c_str());

    if(not file.is_open())
        throw log(__FILE__, __LINE__, LogType::error, "Failed to open " + filename + " for reading");

    savePNG(filename, file, buffer());
}
예제 #15
0
void imageIO::saveImage(char* filename, unsigned char dataArray[], int size) {
	std::string strFilename = std::string(filename);
	std::vector <unsigned char> buffer;

	printf("%s", "Saving File as: ");
	printf("%s \n", filename);

	if (strFilename.substr(strFilename.length() - 4) == ".bmp") {
		saveBMP(filename, imageWidth, imageHeight, dataArray);
	}
	else if (strFilename.substr(strFilename.length() - 4) == ".png") {

		buffer.insert(buffer.begin(), dataArray, dataArray + size);
		savePNG(filename, buffer);
	}
}
예제 #16
0
파일: png.c 프로젝트: ncareol/ncplot
/* -------------------------------------------------------------------- */
void confirmPNG(Widget w, XtPointer client, XtPointer call)
{
  FileCancel((Widget)NULL, (XtPointer)NULL, (XtPointer)NULL);
  ExtractFileName(((XmFileSelectionBoxCallbackStruct *)call)->value, &outFile);

  if (strstr(outFile, ".png") == NULL)
    strcat(outFile, ".png");

  if (access(outFile, F_OK) == 0)
    {
    sprintf(buffer, "Overwrite file %s", outFile);
    WarnUser(buffer, savePNG, NULL);
    }
  else
    savePNG((Widget)NULL, (XtPointer)NULL, (XtPointer)NULL);

}
예제 #17
0
void CQDifferentialEquations::slotSave()
{
  QString outfilename;

  C_INT32 Answer = QMessageBox::No;

  while (Answer == QMessageBox::No)
    {
      outfilename =
        CopasiFileDialog::getSaveFileName(this,
                                          "Save File Dialog",
                                          "untitled.mml",
                                          "MathML (*.mml);;TeX (*.tex);;PNG (*.png)",
                                          "Save Formula to Disk", new QString);

      if (outfilename.isEmpty()) return;

      // Checks whether the file exists
      Answer = checkSelection(outfilename);

      if (Answer == QMessageBox::Cancel)
        return;
    }

#ifdef DEBUG_UI
  qDebug() << "outfilename = " << outfilename;
#endif

  QApplication::setOverrideCursor(Qt::WaitCursor);

  if (outfilename.contains(".tex"))
    {
      saveTeX(outfilename);
    }
  else if (outfilename.contains(".png"))
    {
      savePNG(outfilename);
    }
  else
    {
      saveMML(outfilename);
    }

  QApplication::restoreOverrideCursor();
}
예제 #18
0
_XBool savePngRGBA2RGBA(const char *fileName,
			const unsigned char * data,
			int w,int h,
			int compression)
{
	if(data == NULL) return XFalse;
	//将数据保存成图片
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
	SDL_Surface * picArm = SDL_CreateRGBSurface(SDL_SWSURFACE,w,h,32,0xff000000, 0x00ff0000, 0x0000ff00, 0x000000ff);
#else
	SDL_Surface * picArm = SDL_CreateRGBSurface(SDL_SWSURFACE,w,h,32,0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000);
#endif
	//这里可以考虑保存成32位色提升效率
	unsigned char *pData1 = (unsigned char *)picArm->pixels;
	memcpy(pData1,data,w * h * 4);
	savePNG(fileName,picArm,compression);
	//释放资源
	SDL_FreeSurface(picArm);
	picArm = NULL;
	return XTrue;
}
예제 #19
0
파일: minutor.cpp 프로젝트: Metibor/minutor
void Minutor::save() {
  // get filname to save to
  QFileDialog fileDialog(this);
  fileDialog.setDefaultSuffix("png");
  QString filename = fileDialog.getSaveFileName(this, tr("Save world as PNG"),
                                                QString(), "PNG Images (*.png)");

  // check if filename was given
  if (filename.isEmpty())
    return;

  // add .png suffix if not present
  QFile file(filename);
  QFileInfo fileinfo(file);
  if (fileinfo.suffix().isEmpty()) {
    filename.append(".png");
  }

  // save world to PNG image
  savePNG(filename, false, false, false);
}
void CQExpressionMmlStackedWidget::slotSaveExpression()
{
  QString *filter = new QString;
  QString outfilename;

  C_INT32 Answer = QMessageBox::No;

  while (Answer == QMessageBox::No)
    {
      outfilename =
        CopasiFileDialog::getSaveFileName(this,
                                          "Save File Dialog",
                                          "untitled.mml",
                                          "MathML (*.mml);;TeX (*.tex);;PNG (*.png)",
//                                          "Save Expression to Disk", new QString);
                                          "Save Expression to Disk", filter);

      if (outfilename.isEmpty()) return;

      // Checks whether the file exists
      Answer = checkSelection(outfilename);

      if (Answer == QMessageBox::Cancel)
        return;
    }

#ifdef DEBUG_UI
  qDebug() << "\non CQEMSW::slotSaveExpression -> filter = " << *filter << "\n";
#endif

  if (filter->contains(".tex"))
    saveTeX(outfilename);
  else if (filter->contains(".png"))
    savePNG(outfilename);
  else
    saveMML(outfilename);
}
예제 #21
0
/*
 * Save an image to one of the formats implemented by this class
 */
int RImage::save(char file[100]) {
	if (strstr(file, ".ppm") != NULL) {
		savePPM(file);

	} else if (strstr(file, ".pgm") != NULL){
		savePGM(file);

	} else if (strstr(file, ".jpeg") != NULL ||
			strstr(file, ".jpg") != NULL) {
		saveJPEG(file, 100);

	} else if (strstr(file, ".png") != NULL) {
		fprintf(stderr, "ERROR: Format not supported as yet.\n");
		savePNG(file);

	} else if (strstr(file, ".txt") != NULL) {
		saveText(file);

	} else {
		fprintf(stderr, "ERROR: Cannot save image %s. Unsupported format.\n", file);
		exit(1);
	}

}
예제 #22
0
// ウィンドウプロシージャ
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	HDC hdc;
	
	static BOOL onClip		= FALSE;
	static BOOL firstDraw	= TRUE;
	static RECT clipRect	= {0, 0, 0, 0};
	
	switch (message)
	{
	case WM_RBUTTONDOWN:
		// キャンセル
		DestroyWindow(hWnd);
		return DefWindowProc(hWnd, message, wParam, lParam);
		break;

	case WM_TIMER:
		// ESCキー押下の検知
		if (GetKeyState(VK_ESCAPE) & 0x8000){
			DestroyWindow(hWnd);
			return DefWindowProc(hWnd, message, wParam, lParam);
		}
		break;

	case WM_MOUSEMOVE:
		if (onClip) {
			// 新しい座標をセット
			clipRect.right  = LOWORD(lParam) + ofX;
			clipRect.bottom = HIWORD(lParam) + ofY;
			
			hdc = GetDC(NULL);
			drawRubberband(hdc, &clipRect, FALSE);

			ReleaseDC(NULL, hdc);
		}
		break;
	

	case WM_LBUTTONDOWN:
		{
			// クリップ開始
			onClip = TRUE;
			
			// 初期位置をセット
			clipRect.left = LOWORD(lParam) + ofX;
			clipRect.top  = HIWORD(lParam) + ofY;
			


			// マウスをキャプチャ
			SetCapture(hWnd);
		}
		break;

	case WM_LBUTTONUP:
		{
			// クリップ終了
			onClip = FALSE;
			
			// マウスのキャプチャを解除
			ReleaseCapture();
		
			// 新しい座標をセット
			clipRect.right  = LOWORD(lParam) + ofX;
			clipRect.bottom = HIWORD(lParam) + ofY;

			// 画面に直接描画,って形
			HDC hdc = GetDC(NULL);

			// 線を消す
			drawRubberband(hdc, &clipRect, TRUE);

			// 座標チェック
			if ( clipRect.right  < clipRect.left ) {
				int tmp = clipRect.left;
				clipRect.left   = clipRect.right;
				clipRect.right  = tmp;
			}
			if ( clipRect.bottom < clipRect.top  ) {
				int tmp = clipRect.top;
				clipRect.top    = clipRect.bottom;
				clipRect.bottom = tmp;
			}
			
			// 画像のキャプチャ
			int iWidth, iHeight;
			iWidth  = clipRect.right  - clipRect.left + 1;
			iHeight = clipRect.bottom - clipRect.top  + 1;

			if(iWidth == 0 || iHeight == 0) {
				// 画像になってない, なにもしない
				ReleaseDC(NULL, hdc);
				DestroyWindow(hWnd);
				break;
			}

			// ビットマップバッファを作成
			HBITMAP newBMP = CreateCompatibleBitmap(hdc, iWidth, iHeight);
			HDC	    newDC  = CreateCompatibleDC(hdc);
			
			// 関連づけ
			SelectObject(newDC, newBMP);

			// 画像を取得
			BitBlt(newDC, 0, 0, iWidth, iHeight, 
				hdc, clipRect.left, clipRect.top, SRCCOPY);
			
			// ウィンドウを隠す!
			ShowWindow(hWnd, SW_HIDE);
			/*
			// 画像をクリップボードにコピー
			if ( OpenClipboard(hWnd) ) {
				// 消去
				EmptyClipboard();
				// セット
				SetClipboardData(CF_BITMAP, newBMP);
				// 閉じる
				CloseClipboard();
			}
			*/
			
			// テンポラリファイル名を決定
			TCHAR tmpDir[MAX_PATH], tmpFile[MAX_PATH];
			GetTempPath(MAX_PATH, tmpDir);
			GetTempFileName(tmpDir, _T("gya"), 0, tmpFile);
			
			if (savePNG(tmpFile, newBMP)) {

				// うp
				if (!uploadFile(hWnd, tmpFile)) {
					// アップロードに失敗...
					// エラーメッセージは既に表示されている

					/*
					TCHAR sysDir[MAX_PATH];
					if (SUCCEEDED(StringCchCopy(sysDir, MAX_PATH, tmpFile)) &&
						SUCCEEDED(StringCchCat(sysDir, MAX_PATH, _T(".png")))) {
						
						MoveFile(tmpFile, sysDir);
						SHELLEXECUTEINFO lsw = {0};
						
						lsw.hwnd	= hWnd;
						lsw.cbSize	= sizeof(SHELLEXECUTEINFO);
						lsw.lpVerb	= _T("open");
						lsw.lpFile	= sysDir;

						ShellExecuteEx(&lsw);
					}
					*/
				}
			} else {
				// PNG保存失敗...
				MessageBox(hWnd, _T("Cannot save png image"), szTitle, 
					MB_OK | MB_ICONERROR);
			}

			// 後始末
			DeleteFile(tmpFile);
			
			DeleteDC(newDC);
			DeleteObject(newBMP);

			ReleaseDC(NULL, hdc);
			DestroyWindow(hWnd);
			PostMessage(hWnd,WM_CLOSE,0,0);
//			PostQuitMessage(0);
		}
		break;

	case WM_DESTROY:
		PostQuitMessage(0);
		break;

	default:
		return DefWindowProc(hWnd, message, wParam, lParam);
	}
	return 0;
}
예제 #23
0
// �E�B���h�E�v���V�[�W��
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	HDC hdc;
	
	static BOOL onClip		= FALSE;
	static BOOL firstDraw	= TRUE;
	static RECT clipRect	= {0, 0, 0, 0};
	
	switch (message)
	{
	case WM_RBUTTONDOWN:
		// �L�����Z��
		DestroyWindow(hWnd);
		return DefWindowProc(hWnd, message, wParam, lParam);
		break;

	case WM_TIMER:
		// ESC�L�[�����̌��m
		if (GetKeyState(VK_ESCAPE) & 0x8000){
			DestroyWindow(hWnd);
			return DefWindowProc(hWnd, message, wParam, lParam);
		}
		break;

	case WM_MOUSEMOVE:
		if (onClip) {
			// �V�������W���Z�b�g
			clipRect.right  = LOWORD(lParam) + ofX;
			clipRect.bottom = HIWORD(lParam) + ofY;
			
			hdc = GetDC(NULL);
			drawRubberband(hdc, &clipRect, FALSE);

			ReleaseDC(NULL, hdc);
		}
		break;
	

	case WM_LBUTTONDOWN:
		{
			// �N���b�v�J�n
			onClip = TRUE;
			
			// �����ʒu���Z�b�g
			clipRect.left = LOWORD(lParam) + ofX;
			clipRect.top  = HIWORD(lParam) + ofY;
			


			// �}�E�X���L���v�`��
			SetCapture(hWnd);
		}
		break;

	case WM_LBUTTONUP:
		{
			// �N���b�v�I��
			onClip = FALSE;
			
			// �}�E�X�̃L���v�`��������
			ReleaseCapture();
		
			// �V�������W���Z�b�g
			clipRect.right  = LOWORD(lParam) + ofX;
			clipRect.bottom = HIWORD(lParam) + ofY;

			// ��ʂɒ��ڕ`��C���Č`
			HDC hdc = GetDC(NULL);

			// ��������
			drawRubberband(hdc, &clipRect, TRUE);

			// ���W�`�F�b�N
			if ( clipRect.right  < clipRect.left ) {
				int tmp = clipRect.left;
				clipRect.left   = clipRect.right;
				clipRect.right  = tmp;
			}
			if ( clipRect.bottom < clipRect.top  ) {
				int tmp = clipRect.top;
				clipRect.top    = clipRect.bottom;
				clipRect.bottom = tmp;
			}
			
			// �摜�̃L���v�`��
			int iWidth, iHeight;
			iWidth  = clipRect.right  - clipRect.left + 1;
			iHeight = clipRect.bottom - clipRect.top  + 1;

			if(iWidth == 0 || iHeight == 0) {
				// �摜�ɂȂ��ĂȂ�, �Ȃɂ����Ȃ�
				ReleaseDC(NULL, hdc);
				DestroyWindow(hWnd);
				break;
			}

			// �r�b�g�}�b�v�o�b�t�@���쐬
			HBITMAP newBMP = CreateCompatibleBitmap(hdc, iWidth, iHeight);
			HDC	    newDC  = CreateCompatibleDC(hdc);
			
			// �֘A�Â�
			SelectObject(newDC, newBMP);

			// �摜���擾
			BitBlt(newDC, 0, 0, iWidth, iHeight, 
				hdc, clipRect.left, clipRect.top, SRCCOPY);
			
			// �E�B���h�E���B��!
			ShowWindow(hWnd, SW_HIDE);
			/*
			// �摜���N���b�v�{�[�h�ɃR�s�[
			if ( OpenClipboard(hWnd) ) {
				// ����
				EmptyClipboard();
				// �Z�b�g
				SetClipboardData(CF_BITMAP, newBMP);
				// �‚���
				CloseClipboard();
			}
			*/
			
			// �e���|�����t�@�C����������
			TCHAR tmpDir[MAX_PATH], tmpFile[MAX_PATH];
			GetTempPath(MAX_PATH, tmpDir);
			GetTempFileName(tmpDir, _T("gya"), 0, tmpFile);
			
			if (savePNG(tmpFile, newBMP)) {

				// ����
				if (!uploadFile(hWnd, tmpFile)) {
					// �A�b�v���[�h�Ɏ��s...
					// �G���[���b�Z�[�W�͊��ɕ\������Ă���

					/*
					TCHAR sysDir[MAX_PATH];
					if (SUCCEEDED(StringCchCopy(sysDir, MAX_PATH, tmpFile)) &&
						SUCCEEDED(StringCchCat(sysDir, MAX_PATH, _T(".png")))) {
						
						MoveFile(tmpFile, sysDir);
						SHELLEXECUTEINFO lsw = {0};
						
						lsw.hwnd	= hWnd;
						lsw.cbSize	= sizeof(SHELLEXECUTEINFO);
						lsw.lpVerb	= _T("open");
						lsw.lpFile	= sysDir;

						ShellExecuteEx(&lsw);
					}
					*/
				}
			} else {
				// PNG�ۑ����s...
				MessageBox(hWnd, _T("Cannot save png image"), szTitle, 
					MB_OK | MB_ICONERROR);
			}

			// ��n��
			DeleteFile(tmpFile);
			
			DeleteDC(newDC);
			DeleteObject(newBMP);

			ReleaseDC(NULL, hdc);
			DestroyWindow(hWnd);
			PostQuitMessage(0);
		}
		break;

	case WM_DESTROY:
		PostQuitMessage(0);
		break;

	default:
		return DefWindowProc(hWnd, message, wParam, lParam);
	}
	return 0;
}
예제 #24
0
/**
 * Renders the current scene to a file in the format given.
 *
 * @param filename The name of the target file. It must already contain the correct extension and must be encoded in UTF-8.
 * @param format The format of the file to render. Supported are PNG, PDF, PS (postscript) and EPS (encapsulated postscript).
 * @param title The titel for the document. Must be ANSI encoded for now.
 * @param software A string describing the producer of the document. Must be ANSI encoded for now.
 * @param content A set of flags indicating what additional info to render.
 * @param zoom The zoom at which render the file.
 * @param bounds Position and size of the area to store in the file (currently only for PNG).
 * @return True if successful otherwise false.
 */
bool CGenericCanvas::renderToFile(const char* filename, TGCFileFormat format, const char* title, const char* software,
                                  TGCRenderContent content, float zoom, TGCViewport& bounds)
{
  bool result = false;

  if (!updating())
  {
    beginUpdate();
    try
    {
      if ((FStates & GC_STATE_PENDING_ACTIVATION) != 0)
      {
        // A pending activation state always means there is a valid current view.
        FStates &= ~GC_STATE_PENDING_ACTIVATION;
        FCurrentView->activate();
      };

      switch (format)
      {
        case GC_FILE_FORMAT_PDF:
        case GC_FILE_FORMAT_PS:
        case GC_FILE_FORMAT_EPS:
          {
            if (FCurrentView != NULL)
            {
              const int fileTypeMapper[4] = {GL2PS_PDF, GL2PS_PS, GL2PS_EPS, GL2PS_TEX};

              FILE *file = openFile(filename, "wb");

              GLint bufferSize = 0;
              GLint state = GL2PS_OVERFLOW;
              
              char *oldlocale = setlocale(LC_NUMERIC, "C");
              while (state == GL2PS_OVERFLOW)
              {
                bufferSize += 1024 * 1024;
                gl2psBeginPage(title, software, NULL, fileTypeMapper[format], GL2PS_NO_SORT, GL2PS_DRAW_BACKGROUND | GL2PS_USE_CURRENT_VIEWPORT |
                  GL2PS_COMPRESS, GL_RGBA, 0, NULL, 0, 0, 0, bufferSize, file, filename);
                gl2psEnable(GL2PS_BLEND);
                gl2psBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

                clearBuffers();
                FCurrentView->render(content);

                state = gl2psEndPage();
              };
              setlocale(LC_NUMERIC, oldlocale);
              fclose(file);

              result = true;
            };
            break;
          };
        case GC_FILE_FORMAT_PNG:
          {
            if (FCurrentView != NULL)
            {
              TImage image;

              float workspaceWidth;
              float workspaceHeight;
              FCurrentView->getWorkspace(&workspaceWidth, &workspaceHeight);
              image.width = bounds.width;
              if (image.width < 0)
                image.width = (int) workspaceWidth;
              image.height = bounds.height;
              if (image.height < 0)
                image.height = (int) workspaceHeight;

              // If the frame buffer extension is not supported then there is no sense
              // to allocate a buffer larger than the current viewport,
              // because we cannot render more than this area in this case.
              if (!supportsExtension(GC_OE_FRAME_BUFFER_OBJECTS))
              {
                if (image.height > FCurrentView->viewportGet().height)
                  image.height = FCurrentView->viewportGet().height;
                if (image.width > FCurrentView->viewportGet().width)
                  image.width = FCurrentView->viewportGet().width;
              };

              image.colorType = COLOR_TYPE_RGB_ALPHA;
              image.data = (unsigned char*) malloc(image.width * image.height * 4);
              if (image.data != NULL)
              {
                FCurrentView->renderToMemory(GC_COLOR_FORMAT_RGBA, content, zoom, bounds, image.data);
                image.width = bounds.width;
                image.height = bounds.height;
                result = savePNG(utf8ToUtf16(filename), &image, true, title, software);
                free(image.data);
              };
            };
            break;
          };
      };
      endUpdate();
    }
    catch(...)
    {
      endUpdate();
      throw;
    };

    checkError();
  };

  return result;
}
예제 #25
0
int main(int argc, char *argv[])
{
	int x, y, i, OK, startIndex;
	char name[20];
	SDL_Rect src, dest;
	unsigned char r, g, b;
	int *pixels, xx, yy, pixel;
	int colour;

	i = 0;

	if (argc != 3)
	{
		printf("Usage: %s <PNG File> <Start_Index>\n", argv[0]);

		exit(0);
	}

	atexit(cleanup);

	if (SDL_Init(SDL_INIT_VIDEO|SDL_INIT_JOYSTICK|SDL_INIT_AUDIO) < 0)
	{
		printf("Could not initialize SDL: %s\n", SDL_GetError());

		exit(1);
	}

	screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0);

	image = loadImage(argv[1]);

	i = atoi(argv[2]);

	startIndex = i;

	temp = SDL_CreateRGBSurface(SDL_HWSURFACE, TILE_SIZE, TILE_SIZE, image->format->BitsPerPixel, image->format->Rmask, image->format->Gmask, image->format->Bmask, 0);

	newSurface = SDL_DisplayFormat(temp);

	colour = SDL_MapRGB(image->format, TRANS_R, TRANS_G, TRANS_B);

	for (y=0;y<image->h;y+=TILE_SIZE)
	{
		for (x=0;x<image->w;x+=TILE_SIZE)
		{
			SDL_FillRect(newSurface, NULL, colour);

			src.x = x;
			src.y = y;
			src.w = image->w - x >= TILE_SIZE ? TILE_SIZE : image->w - x;
			src.h = image->h - y >= TILE_SIZE ? TILE_SIZE : image->h - y;

			dest.x = 0;
			dest.y = 0;
			dest.w = src.w;
			dest.h = src.h;

			SDL_BlitSurface(image, &src, newSurface, &dest);

			sprintf(name, "%d.png", i);

			OK = 0;

			for (yy=0;yy<newSurface->h;yy++)
			{
				for (xx=0;xx<newSurface->w;xx++)
				{
					pixels = (int *)newSurface->pixels;

					pixel = pixels[(yy * newSurface->w) + xx];

					SDL_GetRGB(pixel, newSurface->format, &r, &g, &b);

					if (r != TRANS_R && g != TRANS_G && b != TRANS_B)
					{
						OK = 1;

						break;
					}
				}
			}

			if (OK == 1 && isDuplicate(newSurface, startIndex, i) == FALSE)
			{
				printf("Saving %s\n", name);

				savePNG(newSurface, name);

				i++;
			}

		}
	}

	exit(0);
}
예제 #26
0
파일: libxrw.c 프로젝트: maeager/s2volsurf
void Xvol2png(VOL_STRUCT *vol, char *ofname, int use_rows) {
   
  int nx, ny, nz;
  nx = vol->nx;
  ny = vol->ny;
  nz = vol->nz;
  
  bitmap_t bits;
  
  if (use_rows == 1) {
    bits.w = nx * nz;
    bits.h = ny;
    bits.pix = (pixel_t *)malloc(nx*ny*nz*sizeof(pixel_t));
    
    int i, j, k;
    float val;
    uint8_t grey;
    for (i = 0; i < nx; i++) {
      for (j = 0; j < ny; j++) {
	for (k = 0; k < nz; k++) {
	  val = vol->data[i][j][k];
	  grey = val * 255.0;
	  bits.pix[(nx*nz)*j + (k*nx+i)].r = grey;
	  bits.pix[(nx*nz)*j + (k*nx+i)].g = grey;
	  bits.pix[(nx*nz)*j + (k*nx+i)].b = grey;
	}
      }
    }
    
  } else {
    
    int Nzx, Nzy;
    if (use_rows > 1) {
      Nzy = use_rows;
      Nzx = nz/Nzy;
      if (nz % Nzy) {
	Nzx++;
      }
    } else {
      Nzx = (int)(floorf(sqrtf((float)nz)));
      if (Nzx * Nzx == nz) {
	Nzy = Nzx;
      } else {
	Nzx++;
	Nzy = (nz / Nzx) + 1;
      }
    }

    fprintf(stderr, "mosaic dimensions are: %d %d\n", Nzx, Nzy);

    bits.w = nx * Nzx;
    bits.h = ny * Nzy;
    bits.pix = (pixel_t *)malloc(nx * ny * Nzx * Nzy * sizeof(pixel_t));

    int i, j, k;
    int izx, izy;
    float val;
    uint8_t grey;
    for (i = 0; i < nx; i++) {
      for (j = 0; j < ny; j++) {
	for (k = 0; k < nz; k++) {
	  val = vol->data[i][j][k];
	  grey = val * 255.0;
	  izy = k / Nzx;
	  izx = k % Nzx;
	  bits.pix[(nx*Nzx)*(izy*ny+j) + (izx*nx+i)].r = grey;
	  bits.pix[(nx*Nzx)*(izy*ny+j) + (izx*nx+i)].g = grey;
	  bits.pix[(nx*Nzx)*(izy*ny+j) + (izx*nx+i)].b = grey;
	}
      }
    }
  }

  FILE *fout = fopen(ofname, "w");
  if (fout) {
    savePNG(fout, &bits);
    fclose(fout);
  } else {
    fprintf(stderr, "Failed to open '%s' for writing.\n", ofname);
    exit(-1);
  }
}
예제 #27
0
int main(int argc, char *argv[]) {

  #define FNAMELEN 400
  char ifname[FNAMELEN+1];
  int haveifname = 0;
  char ofname[FNAMELEN+1];
  int haveofname = 0;
  int use_rows = 0;

  int stride[3] = {1,1,1}; //{3,3,1};

  if (argc < 5) {
    usage(argv[0]);
    return -1;
  }

  int ic = 1;
  while (ic < argc) {
    if (!strcmp(argv[ic], "-f")) {
      strncpy(ifname, argv[++ic], FNAMELEN);
      haveifname = 1;
    } else if (!strcmp(argv[ic], "-o")) {
      strncpy(ofname, argv[++ic], FNAMELEN);
      haveofname = 1;
    } else if (!strcmp(argv[ic], "-s")) {
      stride[0] = atoi(argv[++ic]);
      stride[1] = atoi(argv[++ic]);
      stride[2] = atoi(argv[++ic]);
      if (stride[0] < 1 || stride[1] < 1 || stride[2] < 1) {
	fprintf(stderr, "stride must be at least 1 in each direction!\n");
	exit(-1);
      }
    } else if (!strcmp(argv[ic], "-R")) {
      use_rows = atoi(argv[++ic]);
    }
    ic++;
  }

  if (!haveifname || !haveofname) {
    usage(argv[0]);
    return -1;
  }
    
  XRAW_STRUCT *xr = loadXraw(ifname);

  if (!xr) {
    fprintf(stderr, "Failed to open or read '%s'.\n", argv[1]);
    return -1;
  }

  showXraw(xr);
  fprintf(stdout, "- - - - - - - - - - - - - - - - - - - - - - - - -\n");
  
  VOL_STRUCT *vol = Xraw2Xvol(xr, stride);
  if (!vol) {
    fprintf(stderr, "Failed to parse data volume.\n");
    return -1;
  }

  showXvol(vol);

  int nx, ny, nz;
  nx = vol->nx;
  ny = vol->ny;
  nz = vol->nz;

  bitmap_t bits;

  if (use_rows == 1) {
    bits.w = nx * nz;
    bits.h = ny;
    bits.pix = (pixel_t *)malloc(nx*ny*nz*sizeof(pixel_t));
    
    int i, j, k;
    float val;
    uint8_t grey;
    for (i = 0; i < nx; i++) {
      for (j = 0; j < ny; j++) {
	for (k = 0; k < nz; k++) {
	  val = vol->data[i][j][k];
	  grey = val * 255.0;
	  bits.pix[(nx*nz)*j + (k*nx+i)].r = grey;
	  bits.pix[(nx*nz)*j + (k*nx+i)].g = grey;
	  bits.pix[(nx*nz)*j + (k*nx+i)].b = grey;
	}
      }
    }

  } else {
   
    int Nzx, Nzy;
    if (use_rows > 1) {
      Nzy = use_rows;
      Nzx = nz/Nzy;
      if (nz % Nzy) {
	Nzx++;
      }
    } else {
      Nzx = (int)(floorf(sqrtf((float)nz)));
      if (Nzx * Nzx == nz) {
	Nzy = Nzx;
      } else {
	Nzx++;
	Nzy = (nz / Nzx) + 1;
      }
    }

    fprintf(stderr, "mosaic dimensions are: %d %d\n", Nzx, Nzy);

    bits.w = nx * Nzx;
    bits.h = ny * Nzy;
    bits.pix = (pixel_t *)malloc(nx * ny * Nzx * Nzy * sizeof(pixel_t));

    int i, j, k;
    int izx, izy;
    float val;
    uint8_t grey;
    for (i = 0; i < nx; i++) {
      for (j = 0; j < ny; j++) {
	for (k = 0; k < nz; k++) {
	  val = vol->data[i][j][k];
	  grey = val * 255.0;
	  izy = k / Nzx;
	  izx = k % Nzx;
	  bits.pix[(nx*Nzx)*(izy*ny+j) + (izx*nx+i)].r = grey;
	  bits.pix[(nx*Nzx)*(izy*ny+j) + (izx*nx+i)].g = grey;
	  bits.pix[(nx*Nzx)*(izy*ny+j) + (izx*nx+i)].b = grey;
	}
      }
    }
  }

  FILE *fout = fopen(ofname, "w");
  if (fout) {
    savePNG(fout, &bits);
    fclose(fout);
  } else {
    fprintf(stderr, "Failed to open '%s' for writing.\n", ofname);
    return -1;
  }

  return 0;
}