bool WICImageLoader::encodeImageData(std::string path, const unsigned char* data, size_t dataLen, WICPixelFormatGUID pixelFormat, int width, int height, GUID containerFormat) { assert(data != NULL); assert(dataLen > 0 && width > 0 && height > 0); IWICImagingFactory* pFact = getWICFactory(); HRESULT hr = E_FAIL; IWICStream* pStream = NULL; if (NULL != pFact) { hr = pFact->CreateStream(&pStream); } if (SUCCEEDED(hr)) { hr = pStream->InitializeFromFilename(StringUtf8ToWideChar(path).c_str(), GENERIC_WRITE); } IWICBitmapEncoder* pEnc = NULL; if (SUCCEEDED(hr)) { hr = pFact->CreateEncoder(containerFormat, NULL, &pEnc); } if (SUCCEEDED(hr)) { hr = pEnc->Initialize(pStream, WICBitmapEncoderNoCache); } IWICBitmapFrameEncode* pFrame = NULL; IPropertyBag2* pProp = NULL; if (SUCCEEDED(hr)) { hr = pEnc->CreateNewFrame(&pFrame, &pProp); } if (SUCCEEDED(hr)) { hr = pFrame->Initialize(pProp); } if (SUCCEEDED(hr)) { hr = pFrame->SetSize(width, height); } if (SUCCEEDED(hr)) { WICPixelFormatGUID targetFormat = pixelFormat; hr = pFrame->SetPixelFormat(&targetFormat); if (targetFormat != pixelFormat) { hr = E_INVALIDARG; } } if (SUCCEEDED(hr)) { size_t bpp = getBitsPerPixel(pixelFormat); size_t stride = (width * bpp + 7) / 8; hr = pFrame->WritePixels(height, static_cast<UINT>(stride), static_cast<UINT>(dataLen), (BYTE*)data); } if (SUCCEEDED(hr)) { hr = pFrame->Commit(); } if (SUCCEEDED(hr)) { hr = pEnc->Commit(); } SafeRelease(&pStream); SafeRelease(&pEnc); SafeRelease(&pFrame); SafeRelease(&pProp); return SUCCEEDED(hr); }
// // IWindowSurface::clear // // Clears the surface to black. // void IWindowSurface::clear() { const argb_t color(255, 0, 0, 0); lock(); if (getBitsPerPixel() == 8) { const argb_t* palette_colors = V_GetDefaultPalette()->basecolors; palindex_t color_index = V_BestColor(palette_colors, color); palindex_t* dest = (palindex_t*)getBuffer(); for (int y = 0; y < getHeight(); y++) { memset(dest, color_index, getWidth()); dest += getPitchInPixels(); } } else { argb_t* dest = (argb_t*)getBuffer(); for (int y = 0; y < getHeight(); y++) { for (int x = 0; x < getWidth(); x++) dest[x] = color; dest += getPitchInPixels(); } } unlock(); }
/** * Clones a current Image. * If, for any reason the Image cannot be copied, * then NULL is returned. */ JPGImage* JPGImage::clone(){ //Create a new instance of JPG Image and copy //the features of the current instance to the new instance. JPGImage *j = new JPGImage(); j->setWidth(getWidth()); j->setHeight(getHeight()); j->setSize(getSize()); j->setFilename(getFilename()); try{ j->createPixelMatrix(j->getWidth(), j->getHeight()); } catch (...) { return NULL; } for(int x = 0; x < j->getWidth(); x++){ for (int y = 0; y < j->getHeight(); y++){ Pixel *p = new Pixel(getPixel(x, y)); j->setPixel(x, y, p); delete(p); } } j->setImageID(getImageID()); j->setChannels(getChannels()); j->setGrayScaleAvaliable(isGrayScaleAvaliable()); j->setBlackAndWhiteAvaliable(isBlackAndWhiteAvaliable()); j->setBitsPerPixel(getBitsPerPixel()); return j; }
bool WICImageLoader::processImage(IWICBitmapDecoder* pDecoder) { HRESULT hr = E_FAIL; IWICBitmapFrameDecode* pFrame = NULL; if(NULL != pDecoder) { hr = pDecoder->GetFrame(0, &pFrame); } if(SUCCEEDED(hr)) { hr = pFrame->GetPixelFormat(&_format); } IWICFormatConverter* pConv = NULL; if(SUCCEEDED(hr)) { hr = convertFormatIfRequired(pFrame, &pConv); } if(SUCCEEDED(hr)) { _bpp = getBitsPerPixel(_format); if(NULL != pConv) { hr = pConv->GetSize((UINT*)&_width, (UINT*)&_height); } else { hr = pFrame->GetSize((UINT*)&_width, (UINT*)&_height); } } assert(_bpp > 0); assert(_width > 0 && _height > 0); if(SUCCEEDED(hr)) { size_t rowPitch = (_width * _bpp + 7) / 8; _dataLen = rowPitch * _height; _data = new (std::nothrow) BYTE[_dataLen]; if(NULL != pConv) { hr = pConv->CopyPixels(NULL, static_cast<UINT>(rowPitch), static_cast<UINT>(_dataLen), _data); } else { hr = pFrame->CopyPixels(NULL, static_cast<UINT>(rowPitch), static_cast<UINT>(_dataLen), _data); } } SafeRelease(&pFrame); SafeRelease(&pConv); return SUCCEEDED(hr); }
STDMETHODIMP Display::GetScreenResolution(ULONG aScreenId, ULONG *aWidth, ULONG *aHeight, ULONG *aBitsPerPixel) { if (aWidth) *aWidth = getWidth(); if (aHeight) *aHeight = getHeight(); if (aBitsPerPixel) *aBitsPerPixel = getBitsPerPixel(); return S_OK; }
/******************************************************************************* * mvCamSensorPixelSizeGet - Get the Pixel size in bytes * * DESCRIPTION: * * INPUT: * Pointer to Camera Sensor Data structure. * * OUTPUT: * pixelSize - Pointer to store the pixel size * * RETURN: * MV_BAD_PTR: if data structure not allocated or invalid output pointers * MV_OK otherwise *******************************************************************************/ MV_STATUS mvCamSensorPixelSizeGet(MV_CAM_SENSOR *pCamSensor, MV_U32 *pixelSize) { mvOsPrintf("mvCamSensorPixelSizeGet\n"); if(!pCamSensor || !pixelSize) { mvOsPrintf("mvCamSensorPixelSizeGet: Bad Input\n"); return MV_BAD_PTR; } *pixelSize = getBitsPerPixel(pCamSensor); return MV_OK; }
IUnknown* DX11Engine::createTexture2D_SRV(IUnknown* pDeviceIn, const Texture& info, const char* buffer, size_t size, const char* name) const { auto pDevice = reinterpret_cast<ID3D11Device*>(pDeviceIn); HRESULT hr; D3D11_TEXTURE2D_DESC tex = { uint32_t(info.mWidth), uint32_t(info.mHeight), uint32_t(info.mMipCount), uint32_t(info.mArraySize), info.mFormat, { 1, 0 }, D3D11_USAGE_DEFAULT, D3D11_BIND_SHADER_RESOURCE, 0, 0 }; if(info.eMiscGenerateMipMaps) { tex.MipLevels = 0; tex.MiscFlags |= D3D11_RESOURCE_MISC_GENERATE_MIPS; tex.BindFlags |= D3D11_BIND_RENDER_TARGET; } uint32_t bpp = getBitsPerPixel(info.mFormat); int level = 1; if (info.eMiscGenerateMipMaps) level = log2i(std::max(info.mWidth, info.mHeight)) + 1; boost::container::small_vector<D3D11_SUBRESOURCE_DATA, 12> subres(level); int w = info.mWidth; int h = info.mHeight; for (int i = 0; i != level; ++i) { subres[i] = D3D11_SUBRESOURCE_DATA{ buffer, w * bpp / 8, 0 }; buffer += mipmap_size<1>(w, h, bpp); w = next_mip_size(w); h = next_mip_size(h); } std::unique_ptr<ID3D11Texture2D, COMDeleter> pTex; std::unique_ptr<ID3D11ShaderResourceView, COMDeleter> pSRV; CD3D11_SHADER_RESOURCE_VIEW_DESC srvDesc(D3D11_SRV_DIMENSION_TEXTURE2D); V(pDevice->CreateTexture2D(&tex, subres.data(), ref(pTex))); V(pDevice->CreateShaderResourceView(pTex.get(), &srvDesc, ref(pSRV))); STAR_SET_DEBUG_NAME(pSRV, size, name); return pSRV.release(); }
/** * Save the current JPG into a file. * * @param filename The name of the file. * * @throw FileException If the image cannot be saved. */ void JPGImage::saveToFile(string filename) throw (artemis::FileException*){ CvScalar s; IplImage *image = cvCreateImage(cvSize(getWidth(), getHeight()), IPL_DEPTH_8U, 0); int div; if ((getBitsPerPixel() > 8) && (getBitsPerPixel() <= 16)) div = 16; else div = 1; for(int x = 0; x < getWidth(); x++){ for(int y = 0; y < getHeight(); y++){ s.val[0] = (getPixel(x, y).getGrayPixelValue()/div); cvSet2D(image, y, x, s); } } filename.append(".jpg"); if (!cvSaveImage(filename.c_str(), image)){ throw new artemis::FileException(0, "This file cannot been created!", filename); } }
std::string ImageLoaderPcxHeader::describe() const { std::stringstream out; out << "PcxHeader Descriptor" << std::endl; out << "identifier: " << (int)mIdentifier << std::endl; out << "version: " << (int)mVersion << std::endl; out << "Encoding: " << (int)mEncoding << std::endl; out << "BitsPerPixel: " << getBitsPerPixel() << std::endl; out << "xStart: " << mXStart << std::endl; out << "yStart: " << mYStart << std::endl; out << "xEnd: " << mXEnd << std::endl; out << "yEnd: " << mYEnd << std::endl; out << "hRes: " << mHRes << std::endl; out << "vRes: " << mVRes << std::endl; out << "numBitPlanes: " << (unsigned int)mNumBitPlanes << std::endl; out << "bytesPerLine: " << (int)mBytesPerLine << std::endl; out << "paletteType: " << (int)mPaletteType << std::endl; return out.str(); }
int ImageLoaderPcxHeader::getType() const { switch(getNumBitPlanes()) { case 1: switch(getBitsPerPixel()) { case 1: return ImageLoaderPcx1Bit; case 8: return ImageLoaderPcx8Bit; } break; case 3: return ImageLoaderPcx24Bit; break; case 4: return ImageLoaderPcx4Bit; break; } return -1; }
// // IWindowSurface::blit // // Blits a surface into this surface, automatically scaling the source image // to fit the destination dimensions. // void IWindowSurface::blit(const IWindowSurface* source_surface, int srcx, int srcy, int srcw, int srch, int destx, int desty, int destw, int desth) { // clamp to source surface edges if (srcx < 0) { srcw += srcx; srcx = 0; } if (srcy < 0) { srch += srcy; srcy = 0; } if (srcx + srcw > source_surface->getWidth()) srcw = source_surface->getWidth() - srcx; if (srcy + srch > source_surface->getHeight()) srch = source_surface->getHeight() - srcy; if (srcw == 0 || srch == 0) return; // clamp to dest surface edges if (destx < 0) { destw += destx; destx = 0; } if (desty < 0) { desth += desty; desty = 0; } if (destx + destw > getWidth()) destw = getWidth() - destx; if (desty + desth > getHeight()) desth = getHeight() - desty; if (destw == 0 || desth == 0) return; fixed_t xstep = FixedDiv(srcw << FRACBITS, destw << FRACBITS); fixed_t ystep = FixedDiv(srch << FRACBITS, desth << FRACBITS); int srcbits = source_surface->getBitsPerPixel(); int destbits = getBitsPerPixel(); int srcpitchpixels = source_surface->getPitchInPixels(); int destpitchpixels = getPitchInPixels(); const argb_t* palette = source_surface->getPalette(); if (srcbits == 8 && destbits == 8) { const palindex_t* source = (palindex_t*)source_surface->getBuffer() + srcy * srcpitchpixels + srcx; palindex_t* dest = (palindex_t*)getBuffer() + desty * destpitchpixels + destx; BlitLoop(dest, source, destpitchpixels, srcpitchpixels, destw, desth, xstep, ystep, palette); } else if (srcbits == 8 && destbits == 32) { if (palette == NULL) return; const palindex_t* source = (palindex_t*)source_surface->getBuffer() + srcy * srcpitchpixels + srcx; argb_t* dest = (argb_t*)getBuffer() + desty * destpitchpixels + destx; BlitLoop(dest, source, destpitchpixels, srcpitchpixels, destw, desth, xstep, ystep, palette); } else if (srcbits == 32 && destbits == 8) { // we can't quickly convert from 32bpp source to 8bpp dest so don't bother return; } else if (srcbits == 32 && destbits == 32) { const argb_t* source = (argb_t*)source_surface->getBuffer() + srcy * srcpitchpixels + srcx; argb_t* dest = (argb_t*)getBuffer() + desty * destpitchpixels + destx; BlitLoop(dest, source, destpitchpixels, srcpitchpixels, destw, desth, xstep, ystep, palette); } }
BOOL fipWinImage::captureWindow(HWND hWndApplicationWindow, HWND hWndSelectedWindow) { int xScreen, yScreen, xshift, yshift; RECT r; // Get window size GetWindowRect(hWndSelectedWindow, &r); // Check if the window is out of the screen or maximixed xshift = 0; yshift = 0; xScreen = GetSystemMetrics(SM_CXSCREEN); yScreen = GetSystemMetrics(SM_CYSCREEN); if(r.right > xScreen) r.right = xScreen; if(r.bottom > yScreen) r.bottom = yScreen; if(r.left < 0) { xshift = -r.left; r.left = 0; } if(r.top < 0){ yshift = -r.top; r.top = 0; } int width = r.right - r.left; int height = r.bottom - r.top; if(width <= 0 || height <= 0) return FALSE; // Hide the application window. ShowWindow(hWndApplicationWindow, SW_HIDE); // Bring the window at the top most level SetWindowPos(hWndSelectedWindow, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE); // Give enough time to refresh the window Sleep(500); // Prepare the DCs HDC dstDC = GetDC(NULL); HDC srcDC = GetWindowDC(hWndSelectedWindow); // full window (GetDC(hWndSelectedWindow) = clientarea) HDC memDC = CreateCompatibleDC(dstDC); // Copy the screen to the bitmap HBITMAP bm = CreateCompatibleBitmap(dstDC, width, height); HBITMAP oldbm = (HBITMAP)SelectObject(memDC, bm); BitBlt(memDC, 0, 0, width, height, srcDC, xshift, yshift, SRCCOPY); // Redraw the application window. ShowWindow(hWndApplicationWindow, SW_SHOW); // Restore the position SetWindowPos(hWndSelectedWindow, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE); SetWindowPos(hWndApplicationWindow, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE); // Convert the HBITMAP to a FIBITMAP copyFromBitmap(bm); // Free objects DeleteObject(SelectObject(memDC, oldbm)); DeleteDC(memDC); // Convert 32-bit images to 24-bit if(getBitsPerPixel() == 32) { convertTo24Bits(); } return TRUE; }
bool ossimGeneralRasterInfo::initializeFromHdr( const ossimFilename& imageFile, const ossimFilename& headerFile ) { bool result = false; ossimKeywordlist kwl; char delimeter = ' '; kwl.change_delimiter(delimeter); if ( kwl.addFile(headerFile) ) { kwl.downcaseKeywords(); ossimString value; while( 1 ) { //--- // Go through the data members in order. // If a required item is not found break from loop. //-- theMetaData.clear(); // scalar ( default ) - adjusted below : theMetaData.setScalarType( OSSIM_UINT8 ); // Image file name: theImageFileList.clear(); theImageFileList.push_back( imageFile ); // interleave ( not required - default=BIL) theInterleaveType = OSSIM_BIL; value.string() = kwl.findKey( std::string("layout") ); if ( value.size() ) { ossimInterleaveTypeLut lut; ossim_int32 intrlv = lut.getEntryNumber( value.string().c_str(), true ); if ( intrlv != ossimLookUpTable::NOT_FOUND ) { theInterleaveType = static_cast<ossimInterleaveType>(intrlv); } } // bands ( required ): ossim_uint32 bands = 0; value.string() = kwl.findKey( std::string("nbands") ); if ( value.size() ) { bands = value.toUInt32(); } if ( !bands ) { break; } theMetaData.setNumberOfBands( bands ); // lines ( required ): ossim_int32 lines = 0; value.string() = kwl.findKey( std::string("nrows") ); if ( value.size() ) { lines = value.toInt32(); } if ( !lines ) { break; } // samples ( required ): ossim_int32 samples = 0; value.string() = kwl.findKey( std::string("ncols") ); if ( value.size() ) { samples = value.toInt32(); } if ( !samples ) { break; } // nodata or null value ( not required ) value.string() = kwl.findKey( std::string("nodata") ); if ( value.empty() ) { value.string() = kwl.findKey( std::string("nodata_value") ); } if ( value.size() ) { ossim_float64 nullValue = value.toUInt32(); for ( ossim_uint32 band = 0; band < theMetaData.getNumberOfBands(); ++band ) { theMetaData.setNullPix( band, nullValue ); } theMetaData.setNullValuesValid(true); } // Set the rectangles: theRawImageRect = ossimIrect( 0, 0, samples - 1, lines - 1 ); theValidImageRect = theRawImageRect; theImageRect = theRawImageRect; // sample start ( not required ): theSubImageOffset.x = 0; // line start ( not required ): theSubImageOffset.y = 0; // header offset ( not required ): theHeaderSize = 0; // null mode: theSetNullsMode = ossimGeneralRasterInfo::NONE; // pixels to chop: thePixelsToChop = 0; // Byte order, ( not required - defaulted to system if not found. theImageDataByteOrder = ossim::byteOrder(); value.string() = kwl.findKey( std::string("byteorder") ); if ( value.size() ) { ossim_uint32 i = value.toUInt32(); if ( i == 0 ) { theImageDataByteOrder = OSSIM_LITTLE_ENDIAN; } else { theImageDataByteOrder = OSSIM_BIG_ENDIAN; } } // Pixel type used for scalar below: std::string pixelType = "N"; // not defined value.string() = kwl.findKey( std::string("pixeltype") ); if ( value.size() ) { pixelType = value.string(); } ossim_int32 nbits = -1; value.string() = kwl.findKey( std::string("nbits") ); if ( value.size() ) { nbits = value.toInt32(); } else { nbits = getBitsPerPixel( imageFile ); } switch( nbits ) { case 8: { theMetaData.setScalarType( OSSIM_UINT8 ); break; } case 16: { if (pixelType == "S") { theMetaData.setScalarType( OSSIM_SINT16 ); } else { theMetaData.setScalarType( OSSIM_UINT16 ); } break; } case 32: { if( pixelType == "S") { theMetaData.setScalarType( OSSIM_SINT32 ); } else if( pixelType == "F") { theMetaData.setScalarType( OSSIM_FLOAT32 ); } else { theMetaData.setScalarType( OSSIM_UINT32 ); } break; } default: { if( (nbits < 8) && (nbits >= 1 ) ) { theMetaData.setScalarType( OSSIM_UINT8 ); } break; } } result = true; break; // Trailing break to get out. } } return result; } // End: ossimGeneralRasterInfo::initializeFromHdr
bool WICImageLoader::encodeImageData(std::string path, ImageBlob data, size_t dataLen, WICPixelFormatGUID pixelFormat, int width, int height, GUID containerFormat) { assert(data != NULL); assert(dataLen > 0 && width > 0 && height > 0); IWICImagingFactory* pFact = getWICFactory(); HRESULT hr = S_FALSE; IWICStream* pStream = NULL; if(NULL != pFact) { hr = pFact->CreateStream(&pStream); } if(SUCCEEDED(hr)) { std::wstring wpath; wpath.assign(path.begin(), path.end()); hr = pStream->InitializeFromFilename(wpath.c_str(), GENERIC_WRITE); } IWICBitmapEncoder* pEnc = NULL; if(SUCCEEDED(hr)) { hr = pFact->CreateEncoder(containerFormat, NULL, &pEnc); } if(SUCCEEDED(hr)) { hr = pEnc->Initialize(pStream, WICBitmapEncoderNoCache); } IWICBitmapFrameEncode* pFrame = NULL; IPropertyBag2* pProp = NULL; if(SUCCEEDED(hr)) { hr = pEnc->CreateNewFrame(&pFrame, &pProp); } if(SUCCEEDED(hr)) { hr = pFrame->Initialize(pProp); } if(SUCCEEDED(hr)) { hr = pFrame->SetSize(width, height); } if(SUCCEEDED(hr)) { hr = pFrame->SetPixelFormat(&pixelFormat); } if(SUCCEEDED(hr)) { size_t bpp = getBitsPerPixel(pixelFormat); size_t stride = (width * bpp + 7) / 8; hr = pFrame->WritePixels(height, stride, dataLen, (BYTE*)data); } if(SUCCEEDED(hr)) { hr = pFrame->Commit(); } if(SUCCEEDED(hr)) { hr = pEnc->Commit(); } SafeRelease(&pStream); SafeRelease(&pEnc); SafeRelease(&pFrame); SafeRelease(&pProp); return SUCCEEDED(hr); }
int xImageSize::getBitsPerPixel() { return getBitsPerPixel(fmt); }
int xImageSize::getBytePerPixel(ePIXEL_FORMAT fmt) { return getBitsPerPixel(fmt) / 8; }