ResourceManager::ResourceManager() : wxImageList(16, 16, true) { thm = new FileThemeHandler(); wxString sTheme = wxT("Default"); bool bLoaded = thm->LoadTheme(sTheme); if(!bLoaded) throw wx::Exception(wxT("ResourceManager::ResourceManager() Can't load theme '%s'"), sTheme.c_str()); // The following list holds standard items for the DirectoryView // See ResourceManager::GetImageIndex() and ResourceManager::GetFileImageIndex() // before making any changes wxBitmap bmpUnknown = thm->GetImage(resUnknown); if(!bmpUnknown.Ok()) throw wx::Exception(wxT("ResourceManager::ResourceManager() Can't load image 'Unknown'")); Add(bmpUnknown); Add(thm->GetImage(resCharacter)); Add(thm->GetImage(resBlock)); Add(thm->GetImage(resFIFO)); Add(thm->GetImage(resLink)); nFolderIndexBase = GetImageCount(); Add(thm->GetImage(resFolderNormal)); Add(thm->GetImage(resFolderHidden)); Add(thm->GetImage(resFolderNormalDropTarget)); Add(thm->GetImage(resFolderHiddenDropTarget)); nFileIndexBase = GetImageCount(); Add(thm->GetImage(resFileNormal)); Add(thm->GetImage(resFileHidden)); }
LPBYTE ExeIconReplacer::CreateIconGroupData(int nBaseID) { delete m_group; m_group = new BYTE[SizeOfIconGroupData()]; CopyMemory(m_group, &m_dir, sizeof(ICONDIR)); int offset = sizeof(ICONDIR); for (int i = 0; i < GetImageCount(); i++) { BITMAPINFOHEADER bmih; CopyMemory(&bmih, GetImageData(i), sizeof(BITMAPINFOHEADER)); GRPICONDIRENTRY grpEntry; grpEntry.bWidth = m_entry[i].bWidth; grpEntry.bHeight = m_entry[i].bHeight; grpEntry.bColorCount = m_entry[i].bColorCount; grpEntry.bReserved = m_entry[i].bReserved; grpEntry.wPlanes = bmih.biPlanes; grpEntry.wBitCount = bmih.biBitCount; grpEntry.dwBytesInRes = m_entry[i].dwBytesInRes; grpEntry.nID = nBaseID + i; CopyMemory(m_group + offset, &grpEntry, sizeof(GRPICONDIRENTRY)); offset += sizeof(GRPICONDIRENTRY); } return m_group; } // ExeIconReplacer::CreateIconGroupData
void CGImageCache::FlushCache (void) // FlushCache // // Remove all images from the cache { int i; // Release all surfaces for (i = 0; i < GetImageCount(); i++) { IMAGEDATASTRUCT *pData = GetImage(i); pData->pSurface->Release(); if (pData->hDepth) DeleteObject(pData->hDepth); if (pData->pTrans) MemFree(pData->pTrans); } // Empty the lists m_UNIDMap.RemoveAll(); m_Images.RemoveAll(); }
//////////////////////////// // STOP EXPOSURE IMAGE READY void Alta::StopExposureImageReady(const bool Digitize ) { if( GetImageCount() > 1) { // cancel the USB transfer, which should clear the IO interface // which should allow register access m_CamIo->CancelImgXfer(); //tell the fpga to stop imaging WriteReg(CameraRegs::CMD_B, CameraRegs::CMD_B_END_EXPOSURE_BIT ); // calling this again to make sure the CAMCON and BUFCON internals // are ok and not mucked up if data was transfered between // the first hard stop and the register call HardStopExposure( "Hard stop 1 of an exposure of image sequences" ); } else { // check if the user wants single the image if( !Digitize ) { GrabImageAndThrowItAway(); } } }
int ResourceManager::AddImage(const wxString& sFileType, const wxBitmap& bmp) { int nNewIndex = GetImageCount(); Add(bmp); hImageIndex[sFileType] = nNewIndex; return nNewIndex; }
void ImageMultiplexer::GetImageDimensions(unsigned int& width, unsigned int& height) const { unsigned int cols; unsigned int rows; GetImageCount(cols, rows); const float maxWidth = (float)m_width / (float)cols; const float maxHeight = (float)m_height / (float)rows; width = (unsigned int)std::min(maxWidth, maxHeight * IMAGE_ASPECT_RATIO); height = (unsigned int)std::min(maxHeight, maxWidth / IMAGE_ASPECT_RATIO); }
//////////////////////////// // EXPOSURE Z uint16_t Alta::ExposureZ() { #ifdef DEBUGGING_CAMERA apgHelper::DebugMsg( "Alta::ExposureZ" ); #endif //detemine number of images if( Apg::CameraMode_TDI == m_CamMode->GetMode() ) { return GetTdiRows(); } return GetImageCount(); }
//////////////////////////// // GET IMAGE Z uint16_t Alta::GetImageZ() { #ifdef DEBUGGING_CAMERA apgHelper::DebugMsg( "Alta::GetImageZ" ); #endif if( Apg::CameraMode_TDI == m_CamMode->GetMode() && m_CamMode->IsBulkDownloadOn() ) { return GetTdiRows(); } return (m_CamMode->IsBulkDownloadOn() ? GetImageCount() : 1 ); }
void cAnimWnd::OnTimer(UINT nIDEvent) { // TODO: Add your message handler code here and/or call default switch (nIDEvent) { case TIMER_ID: { if (m_MemDC) { if (m_ImageIndex++ >= GetImageCount() - 1) m_ImageIndex = 0; Invalidate(TRUE); } } } CWnd::OnTimer(nIDEvent); }
bool compress_and_save(const std::shared_ptr<Spec> spec) { HRESULT hr; hr = ::CoInitializeEx(NULL, COINIT_MULTITHREADED); if (FAILED(hr)) { printf(_T(" CoInitializeEx failed. ret = 0x%x\n"), hr); return false; } auto image = load_image_from_file(spec->input_name); if (!image) { return false; } bool with_ispc_texcomp = true; auto& meta = image->GetMetadata(); if (!ISALIGN(meta.width, 4) || !ISALIGN(meta.height, 4) || is_dither_compression(spec)) { with_ispc_texcomp = false; } image = with_ispc_texcomp ? compress_with_ispc(std::move(image), spec) : compress_with_dxtex(std::move(image), spec); int res = S_FALSE; if (image) { hr = DirectX::SaveToDDSFile(image->GetImages(), image->GetImageCount(), image->GetMetadata(), DirectX::DDS_FLAGS_NONE, spec->output_name.c_str()); if (FAILED(hr)) { printf(_T(" DirectX::SaveToDDSFile failed. ret = 0x%x\n"), hr); } else { printf(_T("done.\n")); res = S_OK; } } ::CoUninitialize(); return res == S_OK ? true : false; }
// **************************************************************************** // * LoadGIF * // * Load a GIF File into the CAnimatedGifSet object * // * (c) Nov 2000, Juan Soulie <*****@*****.**> * // **************************************************************************** int CAnimatedGifSet::LoadGIF (const char * szFileName) { int n; // Global GIF variables: int GlobalBPP; // Bits per Pixel. COLOR * GlobalColorMap; // Global colormap (allocate) struct GIFGCEtag { // GRAPHIC CONTROL EXTENSION unsigned char BlockSize; // Block Size: 4 bytes unsigned char PackedFields; // 3.. Packed Fields. Bits detail: // 0: Transparent Color Flag // 1: User Input Flag // 2-4: Disposal Method unsigned short Delay; // 4..5 Delay Time (1/100 seconds) unsigned char Transparent; // 6.. Transparent Color Index } gifgce; struct GIFNetscapeTag { unsigned char comment[11]; //4...14 NETSCAPE2.0 unsigned char SubBlockLength; //15 0x3 unsigned char reserved; //16 0x1 unsigned short iIterations ; //17..18 number of iterations (lo-hi) } gifnetscape; int GraphicExtensionFound = 0; // OPEN FILE FILE *fd = fopen_utf8(CSpecialProtocol::TranslatePath(szFileName), "rb"); if (!fd) { return 0; } // *1* READ HEADERBLOCK (6bytes) (SIGNATURE + VERSION) char szSignature[6]; // First 6 bytes (GIF87a or GIF89a) int iRead = fread(szSignature, 1, 6, fd); if (iRead != 6) { fclose(fd); return 0; } if ( memcmp(szSignature, "GIF", 2) != 0) { fclose(fd); return 0; } // *2* READ LOGICAL SCREEN DESCRIPTOR struct GIFLSDtag { unsigned short ScreenWidth; // Logical Screen Width unsigned short ScreenHeight; // Logical Screen Height unsigned char PackedFields; // Packed Fields. Bits detail: // 0-2: Size of Global Color Table // 3: Sort Flag // 4-6: Color Resolution // 7: Global Color Table Flag unsigned char Background; // Background Color Index unsigned char PixelAspectRatio; // Pixel Aspect Ratio } giflsd; iRead = fread(&giflsd, 1, sizeof(giflsd), fd); if (iRead != sizeof(giflsd)) { fclose(fd); return 0; } // endian swap SWAP16(giflsd.ScreenWidth); SWAP16(giflsd.ScreenHeight); GlobalBPP = (giflsd.PackedFields & 0x07) + 1; // fill some animation data: FrameWidth = giflsd.ScreenWidth; FrameHeight = giflsd.ScreenHeight; nLoops = 1; //default=play animation 1 time // *3* READ/GENERATE GLOBAL COLOR MAP GlobalColorMap = new COLOR [1 << GlobalBPP]; if (giflsd.PackedFields & 0x80) // File has global color map? for (n = 0;n < 1 << GlobalBPP;n++) { GlobalColorMap[n].r = getbyte(fd); GlobalColorMap[n].g = getbyte(fd); GlobalColorMap[n].b = getbyte(fd); GlobalColorMap[n].x = 0; } else // GIF standard says to provide an internal default Palette: for (n = 0;n < 256;n++) { GlobalColorMap[n].r = GlobalColorMap[n].g = GlobalColorMap[n].b = n; GlobalColorMap[n].x = 0; } // *4* NOW WE HAVE 3 POSSIBILITIES: // 4a) Get and Extension Block (Blocks with additional information) // 4b) Get an Image Separator (Introductor to an image) // 4c) Get the trailer Char (End of GIF File) do { int charGot = getbyte(fd); if (charGot == 0x21) // *A* EXTENSION BLOCK { unsigned char extensionType = getbyte(fd); switch (extensionType) { case 0xF9: // Graphic Control Extension { if (fread((char*)&gifgce, 1, sizeof(gifgce), fd) == sizeof(gifgce)) SWAP16(gifgce.Delay); GraphicExtensionFound++; getbyte(fd); // Block Terminator (always 0) } break; case 0xFE: // Comment Extension: Ignored { while (int nBlockLength = getbyte(fd)) for (n = 0;n < nBlockLength;n++) getbyte(fd); } break; case 0x01: // PlainText Extension: Ignored { while (int nBlockLength = getbyte(fd)) for (n = 0;n < nBlockLength;n++) getbyte(fd); } break; case 0xFF: // Application Extension: Ignored { int nBlockLength = getbyte(fd); if (nBlockLength == 0x0b) { struct GIFNetscapeTag tag; if (fread((char*)&tag, 1, sizeof(gifnetscape), fd) == sizeof(gifnetscape)) { SWAP16(tag.iIterations); nLoops = tag.iIterations; } else nLoops = 0; if (nLoops) nLoops++; getbyte(fd); } else { do { for (n = 0;n < nBlockLength;n++) getbyte(fd); } while ((nBlockLength = getbyte(fd)) != 0); } } break; default: // Unknown Extension: Ignored { // read (and ignore) data sub-blocks while (int nBlockLength = getbyte(fd)) for (n = 0;n < nBlockLength;n++) getbyte(fd); } break; } } else if (charGot == 0x2c) { // *B* IMAGE (0x2c Image Separator) // Create a new Image Object: CAnimatedGif* NextImage = new CAnimatedGif(); // Read Image Descriptor struct GIFIDtag { unsigned short xPos; // Image Left Position unsigned short yPos; // Image Top Position unsigned short Width; // Image Width unsigned short Height; // Image Height unsigned char PackedFields; // Packed Fields. Bits detail: // 0-2: Size of Local Color Table // 3-4: (Reserved) // 5: Sort Flag // 6: Interlace Flag // 7: Local Color Table Flag } gifid; memset(&gifid, 0, sizeof(gifid)); int LocalColorMap = 0; if (fread((char*)&gifid, 1, sizeof(gifid), fd) == sizeof(gifid)) { SWAP16(gifid.xPos); SWAP16(gifid.yPos); SWAP16(gifid.Width); SWAP16(gifid.Height); LocalColorMap = (gifid.PackedFields & 0x08) ? 1 : 0; } NextImage->Init(gifid.Width, gifid.Height, LocalColorMap ? (gifid.PackedFields&7) + 1 : GlobalBPP); // Fill NextImage Data NextImage->xPos = gifid.xPos; NextImage->yPos = gifid.yPos; if (GraphicExtensionFound) { NextImage->Transparent = (gifgce.PackedFields & 0x01) ? gifgce.Transparent : -1; NextImage->Transparency = (gifgce.PackedFields & 0x1c) > 1 ? 1 : 0; NextImage->Delay = gifgce.Delay * 10; } if (NextImage->Transparent != -1) memset(NextImage->Raster, NextImage->Transparent, NextImage->BytesPerRow * NextImage->Height); else memset(NextImage->Raster, giflsd.Background, NextImage->BytesPerRow * NextImage->Height); // Read Color Map (if descriptor says so) size_t palSize = sizeof(COLOR)*(1 << NextImage->BPP); bool isPalRead = false; if (LocalColorMap && fread((char*)NextImage->Palette, 1, palSize, fd) == palSize) isPalRead = true; // Copy global, if no palette if (!isPalRead) memcpy(NextImage->Palette, GlobalColorMap, palSize); short firstbyte = getbyte(fd); // 1st byte of img block (CodeSize) // Calculate compressed image block size // to fix: this allocates an extra byte per block long ImgStart, ImgEnd; ImgEnd = ImgStart = ftell(fd); while ((n = getbyte(fd)) != 0) fseek (fd, ImgEnd += n + 1, SEEK_SET ); fseek (fd, ImgStart, SEEK_SET); // Allocate Space for Compressed Image char * pCompressedImage = new char [ImgEnd - ImgStart + 4]; // Read and store Compressed Image char * pTemp = pCompressedImage; while (int nBlockLength = getbyte(fd)) { if (fread(pTemp, 1, nBlockLength, fd) != (size_t)nBlockLength) { // Error? } pTemp += nBlockLength; } // Call LZW/GIF decompressor n = LZWDecoder( (char*) pCompressedImage, (char*) NextImage->Raster, firstbyte, NextImage->BytesPerRow, //NextImage->AlignedWidth, gifid.Width, gifid.Height, ((gifid.PackedFields & 0x40) ? 1 : 0) //Interlaced? ); if (n) AddImage(NextImage); else { delete NextImage; ERRORMSG("GIF File Corrupt"); } // Some cleanup delete[] pCompressedImage; GraphicExtensionFound = 0; } else if (charGot == 0x3b) { // *C* TRAILER: End of GIF Info break; // Ok. Standard End. } } while ( !feof(fd) ); delete[] GlobalColorMap; fclose(fd); if ( GetImageCount() == 0) ERRORMSG("Premature End Of File"); return GetImageCount(); }
//////////////////////////// // GET IMAGE void Alta::GetImage( std::vector<uint16_t> & out ) { #ifdef DEBUGGING_CAMERA apgHelper::DebugMsg( "Alta::GetImage -> BEGINNING" ); #endif ApgLogger::Instance().Write(ApgLogger::LEVEL_DEBUG,"info","Getting Image."); //pre-condition make sure the image is ready if( Apg::CameraMode_TDI == GetCameraMode() && !IsBulkDownloadOn() ) { if( Apg::Status_ImagingActive != GetImagingStatus() ) { std::stringstream msg; msg << "Invalid imaging status, " << GetImagingStatus(); msg << ", for getting TDI image data."; apgHelper::throwRuntimeException( m_fileName, msg.str(), __LINE__, Apg::ErrorType_InvalidMode ); } } else { Apg::Status actualStatus = Apg::Status_Idle; if( !CheckAndWaitForStatus( Apg::Status_ImageReady, actualStatus ) ) { std::stringstream msg; msg << "Invalid imaging status, " << actualStatus; msg << ", for getting image data."; apgHelper::throwRuntimeException( m_fileName, msg.str(), __LINE__, Apg::ErrorType_InvalidMode ); } } // allocating the buffers for the image // doing this outside of the try / catch, so that // even if the GetImage function throws // we can try to copy whatever data we managed // to fetch from the camera into the user supplied // vector uint16_t r=0, c = 0; ExposureAndGetImgRC( r, c ); const uint16_t z = GetImageZ(); std::vector<uint16_t> datafromCam( r*c*z, 0 ); const int32_t dataLen = r*z; const int32_t numCols = GetRoiNumCols(); if( dataLen*numCols != apgHelper::SizeT2Int32( out.size() ) ) { out.clear(); out.resize( dataLen*numCols ); } try { m_CamIo->GetImageData( datafromCam ); } catch(std::exception & err ) { m_ImageInProgress = false; // log and remove the AD garbage pixels at the beginning of every row std::string msg( "Removing AD latency pixels in exception handler" ); ApgLogger::Instance().Write(ApgLogger::LEVEL_RELEASE,"error", apgHelper::mkMsg( m_fileName, msg, __LINE__) ); FixImgFromCamera( datafromCam, out, dataLen, numCols ); throw; } ++m_NumImgsDownloaded; #ifdef DEBUGGING_CAMERA apgHelper::DebugMsg( "Alta::GetImage -> m_NumImgsDownloaded = %d", m_NumImgsDownloaded ); #endif //determine if we are done imaging if( m_CamMode->GetMode() == Apg::CameraMode_TDI ) { if( GetTdiRows() == m_NumImgsDownloaded || IsBulkDownloadOn() ) { m_ImageInProgress = false; Reset( true ); } } else { if( IsBulkDownloadOn() || GetImageCount() == m_NumImgsDownloaded ) { m_ImageInProgress = false; } } #ifdef DEBUGGING_CAMERA apgHelper::DebugMsg( "Alta::GetImage -> m_ImageInProgress = %d", m_ImageInProgress ); #endif // removing the AD garbage pixels at the beginning of every row FixImgFromCamera( datafromCam, out, dataLen, numCols ); ApgLogger::Instance().Write(ApgLogger::LEVEL_DEBUG,"info","Get Image Completed."); #ifdef DEBUGGING_CAMERA apgHelper::DebugMsg( "Alta::GetImage -> END" ); #endif }
//////////////////////////// // GET IMAGING STATUS Apg::Status Alta::GetImagingStatus() { #ifdef DEBUGGING_CAMERA apgHelper::DebugMsg( "Alta::GetImagingStatus" ); #endif CameraStatusRegs StatusObj = GetStatus(); const uint16_t statusReg = StatusObj.GetStatus(); //throw if there is an error IsThereAStatusError(statusReg); //see if we are waiting on hardware triggers if( statusReg & CameraRegs::STATUS_WAITING_TRIGGER_BIT ) { //the user is externally controlling the exposure time if( m_CamMode->IsTriggerExternalShutterOn() && (statusReg & CameraRegs::STATUS_IMAGING_ACTIVE_BIT) && (statusReg & CameraRegs::STATUS_IMAGE_EXPOSING_BIT) ) { return LogAndReturnStatus( Apg::Status_Exposing, StatusObj ); } else { return LogAndReturnStatus( Apg::Status_WaitingOnTrigger, StatusObj ); } } if( m_ImageInProgress ) { const bool ImgDone = IsImgDone( StatusObj ); //see if we are in tdi mode if( Apg::CameraMode_TDI != GetCameraMode() ) { //see if we are doing a sequence if( GetImageCount() > 1 ) { if( m_CamMode->IsBulkDownloadOn() ) { if( ImgDone ) { return LogAndReturnStatus( Apg::Status_ImageReady, StatusObj ); } } else if( GetImgSequenceCount() > m_NumImgsDownloaded ) { return LogAndReturnStatus( Apg::Status_ImageReady, StatusObj ); } } else { //use this logic for a single image if( ImgDone ) { return LogAndReturnStatus( Apg::Status_ImageReady, StatusObj ); } } } //made up mode for TDI if( Apg::CameraMode_TDI == GetCameraMode() ) { if( IsBulkDownloadOn() && ImgDone ) { return LogAndReturnStatus( Apg::Status_ImageReady, StatusObj ); } else { return LogAndReturnStatus( Apg::Status_ImagingActive, StatusObj ); } } } //exposing OR active if( statusReg & CameraRegs::STATUS_IMAGING_ACTIVE_BIT ) { if( statusReg & CameraRegs::STATUS_IMAGE_EXPOSING_BIT ) { return LogAndReturnStatus( Apg::Status_Exposing, StatusObj ); } else { return LogAndReturnStatus( Apg::Status_ImagingActive, StatusObj ); } } //flushing if( statusReg & CameraRegs::STATUS_FLUSHING_BIT ) { return LogAndReturnStatus( Apg::Status_Flushing, StatusObj ); } //fall through return LogAndReturnStatus( Apg::Status_Idle, StatusObj ); }
~DynamicImages() { for (int i = 0; i < GetImageCount(); ++i) { delete image_list_[i]; } }