inline int ReadImage(const char * path, Image<RGBAColor> * im) { std::vector<unsigned char> ptr; int w, h, depth; int res = ReadImage(path, &ptr, &w, &h, &depth); if (depth !=4) return 0; if (res == 1) { RGBAColor * ptrCol = (RGBAColor*) &ptr[0]; //convert raw array to Image (*im) = Eigen::Map<Image<RGBAColor>::Base>(ptrCol, h, w); } return res; }
/* main function */ int main() { // empty buffers memset(inputimage, 0, HEIGHT*WIDTH*sizeof(unsigned char)); memset(outputimage, 0, HEIGHT*WIDTH*sizeof(unsigned char)); // read image(s) ReadImage("testpattern.raw", inputimage); InitFilter(); ProcessImage(inputimage, outputimage); WriteImage("smoothed.raw", outputimage); return 0; }
void CheckSceneAverage(const char *filename, float expected) { Point2i resolution; std::unique_ptr<RGBSpectrum[]> image = ReadImage(filename, &resolution); float delta = .02; float sum = 0; for (int i = 0; i < resolution.x * resolution.y; ++i) for (int c = 0; c < 3; ++c) sum += image[i][c]; int nPixels = resolution.x * resolution.y * 3; EXPECT_NEAR(expected, sum / nPixels, delta); }
void CControl::run_debug_forlist() { cout<<"processing...."<<endl; for(int i=0;i<nImgList.size();i++) { String n_filename=nImgList.at(i); //read img in nrawimg ReadImage(n_filename); //check if(!nImgRaw.data) continue; //get lines in all direction; nLineSegExtractor.SetParamters(nImgRaw); vector<Point2f> n_linevct=nLineSegExtractor.GetLineSegments(); //get lines in specific direction vector<Point2f> n_filterlinevct; float n_angle=90; FilterLineAngle(n_linevct,n_filterlinevct,n_angle,nControlOptions.nAngleThhold); //get ransac lines; vector<Point3f> n_linecoef; nRansacExtractor.GetRansacLines(n_linecoef,n_filterlinevct,nControlOptions.nInterval,nControlOptions.nRansacThreshold,nControlOptions.nRansacMininlier); if(nIfDebug) { // cout<<"angle: "<<n_angle<<' '<<"threshold: "<<nControlOptions.nAngleThhold<<endl; // cout<<"get filter line: "<<n_filterlinevct.size()<<endl; // cout<<"get ransac lines: "<<n_linecoef.size()<<endl; // Draw_debug; Mat n_img; nImgRaw.copyTo(n_img); Draw_debug(n_img,n_filterlinevct,"1"); Mat n_img2; nImgRaw.copyTo(n_img2); Draw_debug(n_img2,n_linevct,"2"); } //evaluate; Mat n_img3; nImgRaw.copyTo(n_img3); CEvaluate n_evaluate; n_evaluate.SetLines(n_linecoef,n_filterlinevct); n_evaluate.GetNearestLines(5); cout<<"length: "<<n_evaluate.GetLengthVal()<<endl; cout<<"density: "<<n_evaluate.GetDensityVal()<<endl; n_evaluate.Draw_debug(n_img3,"passdirection"); } cout<<"complete!!"<<endl; }
void TestImageModifierStack(void) { BeginTests(); CImage cImage; CImageModifierStack cStack; BOOL bResult; CImageRGBToGrey* pcGrey; CImageHeightToNormals* pcNormals; CImageResampler* pcSmall; CImage cBak; bResult = ReadImage(&cBak, "Input/Adelle.png"); AssertBool(TRUE, bResult); cImage.Copy(&cBak); cStack.Init(&cImage); pcGrey = cStack.AddModifier<CImageRGBToGrey>(); pcGrey->Init(RGBTGS_UseRed); cStack.ApplyAll(); WriteImage(&cImage, "Output/AdelleGrey.raw"); AssertFileMemory("Input/AdelleGrey.raw", cImage.GetData(), cImage.GetByteSize()); cImage.Kill(); pcNormals = cStack.AddModifier<CImageHeightToNormals>(); pcNormals->Init(IMAGE_DIFFUSE_GREY); cImage.Copy(&cBak); cStack.ApplyAll(); WriteImage(&cImage, "Output/AdelleNormal.raw"); AssertFileMemory("Input/AdelleNormal.raw", cImage.GetData(), cImage.GetByteSize()); cImage.Kill(); pcSmall = cStack.AddModifier<CImageResampler>(); pcSmall->Init(IR_NearestNeighbour, 21, 16); cImage.Copy(&cBak); cStack.ApplyAll(); WriteImage(&cImage, "Output/AdelleSmall.raw"); AssertFileMemory("Input/AdelleSmall.raw", cImage.GetData(), cImage.GetByteSize()); AssertInt(3, cStack.NumModifiers()); cStack.Kill(); cImage.Kill(); cBak.Kill(); TestStatistics(); }
GonioPhotometricLight::GonioPhotometricLight(const Transform &light2world, const Spectrum &intensity, const string &texname) : Light(light2world) { lightPos = LightToWorld(Point(0,0,0)); Intensity = intensity; // Create _mipmap_ for _GonioPhotometricLight_ int width, height; RGBSpectrum *texels = ReadImage(texname, &width, &height); if (texels) { mipmap = new MIPMap<RGBSpectrum>(width, height, texels); delete[] texels; } else mipmap = NULL; }
bool UnformatImage (const std::string &path, Range range) { auto disk = std::make_shared<Disk>(); if (!ReadImage(path, disk)) return false; ValidateRange(range, MAX_TRACKS, MAX_SIDES, disk->cyls(), disk->heads()); range.each([&] (const CylHead &cylhead) { if (!g_fAbort) disk->write_track(cylhead, Track()); }); return WriteImage(path, disk); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % R e a d M P E G I m a g e % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % ReadMPEGImage() reads an binary file in the MPEG video stream format % and returns it. It allocates the memory necessary for the new Image % structure and returns a pointer to the new image. % % The format of the ReadMPEGImage method is: % % Image *ReadMPEGImage(const ImageInfo *image_info, % ExceptionInfo *exception) % % A description of each parameter follows: % % o image_info: the image info. % % o exception: return any errors or warnings in this structure. % */ static Image *ReadMPEGImage(const ImageInfo *image_info, ExceptionInfo *exception) { #define ReadMPEGIntermediateFormat "pam" Image *image, *images; ImageInfo *read_info; MagickBooleanType status; /* Open image file. */ assert(image_info != (const ImageInfo *) NULL); assert(image_info->signature == MagickSignature); if (image_info->debug != MagickFalse) (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", image_info->filename); assert(exception != (ExceptionInfo *) NULL); assert(exception->signature == MagickSignature); image=AcquireImage(image_info); status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception); if (status == MagickFalse) { image=DestroyImageList(image); return((Image *) NULL); } (void) CloseBlob(image); (void) DestroyImageList(image); /* Convert MPEG to PAM with delegate. */ read_info=CloneImageInfo(image_info); image=AcquireImage(image_info); (void) InvokeDelegate(read_info,image,"mpeg:decode",(char *) NULL,exception); image=DestroyImage(image); (void) FormatMagickString(read_info->filename,MaxTextExtent,"%s.%s", read_info->unique,ReadMPEGIntermediateFormat); images=ReadImage(read_info,exception); (void) RelinquishUniqueFileResource(read_info->filename); read_info=DestroyImageInfo(read_info); return(images); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % R e a d T I L E I m a g e % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % ReadTILEImage tiles a texture on an image. It allocates the % memory necessary for the new Image structure and returns a pointer to the % new image. % % The format of the ReadTILEImage method is: % % Image *ReadTILEImage(const ImageInfo *image_info, % ExceptionInfo *exception) % % A description of each parameter follows: % % o image_info: the image info. % % o exception: return any errors or warnings in this structure. % */ static Image *ReadTILEImage(const ImageInfo *image_info, ExceptionInfo *exception) { Image *image, *tile_image; ImageInfo *read_info; /* Initialize Image structure. */ assert(image_info != (const ImageInfo *) NULL); assert(image_info->signature == MagickSignature); if (image_info->debug != MagickFalse) (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", image_info->filename); assert(exception != (ExceptionInfo *) NULL); assert(exception->signature == MagickSignature); read_info=CloneImageInfo(image_info); SetImageInfoBlob(read_info,(void *) NULL,0); *read_info->magick='\0'; tile_image=ReadImage(read_info,exception); read_info=DestroyImageInfo(read_info); if (tile_image == (Image *) NULL) return((Image *) NULL); image=AcquireImage(image_info,exception); if ((image->columns == 0) || (image->rows == 0)) ThrowReaderException(OptionError,"MustSpecifyImageSize"); if (*image_info->filename == '\0') ThrowReaderException(OptionError,"MustSpecifyAnImageName"); image->colorspace=tile_image->colorspace; image->alpha_trait=tile_image->alpha_trait; if (image->alpha_trait == BlendPixelTrait) (void) SetImageBackgroundColor(image,exception); (void) CopyMagickString(image->filename,image_info->filename,MaxTextExtent); if (LocaleCompare(tile_image->magick,"PATTERN") == 0) { tile_image->tile_offset.x=0; tile_image->tile_offset.y=0; } (void) TextureImage(image,tile_image,exception); tile_image=DestroyImage(tile_image); if (image->colorspace == GRAYColorspace) image->type=GrayscaleType; return(GetFirstImageInList(image)); }
GLuint Mesh::LoadTexture(char* Filename) { GLint iWidth, iHeight, iComponents; GLubyte* m_pImage = ReadImage(Filename, GL_FALSE, &iWidth, &iHeight, &iComponents); GLuint m_textureObj; if(!m_pImage)return false; glGenTextures(1, &m_textureObj); glBindTexture(GL_TEXTURE_2D, m_textureObj); //glTexImage2D(m_textureTarget, 0, GL_RGB, m_pImage->columns(), m_pImage->rows(), 0, GL_RGBA, GL_UNSIGNED_BYTE, m_blob.data()); glTexImage2D(GL_TEXTURE_2D, 0, iComponents, iWidth, iHeight, 0, iComponents, GL_UNSIGNED_BYTE, m_pImage); //gluBuild2DMipmaps(m_textureTarget, iComponents, iWidth, iHeight, iComponents, GL_UNSIGNED_BYTE, m_pImage); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); return m_textureObj; }
static bool ReadImage( FileFormatInstance* instance, I& image ) { if ( !image.IsShared() ) { I tmp( (void*)0, 0, 0 ); if ( !ReadImage( instance, tmp ) ) return false; image.Assign( tmp ); return true; } if ( (*API->FileFormat->ReadImage)( instance->handle, image.Allocator().Handle() ) == api_false ) return false; image.Synchronize(); return true; }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % R e a d T I L E I m a g e % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % Method ReadTILEImage tiles a texture on an image. It allocates the % memory necessary for the new Image structure and returns a pointer to the % new image. % % The format of the ReadTILEImage method is: % % Image *ReadTILEImage(const ImageInfo *image_info,ExceptionInfo *exception) % % A description of each parameter follows: % % o image: Method ReadTILEImage returns a pointer to the image after % reading. A null image is returned if there is a memory shortage or % if the image cannot be read. % % o image_info: Specifies a pointer to a ImageInfo structure. % % o exception: return any errors or warnings in this structure. % % */ static Image *ReadTILEImage(const ImageInfo *image_info, ExceptionInfo *exception) { Image *image, *tile_image; ImageInfo *clone_info; RectangleInfo geometry; /* Initialize Image structure. */ assert(image_info != (const ImageInfo *) NULL); assert(image_info->signature == MagickSignature); assert(exception != (ExceptionInfo *) NULL); assert(exception->signature == MagickSignature); clone_info=CloneImageInfo(image_info); clone_info->blob=(void *) NULL; clone_info->length=0; *clone_info->magick='\0'; tile_image=ReadImage(clone_info,exception); DestroyImageInfo(clone_info); if (tile_image == (Image *) NULL) return((Image *) NULL); /* Adapt tile image to desired image type. */ if (image_info->type != UndefinedType) (void) SetImageType(tile_image,image_info->type); /* Create tiled canvas image. */ (void) GetGeometry(image_info->size,&geometry.x,&geometry.y,&geometry.width, &geometry.height); image=ConstituteTextureImage(geometry.width,geometry.height,tile_image,exception); DestroyImage(tile_image); return(image); }
//-------------------------------------------------------------- Image::Ptr ReadImage(const std::string& filename, FileFormat::Enum ff, PixelFormat::Enum pf) { File::Ptr file = OpenFile(filename); if (!file) { return 0; } if (ff == FileFormat::AutoDetect) { ff = GetFileFormat(filename); if (ff == FileFormat::Unknown) { ff = FileFormat::AutoDetect; } } return ReadImage(file, ff, pf); }
static bool ReadEXR(const char *name, float **rgba, int *width, int *height) { Point2i res; std::unique_ptr<RGBSpectrum[]> image = ReadImage(name, &res); if (!image) return false; *width = res.x; *height = res.y; *rgba = new float[4 * *width * *height]; for (int i = 0; i < *width * *height; ++i) { Float rgb[3]; image[i].ToRGB(rgb); for (int c = 0; c < 3; ++c) { (*rgba)[4 * i + c] = rgb[c]; } (*rgba)[4 * i + 3] = 1.; } return true; }
static void FormatLabel(ImageInfo *image_info,char *label, const unsigned int width,unsigned int *font_height) { Image *image; MonitorHandler handler; register char *p, *q; if (label == (const char *) NULL) return; if (*label == '\0') return; if (strchr(label,'\n') != (char *) NULL) return; /* Format label to fit within a specified width. */ handler=SetMonitorHandler((MonitorHandler) NULL); p=label; for (q=p+1; *q != '\0'; q++) { (void) strcpy(image_info->filename,"label:"); (void) strncat(image_info->filename+6,p,(int) (q-p+1)); image=ReadImage(image_info); if (image == (Image *) NULL) break; if (image->columns > width) { while (!isspace((int) (*q)) && (q > p)) q--; if (q == p) break; *q='\n'; p=q+1; } if (image->rows > *font_height) *font_height=image->rows; DestroyImage(image); } (void) SetMonitorHandler(handler); }
int main(int argc, char** argv) { const char *usage = "usage: hdrconv <input file> <output file>\n"; assert(argc > 2); if (argc <= 2) { printf("%s", usage); return 0; } int width = 0; int height = 0; Color* pixels = ReadImage(argv[1], &width, &height); assert(pixels != 0); if (pixels) { WriteImage(argv[2], &pixels[0].r, 0, width, height, width, height, 0, 0); } return 0; }
InfiniteAreaLightIS ::InfiniteAreaLightIS(const Transform &light2world, const Spectrum &L, int ns, const string &texmap) : Light(light2world, ns) { radianceMap = NULL; if (texmap != "") { int width, height; Spectrum *texels = ReadImage(texmap, &width, &height); if (texels) radianceMap = new MIPMap<Spectrum>(width, height, texels); // Compute scalar-valued image from environment map float filter = 1.f / max(width, height); int nu = width, nv = height; float *img = new float[width*height]; for (int x = 0; x < nu; ++x) { float xp = (float)x / (float)nu; for (int y = 0; y < nv; ++y) { float yp = (float)y / (float)nv; img[y+x*nv] = radianceMap->Lookup(xp, yp, filter).y(); } } // Initialize sampling PDFs for infinite area light float *func = (float *)alloca(max(nu, nv) * sizeof(float)); float *sinVals = (float *)alloca(nv * sizeof(float)); for (int i = 0; i < nv; ++i) sinVals[i] = sin(M_PI * float(i+.5)/float(nv)); vDistribs = new Distribution1D *[nu]; for (int u = 0; u < nu; ++u) { // Compute sampling distribution for column _u_ for (int v = 0; v < nv; ++v) func[v] = img[u*nv+v] *= sinVals[v]; vDistribs[u] = new Distribution1D(func, nv); } // Compute sampling distribution for columns of image for (int u = 0; u < nu; ++u) func[u] = vDistribs[u]->funcInt; uDistrib = new Distribution1D(func, nu); delete[] img; delete[] texels; } Lbase = L; }
int main(int argc, char *argv[]) { Image *img[2]; Kernel *K; timer *t1, *t2; /*--------------------------------------------------------*/ void *trash = malloc(1); struct mallinfo info; int MemDinInicial, MemDinFinal; free(trash); info = mallinfo(); MemDinInicial = info.uordblks; /*--------------------------------------------------------*/ if (argc != 4) Error("Usage: linearfilter <input.scn> <output.scn> <adj. radius>","windowlevel.c"); t1 = Tic(); img[0] = ReadImage(argv[1]); K = GaussianKernel(atof(argv[3])); img[1] = LinearFilter(img[0],K); WriteImage(img[1],argv[2]); DestroyImage(img[0]); DestroyImage(img[1]); DestroyKernel(K); t2 = Toc(); fprintf(stdout,"Linear filtering in %f ms\n",CompTime(t1,t2)); /* ------------------------------------------------------ */ info = mallinfo(); MemDinFinal = info.uordblks; if (MemDinInicial!=MemDinFinal) printf("\n\nDinamic memory was not completely deallocated (%d, %d)\n", MemDinInicial,MemDinFinal); return(0); }
void CopyPhoto::Copy(const Path& file_path, const TCHAR* dest_folder, const TCHAR* rename_pattern) { DWORD start= ::GetTickCount(); CFile file(file_path.c_str(), CFile::modeRead | CFile::shareDenyWrite);// | CFile::osSequentialScan); const uint64 length= file.SeekToEnd(); if (length == 0) return; // do not create empty copies Progress(0, length); // call progress after opening file file.SeekToBegin(); auto_ptr<PhotoInfo> photo; PhotoFactory::CreateFn create= 0; int type_id= 0; if (GetPhotoFactory().MatchPhotoType(file_path.GetExtension(), create, type_id) && type_id != FT_CATALOG) photo.reset(create()); // if there is 'photo' object available try to decode EXIF block if (photo.get()) { // FileStream str; // VERIFY(str.Open(buffer)); ReadImage(photo.get(), file_path, length, 0); } // create destination name Path dest= CreateDestPath(file_path, length, photo.get()); // copy source file to the destination const size_t CHUNK= 0x10000; // 64 KB vector<uint8> buffer(CHUNK, 0); size_t block= static_cast<size_t>(min<uint64>(CHUNK, length)); if (file.Read(&buffer.front(), block) != block) throw 11111; }
// Connect to given device. // Sets the internal handle if connected as requested // returns true when successfull otherwise false bool ArtDrvSim::Connect(unsigned short Device) { if (m_connected) return false; // basically DeviceIsCamera() also sets the member var of the simFilename if (!CheckSimFile(m_simFilename, Device)) return false; // this sets the cameras properties SetSimProperties((EArtCameraType)Device); if ( ! ReadImage(m_simFilename) ) { wxMessageBox(wxT("ArtSimCam: cannot find a proper image raw file - please check installation")); return false; } m_ccdsx = 0; m_ccdsy = 0; m_ccdw = m_camProps.nPixelsX; m_ccdh = m_camProps.nPixelsY; m_binx = 1; m_biny = 1; if (m_artSample.imageMem) { delete m_artSample.imageMem; m_artSample.imageMem = NULL; m_artSample.dataLength = 0; } // make a new image buffer if we know the ccd i.e. call this before reading the ccd m_artSample.dataLength = m_camProps.nPixelsX * m_camProps.nPixelsY; // WORDS full cam size m_artSample.imageMem = new WordImageMem(m_artSample.dataLength); // progressive CCD m_artSample.dataLength *= 2; // make BYTES (this is what is needed to be read m_artSample.ready = false; m_aborted = false; m_pSimThread = new ArtSimThread(this); m_pSimThread->Create(); m_pSimThread->Run(); // let's run it m_abortExposure = false; m_connected = true; m_camState = CAMERA_IDLE; return m_connected; }
void ConvertGbaToPng(char *inputPath, char *outputPath, int width, int bitDepth, char *paletteFilePath, bool hasTransparency) { struct Image image; if (paletteFilePath != NULL) { ReadGbaPalette(paletteFilePath, &image.palette); image.hasPalette = true; } else { image.hasPalette = false; } ReadImage(inputPath, width, bitDepth, &image, !image.hasPalette); image.hasTransparency = hasTransparency; WritePng(outputPath, &image); FreeImage(&image); }
// 从内存加载图片 BOOL ReadImage(const BYTE* buffer, ULONG size, Mat& img) { try { vector<BYTE> _imgBuffer(buffer, buffer + size); img = cv::imdecode(Mat(_imgBuffer), cv::IMREAD_COLOR); } catch (...) { } if (img.data != NULL) return TRUE; // 加载OpenCV不支持的格式(GIF) CImage image; if (!ReadImage(buffer, size, image)) return FALSE; return CImageToMat(image, img); }
// InfiniteAreaLight Method Definitions InfiniteAreaLight::InfiniteAreaLight(const Transform &LightToWorld, const Spectrum &L, int nSamples, const std::string &texmap) : Light((int)LightFlags::Infinite, LightToWorld, MediumInterface(), nSamples) { // Read texel data from _texmap_ and initialize _Lmap_ Point2i resolution; std::unique_ptr<RGBSpectrum[]> texels(nullptr); if (texmap != "") { texels = ReadImage(texmap, &resolution); if (texels) for (int i = 0; i < resolution.x * resolution.y; ++i) texels[i] *= L.ToRGBSpectrum(); } if (!texels) { resolution.x = resolution.y = 1; texels = std::unique_ptr<RGBSpectrum[]>(new RGBSpectrum[1]); texels[0] = L.ToRGBSpectrum(); } Lmap.reset(new MIPMap<RGBSpectrum>(resolution, texels.get())); // Initialize sampling PDFs for infinite area light // Compute scalar-valued image _img_ from environment map int width = 2 * Lmap->Width(), height = 2 * Lmap->Height(); std::unique_ptr<Float[]> img(new Float[width * height]); float fwidth = 0.5f / std::min(width, height); ParallelFor( [&](int64_t v) { Float vp = (v + .5f) / (Float)height; Float sinTheta = std::sin(Pi * (v + .5f) / height); for (int u = 0; u < width; ++u) { Float up = (u + .5f) / (Float)width; img[u + v * width] = Lmap->Lookup(Point2f(up, vp), fwidth).y(); img[u + v * width] *= sinTheta; } }, height, 32); // Compute sampling distributions for rows and columns of image distribution.reset(new Distribution2D(img.get(), width, height)); }
void TestImageSwizzle(void) { BeginTests(); CImage cImage; CImageModifierStack cStack; CImageRGBToGrey* pcRGBToGrey; CImageChannelRename* pcChannelRename; CImageChannelAdd* pcChannelAdd; CImageDrawBox* pcDrawBox; CImageColourRGB cRGB; ReadImage(&cImage, "Input\\swizzel.png"); cStack.Init(&cImage); pcRGBToGrey = cStack.AddModifier<CImageRGBToGrey>(); pcRGBToGrey->Init(RGBTGS_OnlyIfChannelsSame); pcChannelRename = cStack.AddModifier<CImageChannelRename>(); pcChannelRename->Init(IMAGE_DIFFUSE_GREY, IMAGE_OPACITY); pcChannelAdd = cStack.AddModifier<CImageChannelAdd>(); pcChannelAdd->Init(IMAGE_DIFFUSE_RED, PT_uchar); pcChannelAdd->AddChannel(IMAGE_DIFFUSE_GREEN); pcChannelAdd->AddChannel(IMAGE_DIFFUSE_BLUE); pcDrawBox = cStack.AddModifier<CImageDrawBox>(); cRGB.Init(1.0f, 1.0f, 1.0f); pcDrawBox->Init(NULL, &cRGB); cStack.ApplyAll(); cStack.Kill(); WriteImage(&cImage, "Output\\swizzle.raw"); AssertFileMemory("input\\swizzle.raw", cImage.GetData(), cImage.GetByteSize()); cImage.Kill(); TestStatistics(); }
// 更换验证码 void CLoginDlg::OnStnClickedStatic4() { CString src = HTTPGet(_T("https://passport.baidu.com/v2/?reggetcodestr&token=") + m_token + _T("&tpl=mn&apiver=v3&tt=1374720914453&callback=bd__cbs__hb302a"), TRUE, NULL, &m_cookie); m_verifyStr = GetStringBetween(src, _T("\"verifyStr\" : \""), _T("\"")); // 下载图片 unique_ptr<BYTE[]> buffer; ULONG size; HTTPGetRaw(_T("https://passport.baidu.com/cgi-bin/genimage?") + m_verifyStr, &buffer, &size, TRUE, NULL, &m_cookie); if (buffer == NULL) { AfxMessageBox(_T("获取验证码图片失败!"), MB_ICONERROR); return; } ReadImage(buffer.get(), size, m_verifyImage); // 显示图片 m_verifyCodePicture.Invalidate(); }
inline int ReadImage(const char * path, Image<RGBColor> * im) { std::vector<unsigned char> ptr; int w, h, depth; int res = ReadImage(path, &ptr, &w, &h, &depth); if (res == 1) { if(depth == 3) { (*im) = Image<RGBColor>(w, h, (const RGBColor*) &ptr[0]); } else if(depth == 1) { Image<unsigned char> gray(w, h, &ptr[0]); convertImage(gray, im); } else res = 0; // Do not know how to convert to color } return res; }
void TestImageCelTransparentColourCropBorders(void) { CImageCelTransparent cCel; CImage cImage; unsigned int cBlack; cBlack = 0x5a000000; //the 5a represents garbage. Only the first three bytes are used. ReadImage(&cImage, "Input\\cel5.png"); cCel.Init(&cImage, (SImageColour*)&cBlack); cCel.CropTransparentBorders(); AssertInt(24, cCel.GetSubImage()->GetFullWidth()); AssertInt(18, cCel.GetSubImage()->GetImageWidth()); AssertInt(24, cCel.GetSubImage()->GetFullHeight()); AssertInt(19, cCel.GetSubImage()->GetImageHeight()); AssertInt(4, cCel.GetSubImage()->mcImageRect.miLeft); AssertInt(2, cCel.GetSubImage()->mcImageRect.miTop); cCel.Kill(); cImage.Kill(); }
void TestImageGreyToRGB(void) { BeginTests(); CImage cImage; CImageGreyToRGB cGreyToRGB; ReadImage(&cImage, "Input/basn0g08.png"); cGreyToRGB.Init(); cGreyToRGB.Modify(&cImage); cGreyToRGB.Kill(); WriteImage(&cImage, "Output/GreyToRGB.raw"); AssertFileMemory("input/GreyToRGB.raw", cImage.GetData(), cImage.GetByteSize()); cGreyToRGB.Kill(); cImage.Kill(); TestStatistics(); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % R e a d F D I m a g e % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % ReadFDImage retrieves an image via a file descriptor, decodes the image, % and returns it. It allocates the memory necessary for the new Image % structure and returns a pointer to the new image. % % The format of the ReadFDImage method is: % % Image *ReadFDImage(const ImageInfo *image_info,ExceptionInfo *exception) % % A description of each parameter follows: % % o image_info: the image info. % % o exception: return any errors or warnings in this structure. % */ static Image *ReadFDImage(const ImageInfo *image_info,ExceptionInfo *exception) { Image *image; ImageInfo *read_info; /* Open image file. */ assert(image_info != (const ImageInfo *) NULL); assert(image_info->signature == MagickSignature); if (image_info->debug != MagickFalse) (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", image_info->filename); assert(exception != (ExceptionInfo *) NULL); assert(exception->signature == MagickSignature); read_info=CloneImageInfo(image_info); read_info->file=fdopen(StringToLong(image_info->filename),"rb"); if ((read_info->file == (FILE *) NULL) || (IsGeometry(image_info->filename) == MagickFalse)) { read_info=DestroyImageInfo(read_info); ThrowFileException(exception,BlobError,"UnableToOpenBlob", image_info->filename); return((Image *) NULL); } *read_info->magick='\0'; image=ReadImage(read_info,exception); (void) fclose(read_info->file); read_info=DestroyImageInfo(read_info); if (image == (Image *) NULL) { (void) ThrowMagickException(exception,GetMagickModule(),CoderError, "NoDataReturned","`%s'",image_info->filename); return((Image *) NULL); } return(GetFirstImageInList(image)); }
int vips__magick_read( const char *filename, VipsImage *out ) { Read *read; #ifdef DEBUG printf( "magick2vips: vips__magick_read: %s\n", filename ); #endif /*DEBUG*/ if( !(read = read_new( filename, out )) ) return( -1 ); #ifdef HAVE_SETIMAGEOPTION /* When reading DICOM images, we want to ignore any * window_center/_width setting, since it may put pixels outside the * 0-65535 range and lose data. * * These window settings are attached as vips metadata, so our caller * can interpret them if it wants. */ SetImageOption( read->image_info, "dcm:display-range", "reset" ); #endif /*HAVE_SETIMAGEOPTION*/ read->image = ReadImage( read->image_info, &read->exception ); if( !read->image ) { vips_error( "magick2vips", _( "unable to read file \"%s\"\n" "libMagick error: %s %s" ), filename, read->exception.reason, read->exception.description ); return( -1 ); } if( parse_header( read ) ) return( -1 ); if( vips_image_generate( out, NULL, magick_fill_region, NULL, read, NULL ) ) return( -1 ); return( 0 ); }