void saveScreenshot() { static char path[256]; getNextScreenshotCnt(); if(screenshotCnt<MAX_SCREENSHOTS) { snprintf(path, 256, "%s/scr_%d_left.bmp", configuration.path, screenshotCnt); saveBitmap(path, gfxGetFramebuffer(GFX_TOP, GFX_LEFT, NULL, NULL), 400, 240); if(CONFIG_3D_SLIDERSTATE>0.0f) { snprintf(path, 256, "%s/scr_%d_right.bmp", configuration.path, screenshotCnt); saveBitmap(path, gfxGetFramebuffer(GFX_TOP, GFX_RIGHT, NULL, NULL), 400, 240); } } }
void OmniFEMMainFrame::createTopToolBar() { wxStandardPaths path = wxStandardPaths::Get(); wxImage::AddHandler(new wxPNGHandler); std::string resourcesDirectory = path.GetAppDocumentsDir().ToStdString() + std::string("/GitHub/Omni-FEM/src/UI/MainFrame/resources/");// equilivant to ~ in command line. This is for the path for the source code of the resources mainFrameToolBar->Create(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTB_TOP | wxNO_BORDER); /* This section will need to load the images into memory */ wxImage saveImage(resourcesDirectory + "save.png", wxBITMAP_TYPE_PNG); wxImage openImage(resourcesDirectory + "Open.png", wxBITMAP_TYPE_PNG); wxImage newFileImage(resourcesDirectory + "new_file.png", wxBITMAP_TYPE_PNG); /* This section will convert the images into bitmaps */ wxBitmap saveBitmap(saveImage); wxBitmap openImageBitmap(openImage); wxBitmap newFileBitmap(newFileImage); /* This section will add the tool to the toolbar */ mainFrameToolBar->AddTool(toolbarID::ID_ToolBarNew, newFileBitmap, "New File"); mainFrameToolBar->AddTool(toolbarID::ID_ToolBarOpen, openImageBitmap, "Open"); mainFrameToolBar->AddTool(toolbarID::ID_ToolBarSave, saveBitmap, "Save"); /* Enable the tooolbar and associate it with the main frame */ mainFrameToolBar->Realize(); this->SetToolBar(mainFrameToolBar); }
int main() { char filename[] = "E:\\快盘\\研究生学习\\图像相关科研\\任务\\任务10实现郑培嘉hadamard变换\\实验结果\\watermark\\lena64.bmp"; printf("%s\n",filename); BmpData bmpData; initBmpData(&bmpData); int ret = 0; ret = loadBitmap(filename, &bmpData); printf("%d\n",bmpData.bi._bm_compressed); printf("%d\n",bmpData.bi._bm_color_depth); if( ret != 0 ){ printf("load bitmap failed! error:%d\n", ret ); return -1; }else{ printf("load bitmap success!\n" ); } ret=saveBitmap("E:\\快盘\\研究生学习\\图像相关科研\\任务\\任务10实现郑培嘉hadamard变换\\实验结果\\watermark\\lena64OKOKOK.bmp",bmpData); if( ret != 0 ){ printf("save bitmap failed! error:%d\n", ret ); return -1; }else{ printf("save bitmap success!\n" ); } freeBmpData(&bmpData); return 0; }
void saveRevTrie(revtrie T, FILE *f) { unsigned long long aux; if (fwrite(&T->n,sizeof(uint),1,f) != 1) { fprintf(stderr,"Error: Cannot write RevTrie on file\n"); exit(1); } saveParentheses(f, T->pdata); // stores the bitstring indicating the empty nodes if (fwrite(T->B->data,sizeof(uint),(T->n+W-1)/W,f) != (T->n+W-1)/W) { fprintf(stderr,"Error: Cannot write RevTrie on file\n"); exit(1); } saveBitmap(f, T->B); // stores the array of elements of the rids permutation if (fwrite(&PARAMETER_T_RIDS,sizeof(uint),1,f) != 1) { fprintf(stderr,"Error: Cannot write RevTrie on file\n"); exit(1); } if (savePerm(T->rids,f) == -1) { fprintf (stderr,"Error: Cannot write RevTrie on file\n"); exit(1); } }
bool StreamerSDL::saveBitmap(const Bitmap & bitmap, std::ostream & output) { if(bitmap.getPixelFormat() == PixelFormat::MONO_FLOAT) { Reference<Bitmap> tmp = BitmapUtils::convertBitmap(bitmap, PixelFormat::MONO); return saveBitmap(*tmp.get(), output); } SDL_Surface * surface = BitmapUtils::createSDLSurfaceFromBitmap(bitmap); if (surface == nullptr) { return false; } // Save the bitmap to a file temporarily. static TemporaryDirectory tempDir("StreamerSDL"); FileName fileName(tempDir.getPath()); do { fileName.setFile(StringUtils::createRandomString(16) + ".bmp"); } while(FileUtils::isFile(fileName)); int success = SDL_SaveBMP(surface, fileName.getPath().c_str()); SDL_FreeSurface(surface); if(success != 0) { FileUtils::remove(fileName); return false; } std::ifstream fileInput(fileName.getPath().c_str(), std::ios_base::binary); output << fileInput.rdbuf(); fileInput.close(); FileUtils::remove(fileName); return true; }
int main(int argc, char** argv) { wkeWebView webView; const char* url; wchar_t filename[1024]; void* pixels; int w, h; printf(wkeVersionString()); wkeInit(); webView = wkeCreateWebView(); wkeResize(webView, 1024, 768); url = argc >= 2 ? argv[1] : "http://www.google.com"; printf("loading url %s ...\n", url); wkeLoadURL(webView, url); while (1) { wkeUpdate(); if (wkeIsLoadComplete(webView)) break; Sleep(10); } /*hidden scrollbar*/ wkeRunJS(webView, "document.body.style.overflow='hidden'"); w = wkeContentsWidth(webView); h = wkeContentsHeight(webView); wkeResize(webView, w, h); pixels = malloc(w*h*4); wkePaint(webView, pixels, 0); //save bitmap swprintf(filename, 1024, L"%s.bmp", wkeTitleW(webView)); convertFilename(filename); wprintf(L"%s\n", filename); saveBitmap(pixels, w, h, filename); free(pixels); wkeDestroyWebView(webView); wkeShutdown(); return 0; }
void saveRevTrie(revtrie T, FILE *f) { unsigned long long aux; if (fwrite(&T->n,sizeof(uint),1,f) != 1) { fprintf(stderr,"Error: Cannot write RevTrie on file\n"); exit(1); } /*aux = (2*(unsigned long long)T->n+W-1)/W; if (fwrite(T->data,sizeof(uint),aux,f) != aux) { fprintf(stderr,"Error: Cannot write RevTrie on file\n"); exit(1); }*/ saveParentheses(f, T->pdata); // stores the bitstring indicating the empty nodes if (fwrite(T->B->data,sizeof(uint),(T->n+W-1)/W,f) != (T->n+W-1)/W) { fprintf(stderr,"Error: Cannot write RevTrie on file\n"); exit(1); } saveBitmap(f, T->B); }
int saveIntIndex(void *index, char *pathname) { //void storeStructsCSA(ticsa *myicsa, char *basename) { ticsa *myicsa = (ticsa *) index; char *basename=pathname; char *filename; int file; // Reservamos espacio para o nome do ficheiro filename = (char *)malloc(sizeof(char)*MAX_FILENAME_LENGTH); // Ficheiro co n�mero de elementos indexados (enteiros do texto orixinal) strcpy(filename, basename); strcat(filename, "."); strcat(filename, NUMBER_OF_ELEMENTS_FILE_EXT); unlink(filename); if( (file = open(filename, O_WRONLY|O_CREAT,S_IRWXG | S_IRWXU)) < 0) { printf("Cannot open file %s\n", filename); exit(0); } write(file, &(myicsa->suffixArraySize), sizeof(int)); close(file); strcpy(filename, basename); strcat(filename, "."); strcat(filename, PSI_COMPRESSED_FILE_EXT); #ifdef PSI_HUFFMANRLE storeHuffmanCompressedPsi(&(myicsa->hcPsi), filename); #endif #ifdef PSI_GONZALO storeGonzaloCompressedPsi(&(myicsa->gcPsi), filename); #endif #ifdef PSI_DELTACODES storeDeltaCompressedPsi(&(myicsa->dcPsi), filename); #endif // Ficheiro co vector de bits D strcpy(filename, basename); strcat(filename, "."); strcat(filename, D_FILE_EXT); unlink(filename); if( (file = open(filename, O_WRONLY|O_CREAT,S_IRWXG | S_IRWXU)) < 0) { printf("Cannot open file %s\n", filename); exit(0); } write(file, myicsa->D, sizeof(int)*((myicsa->suffixArraySize+31)/32)); close(file); // Directorio de rank para D // Almacenamos o n�mero de superbloques seguido dos superbloques // E logo o n�mero de bloques seguido dos bloques strcpy(filename, basename); strcat(filename, "."); strcat(filename, D_RANK_DIRECTORY_FILE_EXT); saveBitmap(filename,myicsa->bD); // Ficheiro coas mostras de A strcpy(filename, basename); strcat(filename, "."); strcat(filename, SAMPLES_A_FILE_EXT); unlink(filename); if( (file = open(filename, O_WRONLY|O_CREAT,S_IRWXG | S_IRWXU)) < 0) { printf("Cannot open file %s\n", filename); exit(0); } write(file, myicsa->samplesA, sizeof(int) * (myicsa->samplesASize)); close(file); // Ficheiro co vector BA (marca as posicions de A muestreadas) strcpy(filename, basename); strcat(filename, "."); strcat(filename, BA_FILE_EXT); unlink(filename); if( (file = open(filename, O_WRONLY|O_CREAT,S_IRWXG | S_IRWXU)) < 0) { printf("Cannot open file %s\n", filename); exit(0); } write(file, myicsa->BA, sizeof(int)*((myicsa->suffixArraySize+31)/32)); close(file); // Directorio de rank para BA strcpy(filename, basename); strcat(filename, "."); strcat(filename, BA_RANK_DIRECTORY_FILE_EXT); saveBitmap(filename, myicsa->bBA); // Ficheiro coas mostras de A inversa strcpy(filename, basename); strcat(filename, "."); strcat(filename, SAMPLES_A_INV_FILE_EXT); unlink(filename); if( (file = open(filename, O_WRONLY|O_CREAT,S_IRWXG | S_IRWXU)) < 0) { printf("Cannot open file %s\n", filename); exit(0); } write(file, myicsa->samplesAInv, sizeof(int) * (myicsa->samplesAInvSize)); close(file); // Ficheiro co periodo de muestreo de A e A inversa strcpy(filename, basename); strcat(filename, "."); strcat(filename, SAMPLING_PERIOD_A_FILE_EXT); unlink(filename); if( (file = open(filename, O_WRONLY|O_CREAT,S_IRWXG | S_IRWXU)) < 0) { printf("Cannot open file %s\n", filename); exit(0); } write(file, &(myicsa->T_A), sizeof(int)); write(file, &(myicsa->T_AInv), sizeof(int)); write(file, &(myicsa->psiSearchFactorJump), sizeof(uint)); close(file); free(filename); return 0; //no error. }
void LabelImage::labelImage(const ImageGray8& rImageSrc, unsigned int valueToLabel, ImageUInt& rImageLabeled, std::list<LabelRect>& rListRectsLabel) { rListRectsLabel.clear(); int widthImage = rImageSrc.getWidth(); int heightImage = rImageSrc.getHeight(); rImageLabeled.setSize(widthImage, heightImage); rImageLabeled.fillPixel(PixelUInt(0)); Rect2i rectImage = rImageSrc.getRect(); #ifdef OUTPUT_LABEL_IMAGE // Debug 用 ImageRGB8 imageTemp(widthImage, heightImage); ImageAccessorReadOnly<ImageGray8, PixelRGB8> accessor(&rImageSrc); std::copy(accessor.range_begin(rectImage), accessor.range_end(rectImage), imageTemp.range_begin(rectImage)); #endif // OUTPUT_LABEL_IMAGE unsigned int indexLabel = 1; // 0 は何もなしの意味。ラベルインデックスは 1 からスタート ImageGray8::const_iterator itSrc = rImageSrc.range_begin(rectImage); for (; itSrc != rImageSrc.range_end(rectImage); ++ itSrc) { // 黒領域でないか、すでにラベル付けされているならスキップ if (!isPixelToBeLabeled((*itSrc).getA(), valueToLabel) || rImageLabeled.getPixel(itSrc.getPosition()).getA() > 0) continue; LabelRect rectLabel; std::set<FindLabelInfo> setFinders; // 現在地点から右方向への探索パケットを追加 FindLabelInfo info(itSrc.getPosition(), 1); setFinders.insert(info); while (setFinders.size() > 0) { std::set<FindLabelInfo>::iterator itTop = setFinders.begin(); FindLabelInfo infoFind = *itTop; setFinders.erase(itTop); // 左方向に行き止まりまで探索 int xCurrent = infoFind.getPosition().getX(); int yCurrent = infoFind.getPosition().getY(); int xBoundLeft = xCurrent; while (0 <= xBoundLeft) { int valueSrcCurrent = rImageSrc.getPixel(xBoundLeft, yCurrent).getA(); if (!isPixelToBeLabeled(valueSrcCurrent, valueToLabel)) break; rImageLabeled.setPixel(xBoundLeft, yCurrent, PixelUInt(indexLabel)); rectLabel.addPoint(Point2i(xBoundLeft, yCurrent)); #ifdef OUTPUT_LABEL_IMAGE imageTemp.setPixel(xBoundLeft, yCurrent, PixelRGB8(255, 0, 0)); // Debug #endif // OUTPUT_LABEL_IMAGE xBoundLeft --; } // 右方向に行き止まりまで探索 int xBoundRight = xCurrent + 1; while (xBoundRight < widthImage) { int valueSrcCurrent = rImageSrc.getPixel(xBoundRight, yCurrent).getA(); if (!isPixelToBeLabeled(valueSrcCurrent, valueToLabel)) break; rImageLabeled.setPixel(xBoundRight, yCurrent, PixelUInt(indexLabel)); rectLabel.addPoint(Point2i(xBoundRight, yCurrent)); #ifdef OUTPUT_LABEL_IMAGE imageTemp.setPixel(xBoundRight, yCurrent, PixelRGB8(255, 0, 0)); // Debug #endif // OUTPUT_LABEL_IMAGE xBoundRight ++; } int xStart = xBoundLeft + 1; int xEnd = xBoundRight; int yDir = infoFind.getDirectionSearchY(); findSearchArea(rImageSrc, valueToLabel, xStart, xEnd, yCurrent, yDir, rImageLabeled, setFinders); findSearchArea(rImageSrc, valueToLabel, xStart, xEnd, yCurrent, -yDir, rImageLabeled, setFinders); /* // 探索点をプロット std::set<FindLabelInfo>::const_iterator itFinder = setFinders.begin(); for (; itFinder != setFinders.end(); ++ itFinder) { imageTemp.setPixel((*itFinder).getPosition(), PixelRGB8(0, 255, 0)); } */ } if (rectLabel.getNumPoints() > 0) { rectLabel.updateCOG(); rListRectsLabel.push_back(rectLabel); } #ifdef OUTPUT_LABEL_IMAGE saveBitmap("C:¥¥Users¥¥logion¥¥development¥¥tetsutalow¥¥images¥¥tmp¥¥label.bmp", &imageTemp); #endif // OUTPUT_LABEL_IMAGE indexLabel ++; } }
bool StreamerPNG::saveBitmap(const Bitmap & bitmap, std::ostream & output) { volatile int colorType = 0; // volatile is needed because of the setjmp later on. volatile int transforms = 0; const PixelFormat & pixelFormat = bitmap.getPixelFormat(); if(pixelFormat == PixelFormat::RGBA) { colorType = PNG_COLOR_TYPE_RGB_ALPHA; transforms = PNG_TRANSFORM_IDENTITY; } else if(pixelFormat == PixelFormat::BGRA) { colorType = PNG_COLOR_TYPE_RGB_ALPHA; transforms = PNG_TRANSFORM_BGR; } else if(pixelFormat == PixelFormat::RGB) { colorType = PNG_COLOR_TYPE_RGB; transforms = PNG_TRANSFORM_IDENTITY; } else if(pixelFormat == PixelFormat::BGR) { colorType = PNG_COLOR_TYPE_RGB; transforms = PNG_TRANSFORM_BGR; } else if(pixelFormat == PixelFormat::MONO) { colorType = PNG_COLOR_TYPE_GRAY; transforms = PNG_TRANSFORM_IDENTITY; } else if(pixelFormat == PixelFormat::MONO_FLOAT) { Reference<Bitmap> tmp = BitmapUtils::convertBitmap(bitmap, PixelFormat::MONO); return saveBitmap(*tmp.get(), output); } else { WARN("Unable to save PNG file. Unsupported color type."); return false; } // Set up the necessary structures for libpng. png_structp png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, nullptr, nullptr, nullptr); if (!png_ptr) { return false; } png_infop info_ptr = png_create_info_struct(png_ptr); if (!info_ptr) { png_destroy_write_struct(&png_ptr, nullptr); return false; } if (setjmp(png_jmpbuf(png_ptr))) { png_destroy_write_struct(&png_ptr, &info_ptr); return false; } struct PNGFunctions { static void writeData(png_structp write_ptr, png_bytep data, png_size_t length) { std::ostream * out = reinterpret_cast<std::ostream *>(png_get_io_ptr(write_ptr)); out->write(reinterpret_cast<const char*>(data), static_cast<std::streamsize>(length)); } static void flushData(png_structp flush_ptr) { std::ostream * out = reinterpret_cast<std::ostream *>(png_get_io_ptr(flush_ptr)); out->flush(); } }; png_set_write_fn(png_ptr, reinterpret_cast<png_voidp>(&output), PNGFunctions::writeData, PNGFunctions::flushData); const uint32_t width = bitmap.getWidth(); const uint32_t height = bitmap.getHeight(); png_set_IHDR(png_ptr, info_ptr, width, height, 8, colorType, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT); // Write the image. std::vector<png_bytep> row_pointers; row_pointers.reserve(height); const uint8_t bytes = pixelFormat.getBytesPerPixel(); for (uint_fast32_t row = 0; row < height; ++row) { // Take over rows in the same order. row_pointers.push_back(reinterpret_cast<png_bytep>(const_cast<uint8_t *>(bitmap.data()) + row * width * bytes)); } png_set_rows(png_ptr, info_ptr, row_pointers.data()); png_write_png(png_ptr, info_ptr, transforms, nullptr); // Clean up. png_destroy_write_struct(&png_ptr, &info_ptr); return true; }