void CBitmap::Save(string filename) { if(filename.find(".jpg")!=string::npos) SaveJPG(filename); else SaveBMP(filename); }
void PathTracerDialog::PaintTexture(Uchar4 const * global__texturesData, Texture& texture) { static int numTexture = 1; std::wostringstream oss; oss << exportFolderPath; oss << "Texture "; if(numTexture / 100 == 0) { oss << "0"; if(numTexture / 10 == 0) oss << "0"; } oss << numTexture << ".bmp"; std::wstring sFilePath = oss.str(); LPCWSTR filePath = sFilePath.c_str(); RGBAColor* floatImage = (RGBAColor*) malloc(sizeof(RGBAColor)*texture.width*texture.height); for(uint i=0; i<texture.width*texture.height; i++) { floatImage[i] = global__texturesData[texture.offset+i].toFloat4()/255.0; floatImage[i].w /= 255.0; } long newBufferSize = 0; BYTE* buffer = ConvertRGBAToBMPBuffer(floatImage, NULL, texture.width, texture.height, &newBufferSize); SaveBMP(buffer, texture.width, texture.height, newBufferSize, filePath); delete[] buffer; free(floatImage); numTexture++; }
void Image::SaveImage(const char * filename) { int len = strlen(filename); if(strcmp(".bmp", filename+len-4)==0){ SaveBMP(filename); }else{ SaveTGA(filename); } }
//±£´æͼÏñ BOOL CYangLiuImageProcess::SaveImage(LPCTSTR lpszPathName) { IplImage *image = (IplImage*)voidImage; if (m_nOpenMode == 1 && m_pBits != NULL) { SaveBMP(lpszPathName); } if (m_nOpenMode == 2 && image != NULL) { cvSaveImage(lpszPathName, image); } return TRUE; }
//---------------------------------------------------------------------------- int main (int numArguments, char** arguments) { int width, height; unsigned char* data; LoadBMP(arguments[1], width, height, data); unsigned char* color = data; for (int i = 0; i < width*height; ++i, color += 3) { float b = (float)color[0]; float g = (float)color[1]; float r = (float)color[2]; unsigned char gray = (unsigned char)(0.30f*r + 0.59f*g + 0.11f*b); color[0] = gray; color[1] = gray; color[2] = gray; } SaveBMP(arguments[2], width, height, data); delete[] data; return 0; }
void VideoDlg::OnPaint() { CPaintDC dc(this); // device context for painting /* CRect rect; GetClientRect(&rect); CFont font; int nHeight = -((dc.GetDeviceCaps (LOGPIXELSY) * 20) / 72); font.CreateFont (nHeight, 0, 0, 0, FW_BOLD, TRUE, 0, 0, DEFAULT_CHARSET, OUT_CHARACTER_PRECIS, CLIP_CHARACTER_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, "Times New Roman"); //dc.SetBkMode (TRANSPARENT); dc.SetBkColor(RGB(255,0,255)); dc.SetTextColor (RGB (255, 255, 255)); CFont* pOldFont = dc.SelectObject (&font); dc.DrawText ("Hello, MFC", -1, &rect, DT_SINGLELINE | DT_CENTER | DT_VCENTER); dc.SelectObject (pOldFont);*/ Write2Log("Up to frame %d",m_oAVIReader.CurrentFrame()); LPBITMAPINFOHEADER pBMP = m_oAVIReader.GetCurrentFrame(); if(!pBMP) return; SaveBMP(pBMP,"test.bmp"); byte* pdata=(byte*)pBMP+pBMP->biSize+pBMP->biClrUsed*sizeof(RGBQUAD); // Convert Data To Requested Bitmap Format & Draw IT!!! DrawDibDraw(m_hdd, dc.GetSafeHdc(), 32, 32, pBMP->biWidth, pBMP->biHeight, pBMP, pdata, 0, 0, m_oAVIReader.Width(), m_oAVIReader.Height(), 0); }
int main(int argc, const char * argv[]) { std::string bmp_path = "/Users/maxmustermann/Downloads/shaunak.bmp"; int height = 0; int width = 0; unsigned long size = 0, padding = 0; //std::cout << "[i] path to bmp (without spaces): "; //std::cin >> bmp_path; //std::cout << std::endl; BYTE* bin_buffer = LoadBMP(&width, &height, &size, bmp_path); for(int i = 0; i < size; i++){ //std::cout << bin_buffer[i]; } std::cout << std::endl; //output std::reverse(bin_buffer, bin_buffer + size); std::unique_ptr<BYTE[]> newbuf2 = CreateNewBuffer(padding, bin_buffer, width, height); std::cout << "[i] old size was " << size << "." << std::endl; SaveBMP((BYTE*) &newbuf2[0], width, height, 24, padding, "/tmp/out.bmp"); return 0; }
void CGraphicsBuffer::Save(const std::string& aFilename, const CPalette* aPalette) const { ASSERT(aFilename.length()>0); const char* ext = aFilename.c_str() + aFilename.find_last_of('.'); if (strcasestr(ext,".efp2")) { SaveEFP2(aFilename,aPalette); return; } if (strcasestr(ext,".efp")) { SaveEFP(aFilename,aPalette); return; } if (strcasestr(ext,".sci")) { SaveSCI(aFilename,aPalette); return; } if (strcasestr(ext,".pcx")) { printf("CGraphicsBuffer::Save: pcx image found\n"); SavePCX(aFilename,aPalette); return; } if (strcasestr(ext,".bmp")) { SaveBMP(aFilename,aPalette); return; } error("CGraphicsBuffer::Save: File format not detected (%s)!",aFilename.c_str()); }
int main() { // Init parameter IMAGE_DATA * sdata = (IMAGE_DATA *)malloc(sizeof(IMAGE_DATA)); // Screen data IMAGE_DATA * cdata = (IMAGE_DATA *)malloc(sizeof(IMAGE_DATA)); // Cut data int height = 768; int width = 1376; int flag = 0; sdata->iData = (unsigned char *)malloc(height * width * 4); cdata->iData = (unsigned char *)malloc(height * 1366 * 3); clock_t start_time; clock_t end_time; printf("\n"); printf("============================================================================\n"); // get fb start_time = clock(); flag = GetFramebuffer(sdata); if (!flag) { printf("Get failed!\n"); return 0; } end_time=clock(); printf(" Get fb Running time is: %lf ms\n",static_cast<double>(end_time-start_time)/CLOCKS_PER_SEC*1000);//输出运行时间 // cut data start_time = clock(); flag = CutFbData(sdata, cdata); if (!flag) { printf("Cut failed!\n"); return 0; } end_time=clock(); printf(" Cut data Running time is: %lf ms\n",static_cast<double>(end_time-start_time)/CLOCKS_PER_SEC*1000);//输出运行时间 // Save data as jpeg start_time = clock(); flag = write_JPEG_file(cdata, "/data/eeds/save1.jpeg", 90); if (!flag) { printf("Save failed!\n"); return 0; } end_time=clock(); printf(" Save jpeg Running time is: %lf ms\n",static_cast<double>(end_time-start_time)/CLOCKS_PER_SEC*1000);//输出运行时间 // Read jpeg start_time = clock(); flag = read_JPEG_file(sdata, "/data/eeds/save1.jpeg"); if (!flag) { printf("Read failed!\n"); return 0; } end_time=clock(); printf(" Read jpeg Running time is: %lf ms\n",static_cast<double>(end_time-start_time)/CLOCKS_PER_SEC*1000);//输出运行时间 // Save data as bmp start_time = clock(); flag = SaveBMP(cdata, "/data/eeds/save2.bmp"); if (!flag) { printf("Save failed!\n"); return 0; } end_time=clock(); printf(" Save bmp Running time is: %lf ms\n",static_cast<double>(end_time-start_time)/CLOCKS_PER_SEC*1000);//输出运行时间 // Free memory free(sdata->iData); free(cdata->iData); free(sdata); free(cdata); printf("****************************************************************************\n"); printf("\n"); return 1; }
int main() { static CRaster bmp, bmp_temp; int width_tile, minus_sep, total_cut, nhor, nver, acum1=0, acum2=0, nver_aux, nhor_aux, i,j,i_aux,j_aux; //TEMPORAL int x_aux = 0; int intnsig_aux; cout << "********************************\n"; cout << "* CUTTER WITH FALCON SUPPORT *\n"; cout << "********************************" << endl << endl << "By Com_GP ([email protected]) 06/12/2002" << endl << "SUPPORTS 128x128 AND 256x256 TILES WITH 2 PIXELS OF SEPARATION" << endl << endl; RGBQUAD *rgbq_aux; //Points wherever the palette starts // char ** Raster_aux, ** Raster_main; //Points wherever the image bytes start char cc [256]; char string1 [16]; //Ask for the name of the bmp file printf ("Name of the file you want to open (EX: Htile24bpp.bmp)\n"); gets (cc); printf ("\n\n"); bmp.LoadBMP (cc); ofstream pr; pr.open("pr.txt"); if(!pr) cout << "ERROR GUARDANDO EN EL FICHERO" << endl; else { pr << "# Start Set X has X tiles, Terrain type 4" << endl << "SET 4" << endl; int menus = 0; while( (menus != 1) && (menus != 2)) { //The width of the tile cout << "Choose the width and height (its a square) of the tile" << endl; cout << " (1).- 128x128\n" << " (2).- 256x256\n" << endl; cout << "OPTION --> "; cin >> menus; cout << endl; switch( menus ) { case 1: width_tile = 128; break; case 2: width_tile = 256; break; default: cout << "ERROR, MUST BE BETWEEN 1 AND 2" << endl; system("PAUSE"); break; } } //Separation between tiles cout << "Separation between tiles = "; minus_sep = 2; cout << minus_sep << endl; //bmp_temp = bmp ASIGNACIONES DE TODOS LOS CAMPOS INCLUIDA LA PALETA bmp_temp.Width = width_tile; bmp_temp.Height = width_tile; bmp_temp.BPP = bmp.BPP; bmp_temp.Palette = bmp.Palette; bmp_temp.pbmi = bmp.pbmi; bmp_temp.pbmi->bmiHeader.biHeight = (width_tile); bmp_temp.pbmi->bmiHeader.biWidth = (width_tile); //new temp memory for the temp tile total_cut = width_tile + minus_sep; //HASTA AQUI BIEN 23/11/02 01:19 bmp_temp.Raster = new char*[total_cut]; for( i = 0; i <= total_cut; i++ ) bmp_temp.Raster[i] = new char[total_cut]; //HASTA AQUI BIEN 23/11/02 01:23 nver = (bmp.Width / total_cut); // nver = (bmp.Height /total_cut); cout << "Name of the FILE (ex: HnameX*.bmp, NO MORE THAN 5 CHARACTERS) to save\n"; gets(string1); // string1 += "Hname**"; // string1 = string1 + ".bmp"; int temp_i = 0; cout << "CORRECTOR FOR INCLINATION = " << temp_i << endl; nver_aux = 0; nhor_aux = 0; while( nver > 0) { nhor = ( bmp.Height / total_cut ); while( nhor > 0) { acum1 = 0; i_aux = 0; for ( i = (total_cut*(acum1+nhor_aux)); i < (((acum1+nhor_aux)*total_cut)+(width_tile)); i++ ) { acum2 = 0; j_aux = 0; for ( j = (total_cut*(acum2+nver_aux)); j < (((acum2+nver_aux)*total_cut)+(width_tile)); j++ ) { bmp_temp.Raster[i_aux][j_aux] = bmp.Raster[i][j];//Aqui hay algun problema // cout <<"[" << i_aux << "][" << j_aux <<"]," <<" [" << i << "][" << j <<"]" << endl; j_aux++; } // system("PAUSE"); acum2++; i_aux++; } acum1++; // nver_aux = 0; // cout <<"[" << nver << "][" << nhor <<"]" << endl; // cout <<"[" << nver_aux << "][" << nhor_aux <<"]" << endl << endl; nhor--; nhor_aux++; x_aux++; switch( nhor_aux - 1 ) { case 0: switch( nver_aux ) { //[0,x] case 0: string1[6] = '7'; cout << "TILE 7 ---> DONE" << endl; break; case 1: string1[6] = 'B'; cout << "TILE b ---> DONE" << endl; break; case 2: string1[6] = '8'; cout << "TILE 8 ---> DONE" << endl; break; case 3: string1[6] = 'C'; cout << "TILE c ---> DONE" << endl; break; case 4: string1[6] = '4'; cout << "TILE 4 ---> DONE" << endl; break; default: break; } break; //[1,x] case 1: switch( nver_aux ) { case 0: string1[6] = 'D'; cout << "TILE d ---> DONE" << endl; break; case 1: string1[6] = 'E'; cout << "TILE e ---> DONE" << endl; break; case 2: string1[6] = 'A'; cout << "TILE a ---> DONE" << endl; break; case 3: string1[6] = 'F'; cout << "TILE f ---> DONE" << endl; break; case 4: string1[6] = '5'; cout << "TILE 5 ---> DONE" << endl; break; default: break; } break; //[2,x] case 2: switch( nver_aux ) { case 0: string1[6] = 'x'; break; case 1: string1[6] = 'x'; break; case 2: string1[6] = '2'; cout << "TILE 2 ---> DONE" << endl; break; case 3: string1[6] = '3'; cout << "TILE 3 ---> DONE" << endl; break; case 4: string1[6] = '1'; cout << "TILE 1 ---> DONE" << endl; break; default: break; } break; default: break; } //Borrar cout << (string1[5]) << " " << char(nver_aux) << endl; // string1[7] = char(48 + nhor_aux - 1); // string1[8] = char(48 + nver_aux); //GUARDAR EN FICHERO if( string1[6] != 'x' ) { SaveBMP (string1, bmp_temp, temp_i ); string1[8]='p'; string1[9]='c'; string1[10]='x'; pr << string1 << " 0 0" << endl; string1[8]='b'; string1[9]='m'; string1[10]='p'; } // system("PAUSE"); } nhor_aux = 0; nver--; nver_aux++; } cout << "CUTTING DONE THE FILES SHOULD BE DONE" << endl; cout << "DONT FORGET TO ERASE THE HnameXx.bmp, ITS UNUSEFULL" << endl; system("PAUSE"); pr << "ENDSET" << endl << endl; } return 0; }
int main() { static CRaster bmp, bmp_temp; int width_tile, minus_sep, total_cut, nhor, nver, acum1=0, acum2=0, nver_aux, nhor_aux, i,j,i_aux,j_aux; //TEMPORAL int x_aux = 0; int intnsig_aux; cout << "********************************\n"; cout << "* CUTTER WITH FALCON SUPPORT *\n"; cout << "********************************" << endl << endl << "By Com_GP ([email protected]) 06/12/2002" << endl << "SUPPORTS 128x128 AND 256x256 TILES WITH 2 PIXELS OF SEPARATION" << endl << endl; system("PAUSE"); RGBQUAD *rgbq_aux; //Points wherever the palette starts // char ** Raster_aux, ** Raster_main; //Points wherever the image bytes start // char cc [256]; // char string1 [12]; string cc, string1; string s_aux; int nfiles; int menus = 0; ofstream pr; ifstream ifs; pr.open("texturebin.txt"); if(!pr) cout << "ERROR GUARDANDO EN EL FICHERO" << endl; else { ifs.open("list8bpp.txt"); if(!ifs) cout << "ERROR OPENING THE SCRIPT FILE" << endl; else{ getline( ifs, s_aux); nfiles = String2Int( s_aux ); cout << "NUMBER OF FILES = " << nfiles << endl; while( nfiles > 0 ) { getline( ifs, cc ); getline( ifs, string1 ); getline( ifs, s_aux ); menus = String2Int( s_aux ); //Ask for the name of the bmp file printf ("The file opened is ------> "); cout << cc; printf ("\n\n"); bmp.LoadBMP (cc.c_str()); pr << "# Start Set X has X tiles, Terrain type 4" << endl << "SET 4" << endl; //The width of the tile cout << "The width and height (its a square) of the tile is ---> "; switch( menus ) { case 1: cout << "128x128\n\n"; width_tile = 128; break; case 2: cout << "256x256\n\n"; width_tile = 256; break; case 3: cout << "512x512\n\n"; width_tile = 512; break; default: cout << "ERROR, MUST BE BETWEEN 1 AND 2, CHECK THE list8bpp.txt FILE" << endl; system("PAUSE"); break; } //Separation between tiles cout << "Separation between tiles = "; minus_sep = 2; cout << minus_sep << endl; //bmp_temp = bmp ASIGNACIONES DE TODOS LOS CAMPOS INCLUIDA LA PALETA bmp_temp.Width = width_tile; bmp_temp.Height = width_tile; bmp_temp.BPP = bmp.BPP; bmp_temp.Palette = bmp.Palette; bmp_temp.pbmi = bmp.pbmi; bmp_temp.pbmi->bmiHeader.biHeight = (width_tile); bmp_temp.pbmi->bmiHeader.biWidth = (width_tile); //new temp memory for the temp tile total_cut = width_tile + minus_sep; //HASTA AQUI BIEN 23/11/02 01:19 bmp_temp.Raster = new char*[total_cut]; for( i = 0; i <= total_cut; i++ ) bmp_temp.Raster[i] = new char[total_cut]; //HASTA AQUI BIEN 23/11/02 01:23 nver = (bmp.Width / total_cut); // nver = (bmp.Height /total_cut); cout << "Name of the FILE in which is gonna be saved"; cout << string1; cout << endl; int temp_i = 0; cout << "CORRECTOR FOR INCLINATION = " << temp_i << endl; nver_aux = 0; nhor_aux = 0; while( nver > 0) { nhor = ( bmp.Height / total_cut ); while( nhor > 0) { acum1 = 0; i_aux = 0; for ( i = (total_cut*(acum1+nhor_aux)); i < (((acum1+nhor_aux)*total_cut)+(width_tile)); i++ ) { acum2 = 0; j_aux = 0; for ( j = (total_cut*(acum2+nver_aux)); j < (((acum2+nver_aux)*total_cut)+(width_tile)); j++ ) { bmp_temp.Raster[i_aux][j_aux] = bmp.Raster[i][j];//Aqui hay algun problema j_aux++; } acum2++; i_aux++; } acum1++; nhor--; nhor_aux++; x_aux++; /***************** cout << "nver_aux = " << nver_aux << endl; cout << "nhor_aux -1 = " << nver_aux - 1 << endl; system("PAUSE"); *****************/ switch( nhor_aux - 1 ) { case 0: switch( nver_aux ) { //[0,x] case 0: string1[7] = '0'; cout << "TILE 0 ---> DONE" << endl; break; case 1: string1[7] = '1'; cout << "TILE 1 ---> DONE" << endl; break; case 2: string1[7] = '2'; cout << "TILE 2 ---> DONE" << endl; break; case 3: string1[7] = '3'; cout << "TILE 3 ---> DONE" << endl; break; default: break; } break; //[1,x] case 1: switch( nver_aux ) { case 0: string1[7] = '4'; cout << "TILE 4 ---> DONE" << endl; break; case 1: string1[7] = '5'; cout << "TILE 5 ---> DONE" << endl; break; case 2: string1[7] = '6'; cout << "TILE 6 ---> DONE" << endl; break; case 3: string1[7] = '7'; cout << "TILE 7 ---> DONE" << endl; break; default: break; } break; //[2,x] case 2: switch( nver_aux ) { case 0: string1[7] = '8'; cout << "TILE 8 ---> DONE" << endl; break; case 1: string1[7] = '9'; cout << "TILE 9 ---> DONE" << endl; break; case 2: string1[7] = 'A'; cout << "TILE A ---> DONE" << endl; break; case 3: string1[7] = 'B'; cout << "TILE B ---> DONE" << endl; break; default: break; } break; //[3,x] case 3: switch( nver_aux ) { case 0: string1[7] = 'C'; cout << "TILE C ---> DONE" << endl; break; case 1: string1[7] = 'D'; cout << "TILE D ---> DONE" << endl; break; case 2: string1[7] = 'E'; cout << "TILE E ---> DONE" << endl; break; case 3: string1[7] = 'F'; cout << "TILE F ---> DONE" << endl; break; default: break; } break; default: break; } cout << x_aux << endl; //GUARDAR EN FICHERO SaveBMP (string1.c_str(), bmp_temp, temp_i ); string1[9]='p'; string1[10]='c'; string1[11]='x'; switch( x_aux ) { case 1: string1[7] = '0'; break; case 2: string1[7] = '1'; break; case 3: string1[7] = '2'; break; case 4: string1[7] = '3'; break; case 5: string1[7] = '4'; break; case 6: string1[7] = '5'; break; case 7: string1[7] = '6'; break; case 8: string1[7] = '7'; break; case 9: string1[7] = '8'; break; case 10: string1[7] = '9'; break; case 11: string1[7] = 'A'; break; case 12: string1[7] = 'B'; break; case 13: string1[7] = 'C'; break; case 14: string1[7] = 'D'; break; case 15: string1[7] = 'E'; break; case 16: string1[7] = 'F'; break; default: break; } pr << string1 << " 0 0" << endl; string1[9]='b'; string1[10]='m'; string1[11]='p'; } nhor_aux = 0; nver--; nver_aux++; } cout << "Cutting of the set done, 13 files should be done" << endl; system("PAUSE"); pr << "ENDSET" << endl << endl; nfiles--; } //end while ifs.close(); } pr.close(); } cout << "A texturebin.txt should be done" << endl; return 0; }
int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR lpCmdLine, int) { // константы // максимальное число сфер - для выделения буффера памяти long MAX_NUM_SPHERES = 100000000; // реальное число - определяется при считывании из файла или используется в рандомной генерации. long REAL_NUM_SPHERES = 10000000; // количество миров сфер, когда мы убираем сферы лежащие в других сферах - нужно разделять все сферы по разным мирам - там добавления новых сфер происходит быстрее. int SPHERE_WORLD_NUMBER = 128; // количество сфер которое мы обрабатываем полностью, то есть убираем все сферы содержащиеся в других сферах. Так мы бъем все сферы на такие группы и обрабатываем полностью. // после этого мы просто склеиваем все такие группы. Это сделано для того что, обрабатывать все 100M долго по времени (>1h), из за этого нам придется отрисовывать на 30% // cфер больше. long SPHERES_PROCESSING_STEP = 10000000; // имена файлов std::string inputFileName = "input2.txt"; std::string outputTxtFileName = "balabok2.txt"; std::string outputBmpFileName = "balabok2.bmp"; std::string fullOutputTxtFileName = "tmp_balabok/spheres_fullOutput.txt"; CreateDirectory (L"tmp_balabok", NULL); LoggerCreate("tmp_balabok/spheres.log"); // установим зерно генератора случайных чисел srand((unsigned int)time(NULL)); /// create window, start main loop, etc. int windowWidht = 1024; int windowHeight = 1024; if (!GLWindowCreate(L"Spheres", windowWidht, windowHeight)) return 1; /// SphereKoords *allSpheres = new SphereKoords[MAX_NUM_SPHERES]; /// считывание сфер из файла REAL_NUM_SPHERES = readSpheresDataFromFile(inputFileName, allSpheres, MAX_NUM_SPHERES); //generateRandomSpheres(allSpheres, REAL_NUM_SPHERES); SphereWorld * sphereWorlds = new SphereWorld[SPHERE_WORLD_NUMBER]; SphereWorld finalWorld; LOG_DEBUG ("Please, be patient. There is a quite long data preprocessing before rendering.\n"); LOG_DEBUG ("It can take up to 20 minutes for 100M spheres.\n"); LOG_DEBUG ("Take into account, that time for preprocessing wasn't limited.\n"); LOG_DEBUG ("By the way, you can see the progress in this file\n"); auto beginTime = GetTickCount(); /// вычисление сфер внутри других сфер в несколько потоков по блокам (мирам) for (int spheresInitialNumber = 0; spheresInitialNumber < REAL_NUM_SPHERES; spheresInitialNumber += SPHERES_PROCESSING_STEP) { long spheresToProcess = spheresInitialNumber + SPHERES_PROCESSING_STEP >= REAL_NUM_SPHERES ? REAL_NUM_SPHERES - spheresInitialNumber : SPHERES_PROCESSING_STEP; LOG_DEBUG ("processing spheres from %i to %i, time: %i\n", spheresInitialNumber, spheresInitialNumber + spheresToProcess , GetTickCount() - beginTime); int worldsPerThread = SPHERE_WORLD_NUMBER/THREADS_COUNT; SphereWorldWorkerData workersData[THREADS_COUNT]; HANDLE hHandles[THREADS_COUNT]; for (int threadNumber = 0; threadNumber < THREADS_COUNT; ++threadNumber) { long spheresPerThread = spheresToProcess/THREADS_COUNT; workersData[threadNumber] = SphereWorldWorkerData(worldsPerThread, sphereWorlds + threadNumber * worldsPerThread, threadNumber == THREADS_COUNT - 1 ? spheresToProcess - spheresPerThread * (THREADS_COUNT - 1) : spheresPerThread, allSpheres + spheresInitialNumber + spheresPerThread * threadNumber); DWORD ThreadId; hHandles[threadNumber] = CreateThread(NULL, 0, SphereWorldWorker, workersData + threadNumber, 0, &ThreadId); } for (int i = 0; i < THREADS_COUNT; i++) { WaitForSingleObject(hHandles[i],INFINITE); } /// склейка миров из разных потоков for (int degree = (int)(log((double)worldsPerThread) / log(2.0)); degree < log((double)SPHERE_WORLD_NUMBER) / log(2.0); ++degree) { int step = (int) pow(2.0f, (int)degree); for (int worldNumber = 0; worldNumber < SPHERE_WORLD_NUMBER; worldNumber += step * 2) { sphereWorlds[worldNumber].AddSphereWorldInSeveralThreads(sphereWorlds[worldNumber + step], THREADS_COUNT); } } /// простое (без вычислений) добавление сфер из разных миров к финальному миру - сделано для увеличение скорости предобработки. finalWorld.SimpleAddSphereWorld(sphereWorlds[0]); clearWorlds(sphereWorlds, SPHERE_WORLD_NUMBER); } LOG_DEBUG("sphere amount after removing the spheres located insides others: %i, time %i\n", finalWorld.GetCurrentSize(), GetTickCount() - beginTime); LOG_DEBUG("started checking how spheres cover cube (0,0,0 - 1,1,1)\n"); /// проверка насколько сферы покрывают все стороны каждой ячейки finalWorld.GenerateCover(coverBuilder); LOG_DEBUG("covering finished, time %i\n", GetTickCount() - beginTime); LOG_DEBUG("creating the main window, etc, and started rendering\n"); /// generate matrix in cells; REDUCED_NUM_SPHERES = finalWorld.GetCurrentSize(); spheres = new mat4[REDUCED_NUM_SPHERES]; finalWorld.GenerateMatrixInCells(matrixInCells, spheres); /// вектор со временами отрисовки фремов std::vector<double> msecsPerFrameList; int nSize = windowWidht * windowHeight * 3; GLubyte *pixels = new GLubyte [nSize]; /// старт петли сообщений int result = GLWindowMainLoop(msecsPerFrameList, pixels); /// сохранение всех данных в файлы if (pixels) { SaveBMP(pixels, windowWidht, windowHeight, nSize, outputBmpFileName.c_str()); } double performance = 0; double medianeMsecsPerFrame = 0; std::ofstream fullResultStream(fullOutputTxtFileName); std::ofstream resultStream(outputTxtFileName); fullResultStream << "msecs per frame: "; for (auto msecsValue = msecsPerFrameList.begin(); msecsValue != msecsPerFrameList.end(); ++msecsValue) { medianeMsecsPerFrame += *msecsValue; fullResultStream << *msecsValue << " "; } medianeMsecsPerFrame /= 10.0f; fullResultStream << std::endl << "average msecs per frame: " << medianeMsecsPerFrame ; performance = REAL_NUM_SPHERES / (1000 * medianeMsecsPerFrame); fullResultStream << std::endl << "Mspheres per second: " << performance; resultStream << performance << std::endl; GLWindowDestroy(); LoggerDestroy(); /// TODO: kill all windows handlers and free all the memory. return result; }
int main() { static CRaster bmp, bmp_temp; int width_tile, minus_sep, total_cut, nhor, nver, acum1=0, acum2=0, nver_aux, nhor_aux, i,j,i_aux,j_aux; int nfiles_aux; int x_aux = 0; int intnsig_aux; string cc, string1, naming; cout << "********************************\n"; cout << "* CUTTER WITH FALCON SUPPORT *\n"; cout << "********************************" << endl << endl << "By Com_GP ([email protected]) DATE: " << "23/01/2003" << endl << "SUPPORTS 128x128, 256x256 AND 512x512 TILES WITH 2 PIXELS OF SEPARATION" << endl << endl; // system("PAUSE"); RGBQUAD *rgbq_aux; //Points wherever the palette starts string s_aux; int nfiles; int menus = 0; ofstream pr; ifstream ifs; pr.open("texturebin.txt"); if(!pr) cout << "ERROR SAVING TEXTURE.BIN, NO MEMORY??" << endl; else { ifs.open("list8bpp.txt"); if(!ifs) cout << "ERROR OPENING THE SCRIPT FILE" << endl; else{ getline( ifs, s_aux); nfiles = String2Int( s_aux ); cout << "NUMBER OF FILES = " << nfiles << endl; while( nfiles > 0 ) { getline( ifs, cc ); getline( ifs, string1 ); getline( ifs, s_aux ); menus = String2Int( s_aux ); //**ESTO** getline( ifs, s_aux); nfiles_aux = String2Int( s_aux ); //NAMING PROCEDURE getline( ifs, naming ); //Ask for the name of the bmp file printf ("The file opened is ------> "); cout << cc; printf ("\n\n"); if ( bmp.LoadBMP (cc.c_str())) return 0; pr << "# Start Set X has X tiles, Terrain type 4" << endl << "SET 4" << endl; //The width of the tile cout << "The width and height (its a square) of the tile is ---> "; switch( menus ) { case 1: cout << "128x128\n\n"; width_tile = 128; break; case 2: cout << "256x256\n\n"; width_tile = 256; break; case 3: cout << "512x512\n\n"; width_tile = 512; break; default: cout << "ERROR, MUST BE BETWEEN 1 AND 2, CHECK THE list8bpp.txt FILE" << endl; system("PAUSE"); break; } //Separation between tiles cout << "Separation between tiles = "; minus_sep = 2; cout << minus_sep << endl; //bmp_temp = bmp ASIGNACIONES DE TODOS LOS CAMPOS INCLUIDA LA PALETA bmp_temp.Width = width_tile; bmp_temp.Height = width_tile; bmp_temp.BPP = bmp.BPP; bmp_temp.Palette = bmp.Palette; bmp_temp.pbmi = bmp.pbmi; bmp_temp.pbmi->bmiHeader.biHeight = (width_tile); bmp_temp.pbmi->bmiHeader.biWidth = (width_tile); total_cut = width_tile + minus_sep; //new temp memory for the temp tile bmp_temp.Raster = new char*[total_cut]; for( i = 0; i <= total_cut; i++ ) bmp_temp.Raster[i] = new char[total_cut]; nver = (bmp.Width / total_cut); cout << "Name of the FILE in which is gonna be saved -> "; cout << string1; cout << endl; int temp_i = 0; cout << "CORRECTOR FOR INCLINATION = " << temp_i << endl; nver_aux = 0; nhor_aux = 0; while( nver > 0) { nhor = ( bmp.Height / total_cut ); while( nhor > 0) { acum1 = 0; i_aux = 0; for ( i = (total_cut*(acum1+nhor_aux)); i < (((acum1+nhor_aux)*total_cut)+(width_tile)); i++ ) { acum2 = 0; j_aux = 0; for ( j = (total_cut*(acum2+nver_aux)); j < (((acum2+nver_aux)*total_cut)+(width_tile)); j++ ) { bmp_temp.Raster[i_aux][j_aux] = bmp.Raster[i][j];//Aqui hay algun problema // cout <<"[" << i_aux << "][" << j_aux <<"]," <<" [" << i << "][" << j <<"]" << endl; j_aux++; } // system("PAUSE"); acum2++; i_aux++; } acum1++; nhor--; nhor_aux++; x_aux++; switch( nhor_aux - 1 ) { case 0: switch( nver_aux ) { case 0: string1[7] = naming[0]; cout << "TILE " << naming[0] << " ---> DONE" << endl; break; case 1: string1[7] = naming[2]; cout << "TILE " << naming[2] << " ---> DONE" << endl; break; case 2: string1[7] = naming[4]; cout << "TILE " << naming[4] << " ---> DONE" << endl; break; case 3: string1[7] = naming[6]; cout << "TILE " << naming[6] << " ---> DONE" << endl; break; case 4: string1[7] = naming[8]; cout << "TILE " << naming[8] << " ---> DONE" << endl; break; case 5: string1[7] = naming[10]; cout << "TILE " << naming[10] << " ---> DONE" << endl; break; case 6: string1[7] = naming[12]; cout << "TILE " << naming[12] << " ---> DONE" << endl; break; case 7: string1[7] = naming[14]; cout << "TILE " << naming[14] << " ---> DONE" << endl; break; case 8: string1[7] = naming[16]; cout << "TILE " << naming[16] << " ---> DONE" << endl; break; case 9: string1[7] = naming[18]; cout << "TILE " << naming[18] << " ---> DONE" << endl; break; case 10: string1[7] = naming[20]; cout << "TILE " << naming[20] << " ---> DONE" << endl; break; case 11: string1[7] = naming[22]; cout << "TILE " << naming[22] << " ---> DONE" << endl; break; case 12: string1[7] = naming[24]; cout << "TILE " << naming[24] << " ---> DONE" << endl; break; case 13: string1[7] = naming[26]; cout << "TILE " << naming[26] << " ---> DONE" << endl; break; case 14: string1[7] = naming[28]; cout << "TILE " << naming[28] << " ---> DONE" << endl; break; case 15: string1[7] = naming[30]; cout << "TILE " << naming[30] << " ---> DONE" << endl; break; default: break; } break; default: break; } if(nfiles_aux>0){ nfiles_aux--; //GUARDAR EN FICHERO if( string1[7] != 'x' ){ SaveBMP (string1.c_str(), bmp_temp, temp_i ); string1[9]='p'; string1[10]='c'; string1[11]='x'; pr << string1 << " 0 0" << endl; string1[9]='b'; string1[10]='m'; string1[11]='p'; } } } nhor_aux = 0; nver--; nver_aux++; } cout << "Cutting of the set done, " << x_aux << " files should be done" << endl; system("PAUSE"); pr << "ENDSET" << endl << endl; nfiles--; } //end while ifs.close(); } pr.close(); } cout << "A texturebin.txt should be done" << endl; return 0; }
int main() { static CRaster bmp, bmp_temp; int width_tile, minus_sep, total_cut, nhor, nver, acum1=0, acum2=0, nver_aux, nhor_aux, i,j,i_aux,j_aux; //TEMPORAL int x_aux = 0; int intnsig_aux; RGBQUAD *rgbq_aux; //Points wherever the palette starts // char ** Raster_aux, ** Raster_main; //Points wherever the image bytes start char cc [256]; char string1 [16]; //Ask for the name of the bmp file printf ("Name of the file you want to open (EX: 512x512.bmp)\n"); gets (cc); printf ("\n\n"); bmp.LoadBMP (cc); //The width of the tile cout << "The width and height (its a square) of the tile" << endl; cin >> width_tile; //Separation between tiles cout << "Separation between tiles" << endl; cin >> minus_sep; //bmp_temp = bmp ASIGNACIONES DE TODOS LOS CAMPOS INCLUIDA LA PALETA bmp_temp.Width = width_tile; bmp_temp.Height = width_tile; bmp_temp.BPP = bmp.BPP; bmp_temp.Palette = bmp.Palette; bmp_temp.pbmi = bmp.pbmi; bmp_temp.pbmi->bmiHeader.biHeight = (width_tile); bmp_temp.pbmi->bmiHeader.biWidth = (width_tile); //new temp memory for the temp tile total_cut = width_tile + minus_sep; //HASTA AQUI BIEN 23/11/02 01:19 bmp_temp.Raster = new char*[total_cut]; for( i = 0; i <= total_cut; i++ ) bmp_temp.Raster[i] = new char[total_cut]; //HASTA AQUI BIEN 23/11/02 01:23 nver = (bmp.Width / total_cut); // nver = (bmp.Height /total_cut); cout << "Name of the FILE (ex: HnameX*.bmp, NO MORE THAN 5 CHARACTERS) to save\n"; gets(string1); // string1 += "Hname**"; // string1 = string1 + ".bmp"; int temp_i; cout << "CORRECTOR FOR INCLINATION, USUALLY 0 --> "; cin >> temp_i; nver_aux = 0; nhor_aux = 0; while( nver > 0) { nhor = ( bmp.Height / total_cut ); while( nhor > 0) { acum1 = 0; i_aux = 0; for ( i = (total_cut*(acum1+nhor_aux)); i < (((acum1+nhor_aux)*total_cut)+(width_tile)); i++ ) { acum2 = 0; j_aux = 0; for ( j = (total_cut*(acum2+nver_aux)); j < (((acum2+nver_aux)*total_cut)+(width_tile)); j++ ) { bmp_temp.Raster[i_aux][j_aux] = bmp.Raster[i][j];//Aqui hay algun problema // cout <<"[" << i_aux << "][" << j_aux <<"]," <<" [" << i << "][" << j <<"]" << endl; j_aux++; } // system("PAUSE"); acum2++; i_aux++; } acum1++; // nver_aux = 0; cout <<"[" << nver << "][" << nhor <<"]" << endl; cout <<"[" << nver_aux << "][" << nhor_aux <<"]" << endl << endl; nhor--; nhor_aux++; x_aux++; switch( nhor_aux - 1 ) { case 0: switch( nver_aux ) { //[0,x] case 0: string1[6] = '7'; break; case 1: string1[6] = 'B'; break; case 2: string1[6] = '8'; break; case 3: string1[6] = 'C'; break; case 4: string1[6] = '4'; break; default: break; } break; //[1,x] case 1: switch( nver_aux ) { case 0: string1[6] = 'D'; break; case 1: string1[6] = 'E'; break; case 2: string1[6] = 'A'; break; case 3: string1[6] = 'F'; break; case 4: string1[6] = '5'; break; default: break; } break; //[2,x] case 2: switch( nver_aux ) { case 0: string1[6] = '0'; break; case 1: string1[6] = 'x'; break; case 2: string1[6] = 'x'; break; case 3: string1[6] = 'x'; break; case 4: string1[6] = 'x'; break; default: break; } break; default: break; } //Borrar cout << (string1[5]) << " " << char(nver_aux) << endl; // string1[7] = char(48 + nhor_aux - 1); // string1[8] = char(48 + nver_aux); //GUARDAR EN FICHERO SaveBMP (string1, bmp_temp, temp_i ); // system("PAUSE"); } nhor_aux = 0; nver--; nver_aux++; } cout << "CUTTING DONE THE " << x_aux << " FILES SHOULD BE DONE" << endl; system("PAUSE"); //end FIN // return 0; }
bool PathTracerDialog::PaintWindow(RGBAColor const * imageColor, float const * imageRay) { #ifdef MAYA if(true) { ///////////////////////////////////////////////////////////////////////////// /// Print in Maya: ///////////////////////////////////////////////////////////////////////////// MStatus stat = MS::kSuccess; // Check if the render view exists. It should always exist, unless // Maya is running in batch mode. // if (!MRenderView::doesRenderEditorExist()) { CONSOLE_LOG << "Cannot renderViewInteractiveRender in batch render mode." << ENDL; CONSOLE_LOG << "Run in interactive mode, so that the render editor exists." << ENDL; return false; }; bool doNotClearBackground = true; if (MRenderView::startRender( pathTracerWidth, pathTracerHeight, doNotClearBackground, true) != MS::kSuccess) { CONSOLE_LOG << "renderViewInteractiveRender: error occurred in startRender." << ENDL; return false; } RV_PIXEL* pixels = new RV_PIXEL[pathTracerWidth * pathTracerHeight]; // Fill buffer with uniform color for (unsigned int index = 0; index < pathTracerWidth * pathTracerHeight; ++index ) { float c = 255.0f / imageRay[index]; pixels[index].r = imageColor[index].x * c; pixels[index].g = imageColor[index].y * c; pixels[index].b = imageColor[index].z * c; pixels[index].a = imageColor[index].w * c; } // Pushing buffer to Render View if (MRenderView::updatePixels(0, pathTracerWidth-1, 0, pathTracerHeight-1, pixels) != MS::kSuccess) { CONSOLE_LOG << "renderViewInteractiveRender: error occurred in updatePixels." << ENDL; delete[] pixels; return false; } delete[] pixels; // Inform the Render View that we have completed rendering the entire image. // if (MRenderView::endRender() != MS::kSuccess) { CONSOLE_LOG << "renderViewInteractiveRender: error occurred in endRender."; return false; } } else { static float* imageRay2 = NULL; if(imageRay2 ==NULL) { imageRay2 = new float[pathTracerWidth * pathTracerHeight]; memset(imageRay2, 0, pathTracerWidth * pathTracerHeight * sizeof(float)); } ///////////////////////////////////////////////////////////////////////////// /// Print in Maya: ///////////////////////////////////////////////////////////////////////////// MStatus stat = MS::kSuccess; // Check if the render view exists. It should always exist, unless // Maya is running in batch mode. // if (!MRenderView::doesRenderEditorExist()) { CONSOLE_LOG << "Cannot renderViewInteractiveRender in batch render mode." << ENDL; CONSOLE_LOG << "Run in interactive mode, so that the render editor exists." << ENDL; return false; }; bool doNotClearBackground = true; if (MRenderView::startRender( pathTracerWidth, pathTracerHeight, doNotClearBackground, true) != MS::kSuccess) { CONSOLE_LOG << "renderViewInteractiveRender: error occurred in startRender." << ENDL; return false; } float nbRayMin = imageRay[0]; float nbRayMax = nbRayMin; for(int i=0; i<pathTracerWidth * pathTracerHeight; i++) { nbRayMax = max(nbRayMax, imageRay[i]); nbRayMin = min(nbRayMin, imageRay[i]); } RV_PIXEL* pixels = new RV_PIXEL[pathTracerWidth * pathTracerHeight]; // Fill buffer with uniform color for (unsigned int index = 0; index < pathTracerWidth * pathTracerHeight; ++index ) { //float c = 255.f*(imageRay[index]-nbRayMin) / (nbRayMax-nbRayMin); float c = 255.f*(imageRay[index] - imageRay2[index]); pixels[index].r = c; pixels[index].g = c; pixels[index].b = c; pixels[index].a = 1; } memcpy(imageRay2, imageRay, pathTracerWidth * pathTracerHeight * sizeof(float)); // Pushing buffer to Render View if (MRenderView::updatePixels(0, pathTracerWidth-1, 0, pathTracerHeight-1, pixels) != MS::kSuccess) { CONSOLE_LOG << "renderViewInteractiveRender: error occurred in updatePixels." << ENDL; delete[] pixels; return false; } delete[] pixels; // Inform the Render View that we have completed rendering the entire image. // if (MRenderView::endRender() != MS::kSuccess) { CONSOLE_LOG << "renderViewInteractiveRender: error occurred in endRender."; return false; } } #endif // END MAYA if(saveRenderedImages || imageIndex==500) { std::wostringstream oss; oss << exportFolderPath; if(imageIndex / 100 == 0) { oss << "0"; if(imageIndex / 10 == 0) oss << "0"; } oss << imageIndex << ".bmp"; std::wstring sFilePath = oss.str(); LPCWSTR filePath = sFilePath.c_str(); long newBufferSize = 0; BYTE* buffer = ConvertRGBAToBMPBuffer(imageColor, imageRay, pathTracerWidth, pathTracerHeight, &newBufferSize); if(!SaveBMP(buffer, pathTracerWidth, pathTracerHeight, newBufferSize, filePath)) { CONSOLE_LOG << "WARNING : unable to save rendered picture in the folder \"" << exportFolderPath << "\". Aborting saving." << ENDL; saveRenderedImages = false; } delete[] buffer; } imageIndex++; return true; }