static int FormatConversionToPixelFormat(int id, bool Alpha, VSCore *core, const VSAPI *vsapi) { const VSFormat *f = vsapi->getFormatPreset(id, core); int npixfmt = GetNumPixFmts(); // Look for a suitable format without alpha first to not waste memory if (!Alpha) { for (int i = 0; i < npixfmt; i++) { const AVPixFmtDescriptor &desc = *av_pix_fmt_desc_get((AVPixelFormat)i); if (IsRealNativeEndianPlanar(desc) && !HasAlpha(desc) && GetColorFamily(desc) == f->colorFamily && desc.comp[0].depth_minus1 + 1 == f->bitsPerSample && desc.log2_chroma_w == f->subSamplingW && desc.log2_chroma_h == f->subSamplingH) return i; } } // Try all remaining formats for (int i = 0; i < npixfmt; i++) { const AVPixFmtDescriptor &desc = *av_pix_fmt_desc_get((AVPixelFormat)i); if (IsRealNativeEndianPlanar(desc) && HasAlpha(desc) && GetColorFamily(desc) == f->colorFamily && desc.comp[0].depth_minus1 + 1 == f->bitsPerSample && desc.log2_chroma_w == f->subSamplingW && desc.log2_chroma_h == f->subSamplingH) return i; } return PIX_FMT_NONE; }
void ImageLoader::loadCubemap(std::vector<asl::Ptr<ReadableBlockHandle> > & theBlocks, unsigned theDepth) { for (unsigned i = 0; i < 6; ++i) { string myDescription = string("Face")+as_string(i)+"_"+_myFilename; ImageLoader myFaceBmp(theBlocks[i], myDescription, _myTextureManager.lock()); myFaceBmp.ensurePowerOfTwo(IMAGE_RESIZE_SCALE, theDepth); if (i == 0) { // Setup current image to have 6 times the height of one face Create(myFaceBmp.GetWidth(), myFaceBmp.GetHeight() * 6 * theDepth, myFaceBmp.GetPixelFormat(), 0, 0, myFaceBmp.GetResolution()); } // Check if new face is compatible with other faces if (myFaceBmp.GetBitsPerPixel() != GetBitsPerPixel()) { throw ImageLoaderException(string("The cubemap-face: ") + myDescription + " has " + as_string(myFaceBmp.GetBitsPerPixel()) + " but should have " + as_string(GetBitsPerPixel()), PLUS_FILE_LINE); } if (myFaceBmp.HasAlpha() != HasAlpha()) { throw ImageLoaderException(string("The cubemap-face: ") + myDescription + " alpha-flag: " + as_string(myFaceBmp.HasAlpha()) + " but should be: " + as_string(HasAlpha()), PLUS_FILE_LINE); } if (myFaceBmp.IsGreyscale() != IsGreyscale()) { throw ImageLoaderException(string("The cubemap-face: ") + myDescription + " greyscale-flag: " + as_string(myFaceBmp.IsGreyscale()) + " but should be: " + as_string(IsGreyscale()), PLUS_FILE_LINE); } int myTargetWidth = GetWidth(); int myTargetHeight = GetHeight() / 6 / theDepth; if (myFaceBmp.GetWidth() != myTargetWidth || myFaceBmp.GetHeight() != myTargetHeight) { AC_WARNING << "Resizing bitmap " << myDescription << " to " << myTargetWidth << "x" << myTargetHeight << "."; myFaceBmp.ApplyFilter(PLFilterResizeBilinear(myTargetWidth, myTargetHeight)); } // Copy face into destination bitmap PLBYTE ** mySrcLines = myFaceBmp.GetLineArray(); PLBYTE ** myDstLines = GetLineArray(); unsigned int myFaceHeight = myFaceBmp.GetHeight(); long myLineSize = GetBytesPerLine(); for (unsigned int y = 0; y < myFaceHeight; ++y) { memcpy(myDstLines[y + myFaceHeight * i], mySrcLines[y], myLineSize); } } }
/////////////////////////////////////////////////////////////////////////////////////// // private helper for IconToPARGB32Bitmap BOOL ConvertBufferToPARGB32(HPAINTBUFFER hPaintBuffer, HDC hdc, HICON hicon, SIZE& sizIcon) { RGBQUAD *prgbQuad = NULL; int cxRow = 0; if (CThemed::GetBufferedPaintBits(hPaintBuffer, &prgbQuad, &cxRow)) { ARGB *pargb = reinterpret_cast<ARGB *>(prgbQuad); if (!HasAlpha(pargb, sizIcon, cxRow)) { ICONINFO info = { 0 }; if (GetIconInfo(hicon, &info)) { if (info.hbmMask) { ConvertToPARGB32(hdc, pargb, info.hbmMask, sizIcon, cxRow); } // cleanup VERIFY(DeleteObject(info.hbmColor)); VERIFY(DeleteObject(info.hbmMask)); } } return TRUE; } return FALSE; }
HRESULT CIconMenu::ConvertBufferToPARGB32(HPAINTBUFFER hPaintBuffer, HDC hdc, HICON hicon, SIZE& sizIcon) { RGBQUAD *prgbQuad; int cxRow; HRESULT hr = pfnGetBufferedPaintBits(hPaintBuffer, &prgbQuad, &cxRow); if (SUCCEEDED(hr)) { Gdiplus::ARGB *pargb = reinterpret_cast<Gdiplus::ARGB *>(prgbQuad); if (!HasAlpha(pargb, sizIcon, cxRow)) { ICONINFO info; if (GetIconInfo(hicon, &info)) { if (info.hbmMask) { hr = ConvertToPARGB32(hdc, pargb, info.hbmMask, sizIcon, cxRow); } DeleteObject(info.hbmColor); DeleteObject(info.hbmMask); } } } return hr; }
HRESULT IconBitmapUtils::ConvertBufferToPARGB32(HPAINTBUFFER hPaintBuffer, HDC hdc, HICON hicon, SIZE& sizIcon) { RGBQUAD *prgbQuad; int cxRow; HRESULT hr = GetBufferedPaintBits(hPaintBuffer, &prgbQuad, &cxRow); if (FAILED(hr)) return hr; Gdiplus::ARGB *pargb = reinterpret_cast<Gdiplus::ARGB *>(prgbQuad); if (HasAlpha(pargb, sizIcon, cxRow)) return S_OK; ICONINFO info; if (!GetIconInfo(hicon, &info)) return S_OK; SCOPE_EXIT { DeleteObject(info.hbmColor); DeleteObject(info.hbmMask); }; if (info.hbmMask) return ConvertToPARGB32(hdc, pargb, info.hbmMask, sizIcon, cxRow); return S_OK; }
void SharedSurface_EGLImage::Fence() { MutexAutoLock lock(mMutex); mGL->MakeCurrent(); if (!mPipeActive) { MOZ_ASSERT(!mSync); MOZ_ASSERT(!mPipeComplete); if (!mPipeFailed) { if (!CreateTexturePipe(mEGL, mGL, mFormats, Size(), &mProdTexForPipe, &mImage)) { mPipeFailed = true; } } if (!mPixels) { SurfaceFormat format = HasAlpha() ? SurfaceFormat::B8G8R8A8 : SurfaceFormat::B8G8R8X8; mPixels = Factory::CreateDataSourceSurface(Size(), format); } nsRefPtr<gfxImageSurface> wrappedData = new gfxImageSurface(mPixels->GetData(), ThebesIntSize(mPixels->GetSize()), mPixels->Stride(), SurfaceFormatToImageFormat(mPixels->GetFormat())); ReadScreenIntoImageSurface(mGL, wrappedData); mPixels->MarkDirty(); return; } MOZ_ASSERT(mPipeActive); MOZ_ASSERT(mCurConsGL); if (mEGL->IsExtensionSupported(GLLibraryEGL::KHR_fence_sync) && mGL->IsExtensionSupported(GLContext::OES_EGL_sync)) { if (mSync) { MOZ_ALWAYS_TRUE( mEGL->fDestroySync(Display(), mSync) ); mSync = 0; } mSync = mEGL->fCreateSync(Display(), LOCAL_EGL_SYNC_FENCE, nullptr); if (mSync) { mGL->fFlush(); return; } } MOZ_ASSERT(!mSync); mGL->fFinish(); }
void Texture::BindTexture( int slotNum ) { glActiveTexture( slotNum ); glBindTexture( GL_TEXTURE_2D, m_textureID ); if( HasAlpha() ) { glEnable( GL_BLEND ); glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); } glEnable( GL_TEXTURE_2D ); }
void SharedSurface_EGLImage::Fence() { MutexAutoLock lock(mMutex); mGL->MakeCurrent(); if (!mPipeActive) { MOZ_ASSERT(!mSync); MOZ_ASSERT(!mPipeComplete); if (!mPipeFailed) { if (!CreateTexturePipe(mEGL, mGL, mFormats, Size(), &mProdTexForPipe, &mImage)) { mPipeFailed = true; } } if (!mPixels) { gfxASurface::gfxImageFormat format = HasAlpha() ? gfxASurface::ImageFormatARGB32 : gfxASurface::ImageFormatRGB24; mPixels = new gfxImageSurface(Size(), format); } mPixels->Flush(); mGL->ReadScreenIntoImageSurface(mPixels); mPixels->MarkDirty(); return; } MOZ_ASSERT(mPipeActive); MOZ_ASSERT(mCurConsGL); if (mEGL->IsExtensionSupported(GLLibraryEGL::KHR_fence_sync) && mGL->IsExtensionSupported(GLContext::OES_EGL_sync)) { if (mSync) { MOZ_ALWAYS_TRUE( mEGL->fDestroySync(Display(), mSync) ); mSync = 0; } mSync = mEGL->fCreateSync(Display(), LOCAL_EGL_SYNC_FENCE, nullptr); if (mSync) { mGL->fFlush(); return; } } MOZ_ASSERT(!mSync); mGL->fFinish(); }
void Texture::Load( const IFileIO* fileIO ) { IFileReader* asset = fileIO->ReadAsset( cFileName ); Image* image = Image::LoadPNG( asset ); mTextureId = GenerateGLTexture( image ); mWidth = image->cWidth; mHeight = image->cHeight; mHasAlpha = HasAlpha( image->cColorFormat ); delete image; delete asset; }
void ImageLoader::removeUnusedAlpha() { if (!_isI60 && GetBitsPerPixel() == 32 && !HasAlpha()) { // Compress unused fourth channel AC_DEBUG << "ImageLoader removing unused fourth channel"; unsigned myHeight = GetHeight(); unsigned myWidth = GetWidth(); //unsigned myLineStride = GetBytesPerLine(); asl::Ptr<Block> myDestinationBlock = asl::Ptr<Block>(new Block()); myDestinationBlock->resize(myHeight * myWidth * 3); unsigned char ** myLineArray = GetLineArray(); unsigned char * myDestination = myDestinationBlock->begin(); for (unsigned i = 0; i < myHeight; ++i) { unsigned char * mySource = *myLineArray; for (unsigned j = 0; j < myWidth; ++j) { myDestination[0] = mySource[0]; myDestination[1] = mySource[1]; myDestination[2] = mySource[2]; mySource += 4; myDestination += 3; } myLineArray++; } // Update internal representation switch (_myEncoding) { case RGBA : _myEncoding = RGB; break; case BGRA : _myEncoding = BGR; break; default: throw ImageLoaderException("Unsupported pixel encoding", PLUS_FILE_LINE); } _myData = myDestinationBlock; PLPixelFormat myPixelFormat; mapPixelEncodingToFormat(_myEncoding, myPixelFormat); SetBmpInfo(GetSize(), GetResolution(), myPixelFormat); updateLineArray(); } }
/*++ Routine Name: CColorChannelData::GetChannelCountNoAlpha Routine Description: Retrieves the number of channels less the alpha channel if present Arguments: pcChannels - Pointer to a variable that recieves the count of non-alpha channels Return Value: HRESULT S_OK - On success E_* - On error --*/ HRESULT CColorChannelData::GetChannelCountNoAlpha( _Out_ DWORD* pcChannels ) { HRESULT hr = S_OK; if (SUCCEEDED(hr = GetChannelCount(pcChannels))) { if (HasAlpha()) { (*pcChannels)--; } } ERR_ON_HR(hr); return hr; }
void CWsWindow::SendState(MWsWindowTreeObserver& aWindowTreeObserver) const { aWindowTreeObserver.NodeCreated(*this, ParentNode()); if(iFlags & EFlagActive) { aWindowTreeObserver.NodeExtentChanged(*this, FullRect()); aWindowTreeObserver.NodeActivated(*this); } if(!IsVisible()) { aWindowTreeObserver.FlagChanged(*this, MWsWindowTreeObserver::EVisible, EFalse); } if(IsTrackingVisibleRegion()) { MWsWindowVisibilityNotifier* windowVisibilityNotifier = Screen()->WindowVisibilityNotifier(); if(windowVisibilityNotifier) windowVisibilityNotifier->RegisterWindow(*this); } if(HasAlpha()) { aWindowTreeObserver.FlagChanged(*this, MWsWindowTreeObserver::EAlphaChannelTransparencyEnabled, ETrue); } if(IsNonFading()) { aWindowTreeObserver.FlagChanged(*this, MWsWindowTreeObserver::ENonFading, ETrue); } if(IsTopClientWindow() && (iFlags&EFlagScreenDeviceInvalid) ) { aWindowTreeObserver.FlagChanged(*this, MWsWindowTreeObserver::EScreenDeviceValid, EFalse); } if(iAnimList) iAnimList->SendState(aWindowTreeObserver); CWsWindowBase::SendState(aWindowTreeObserver); }
void ConvertBufferToPARGB32(HANDLE hPaintBuffer, HDC hdc, HICON hIcon, SIZE& sizIcon) { RGBQUAD *prgbQuad; int cxRow; HRESULT hr = getBufferedPaintBits(hPaintBuffer, &prgbQuad, &cxRow); if (SUCCEEDED(hr)) { ARGB *pargb = (ARGB *)prgbQuad; if (!HasAlpha(pargb, sizIcon, cxRow)) { ICONINFO info; if (GetIconInfo(hIcon, &info)) { if (info.hbmMask) ConvertToPARGB32(hdc, pargb, info.hbmMask, sizIcon, cxRow); DeleteObject(info.hbmColor); DeleteObject(info.hbmMask); } } } }
//******************************************** // AddAlphaLayer //******************************************** int Texture::AddAlphaLayer(unsigned char alpha) // 0 - 255 { // Check if(!IsValid()) return 0; // Has soon alpha if(HasAlpha()) return SetAlphaLayer(alpha); // Alloc memory unsigned char *pData = new unsigned char[4*m_Width*m_Height]; if(pData == NULL) { //TRACE("Texture::AddAlphaLayer : insufficiant memory"); return 0; } // Fill new data int size = m_Width * m_Height; int BytePerPixel = m_Depth / 8; for(int i=0;i<size;i++) { pData[4*i+0] = m_pData[BytePerPixel*i+0]; pData[4*i+1] = m_pData[BytePerPixel*i+1]; pData[4*i+2] = m_pData[BytePerPixel*i+2]; pData[4*i+3] = alpha; } // Set new depth m_Depth = 32; // Replace datas delete [] m_pData; m_pData = pData; return 1; }
//------------------------------------------------------------------------------------- // Converts to a premultiplied alpha version of the texture //------------------------------------------------------------------------------------- _Use_decl_annotations_ HRESULT PremultiplyAlpha( const Image& srcImage, ScratchImage& image ) { if ( !srcImage.pixels ) return E_POINTER; if ( IsCompressed(srcImage.format) || IsVideo(srcImage.format) || IsTypeless(srcImage.format) || !HasAlpha(srcImage.format) ) return HRESULT_FROM_WIN32( ERROR_NOT_SUPPORTED ); #ifdef _M_X64 if ( (srcImage.width > 0xFFFFFFFF) || (srcImage.height > 0xFFFFFFFF) ) return E_INVALIDARG; #endif HRESULT hr = image.Initialize2D( srcImage.format, srcImage.width, srcImage.height, 1, 1 ); if ( FAILED(hr) ) return hr; const Image *rimage = image.GetImage( 0, 0, 0 ); if ( !rimage ) { image.Release(); return E_POINTER; } hr = _PremultiplyAlpha( srcImage, *rimage ); if ( FAILED(hr) ) { image.Release(); return hr; } return S_OK; }
void VSVideoSource::InitOutputFormat(int ResizeToWidth, int ResizeToHeight, const char *ResizerName, int ConvertToFormat, const VSAPI *vsapi, VSCore *core) { char ErrorMsg[1024]; FFMS_ErrorInfo E; E.Buffer = ErrorMsg; E.BufferSize = sizeof(ErrorMsg); const FFMS_Frame *F = FFMS_GetFrame(V, 0, &E); if (!F) { std::string buf = "Source: "; buf += E.Buffer; throw std::runtime_error(buf); } std::vector<int> TargetFormats; int npixfmt = GetNumPixFmts(); for (int i = 0; i < npixfmt; i++) if (IsRealNativeEndianPlanar(*av_pix_fmt_desc_get((AVPixelFormat)i))) TargetFormats.push_back(i); TargetFormats.push_back(PIX_FMT_NONE); int TargetPixelFormat = PIX_FMT_NONE; if (ConvertToFormat != pfNone) { TargetPixelFormat = FormatConversionToPixelFormat(ConvertToFormat, OutputAlpha, core, vsapi); if (TargetPixelFormat == PIX_FMT_NONE) throw std::runtime_error(std::string("Source: Invalid output colorspace specified")); TargetFormats.clear(); TargetFormats.push_back(TargetPixelFormat); TargetFormats.push_back(-1); } if (ResizeToWidth <= 0) ResizeToWidth = F->EncodedWidth; if (ResizeToHeight <= 0) ResizeToHeight = F->EncodedHeight; int Resizer = ResizerNameToSWSResizer(ResizerName); if (Resizer == 0) throw std::runtime_error(std::string("Source: Invalid resizer name specified")); if (FFMS_SetOutputFormatV2(V, &TargetFormats[0], ResizeToWidth, ResizeToHeight, Resizer, &E)) throw std::runtime_error(std::string("Source: No suitable output format found")); F = FFMS_GetFrame(V, 0, &E); TargetFormats.clear(); TargetFormats.push_back(F->ConvertedPixelFormat); TargetFormats.push_back(-1); // This trick is required to first get the "best" default format and then set only that format as the output if (FFMS_SetOutputFormatV2(V, TargetFormats.data(), ResizeToWidth, ResizeToHeight, Resizer, &E)) throw std::runtime_error(std::string("Source: No suitable output format found")); F = FFMS_GetFrame(V, 0, &E); // Don't output alpha if the clip doesn't have it if (!HasAlpha(*av_pix_fmt_desc_get((AVPixelFormat)F->ConvertedPixelFormat))) OutputAlpha = false; VI[0].format = FormatConversionToVS(F->ConvertedPixelFormat, core, vsapi); if (!VI[0].format) throw std::runtime_error(std::string("Source: No suitable output format found")); VI[0].width = F->ScaledWidth; VI[0].height = F->ScaledHeight; // fixme? Crop to obey sane even width/height requirements }
int ReadPictureWithWIC(const char* const filename, WebPPicture* const pic, int keep_alpha, Metadata* const metadata) { // From Microsoft SDK 6.0a -- ks.h // Define a local copy to avoid link errors under mingw. WEBP_DEFINE_GUID(GUID_NULL_, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); static const WICFormatImporter kAlphaFormatImporters[] = { { &GUID_WICPixelFormat32bppBGRA_, 4, WebPPictureImportBGRA }, { &GUID_WICPixelFormat32bppRGBA_, 4, WebPPictureImportRGBA }, { NULL, 0, NULL }, }; static const WICFormatImporter kNonAlphaFormatImporters[] = { { &GUID_WICPixelFormat24bppBGR_, 3, WebPPictureImportBGR }, { &GUID_WICPixelFormat24bppRGB_, 3, WebPPictureImportRGB }, { NULL, 0, NULL }, }; HRESULT hr = S_OK; IWICBitmapFrameDecode* frame = NULL; IWICFormatConverter* converter = NULL; IWICImagingFactory* factory = NULL; IWICBitmapDecoder* decoder = NULL; IStream* stream = NULL; UINT frame_count = 0; UINT width = 0, height = 0; BYTE* rgb = NULL; WICPixelFormatGUID src_pixel_format = GUID_WICPixelFormatUndefined; const WICFormatImporter* importer = NULL; GUID src_container_format = GUID_NULL_; static const GUID* kAlphaContainers[] = { &GUID_ContainerFormatBmp, &GUID_ContainerFormatPng, &GUID_ContainerFormatTiff, NULL }; int has_alpha = 0; int64_t stride; IFS(CoInitialize(NULL)); IFS(CoCreateInstance(MAKE_REFGUID(CLSID_WICImagingFactory), NULL, CLSCTX_INPROC_SERVER, MAKE_REFGUID(IID_IWICImagingFactory), (LPVOID*)&factory)); if (hr == REGDB_E_CLASSNOTREG) { fprintf(stderr, "Couldn't access Windows Imaging Component (are you running " "Windows XP SP3 or newer?). Most formats not available. " "Use -s for the available YUV input.\n"); } // Prepare for image decoding. IFS(OpenInputStream(filename, &stream)); IFS(IWICImagingFactory_CreateDecoderFromStream( factory, stream, NULL, WICDecodeMetadataCacheOnDemand, &decoder)); IFS(IWICBitmapDecoder_GetFrameCount(decoder, &frame_count)); if (SUCCEEDED(hr) && frame_count == 0) { fprintf(stderr, "No frame found in input file.\n"); hr = E_FAIL; } IFS(IWICBitmapDecoder_GetFrame(decoder, 0, &frame)); IFS(IWICBitmapFrameDecode_GetPixelFormat(frame, &src_pixel_format)); IFS(IWICBitmapDecoder_GetContainerFormat(decoder, &src_container_format)); if (SUCCEEDED(hr) && keep_alpha) { const GUID** guid; for (guid = kAlphaContainers; *guid != NULL; ++guid) { if (IsEqualGUID(MAKE_REFGUID(src_container_format), MAKE_REFGUID(**guid))) { has_alpha = HasAlpha(factory, decoder, frame, src_pixel_format); break; } } } // Prepare for pixel format conversion (if necessary). IFS(IWICImagingFactory_CreateFormatConverter(factory, &converter)); for (importer = has_alpha ? kAlphaFormatImporters : kNonAlphaFormatImporters; hr == S_OK && importer->import != NULL; ++importer) { BOOL can_convert; const HRESULT cchr = IWICFormatConverter_CanConvert( converter, MAKE_REFGUID(src_pixel_format), MAKE_REFGUID(*importer->pixel_format), &can_convert); if (SUCCEEDED(cchr) && can_convert) break; } if (importer->import == NULL) hr = E_FAIL; IFS(IWICFormatConverter_Initialize(converter, (IWICBitmapSource*)frame, importer->pixel_format, WICBitmapDitherTypeNone, NULL, 0.0, WICBitmapPaletteTypeCustom)); // Decode. IFS(IWICFormatConverter_GetSize(converter, &width, &height)); stride = (int64_t)importer->bytes_per_pixel * width * sizeof(*rgb); if (stride != (int)stride || !ImgIoUtilCheckSizeArgumentsOverflow(stride, height)) { hr = E_FAIL; } if (SUCCEEDED(hr)) { rgb = (BYTE*)malloc((size_t)stride * height); if (rgb == NULL) hr = E_OUTOFMEMORY; } IFS(IWICFormatConverter_CopyPixels(converter, NULL, (UINT)stride, (UINT)stride * height, rgb)); // WebP conversion. if (SUCCEEDED(hr)) { int ok; pic->width = width; pic->height = height; pic->use_argb = 1; // For WIC, we always force to argb ok = importer->import(pic, rgb, (int)stride); if (!ok) hr = E_FAIL; } if (SUCCEEDED(hr)) { if (metadata != NULL) { hr = ExtractMetadata(factory, frame, metadata); if (FAILED(hr)) { fprintf(stderr, "Error extracting image metadata using WIC!\n"); } } } // Cleanup. if (converter != NULL) IUnknown_Release(converter); if (frame != NULL) IUnknown_Release(frame); if (decoder != NULL) IUnknown_Release(decoder); if (factory != NULL) IUnknown_Release(factory); if (stream != NULL) IUnknown_Release(stream); free(rgb); return SUCCEEDED(hr); }
void STextureParams::FillProp(LPCSTR base_name, PropItemVec& items, PropValue::TOnChange on_type_change) { OnTypeChangeEvent = on_type_change; PropValue* P = PHelper().CreateToken32 (items, "Type", (u32*)&type, ttype_token); P->OnChangeEvent.bind(this,&STextureParams::OnTypeChange); PHelper().CreateCaption (items, "Source\\Width", shared_str().sprintf("%d",width)); PHelper().CreateCaption (items, "Source\\Height", shared_str().sprintf("%d",height)); PHelper().CreateCaption (items, "Source\\Alpha", HasAlpha ()?"present":"absent"); switch (type){ case ttImage: case ttCubeMap: PHelper().CreateToken32 (items, "Format", (u32*)&fmt, tfmt_token); PHelper().CreateFlag32 (items, "MipMaps\\Enabled", &flags, flGenerateMipMaps); PHelper().CreateToken32 (items, "MipMaps\\Filter", (u32*)&mip_filter, tparam_token); P = PHelper().CreateToken32 (items, "Bump\\Mode", (u32*)&bump_mode, tbmode_token); P->OnChangeEvent.bind(this,&STextureParams::OnTypeChange); if (tbmUse==bump_mode){ AnsiString path; path = base_name; PHelper().CreateChoose (items, "Bump\\Texture", &bump_name, smTexture, path.c_str()); } PHelper().CreateFlag32 (items, "Details\\Use As Diffuse", &flags, flDiffuseDetail); PHelper().CreateFlag32 (items, "Details\\Use As Bump (R2)",&flags, flBumpDetail); PHelper().CreateChoose (items, "Details\\Texture", &detail_name, smTexture); PHelper().CreateFloat (items, "Details\\Scale", &detail_scale, 0.1f,10000.f,0.1f,2); PHelper().CreateToken32 (items, "Material\\Base", (u32*)&material, tmtl_token); PHelper().CreateFloat (items, "Material\\Weight", &material_weight ); // PHelper().CreateFlag32 (items, "Flags\\Binary Alpha", &flags, flBinaryAlpha); PHelper().CreateFlag32 (items, "Flags\\Dither", &flags, flDitherColor); PHelper().CreateFlag32 (items, "Flags\\Dither Each MIP", &flags, flDitherEachMIPLevel); PHelper().CreateFlag32 (items, "Flags\\Implicit Lighted", &flags, flImplicitLighted); PHelper().CreateFlag32 (items, "Fade\\Enable Color", &flags, flFadeToColor); PHelper().CreateFlag32 (items, "Fade\\Enabled Alpha", &flags, flFadeToAlpha); PHelper().CreateU8 (items, "Fade\\Delay 'n' MIP", &fade_delay, 0,255); PHelper().CreateU32 (items, "Fade\\% of color to fade in",&fade_amount, 0,100,0); PHelper().CreateColor (items, "Fade\\Color", &fade_color ); PHelper().CreateU8 (items, "Fade\\Alpha", ((u8*)&fade_color)+3,0,255); PHelper().CreateFlag32 (items, "Border\\Enabled Color", &flags, flColorBorder); PHelper().CreateFlag32 (items, "Border\\Enabled Alpha", &flags, flAlphaBorder); PHelper().CreateColor (items, "Border\\Color", &border_color ); break; case ttBumpMap: PHelper().CreateChoose (items, "Bump\\Special NormalMap", &ext_normal_map_name,smTexture,base_name); PHelper().CreateFloat (items, "Bump\\Virtual Height (m)", &bump_virtual_height, 0.f, 0.1f, 0.001f, 3); break; case ttNormalMap: P = PHelper().CreateToken32 (items, "Format", (u32*)&fmt, tfmt_token); P->Owner()->Enable(false); PHelper().CreateFlag32 (items, "MipMaps\\Enabled", &flags, flGenerateMipMaps); PHelper().CreateToken32 (items, "MipMaps\\Filter", (u32*)&mip_filter, tparam_token); break; case ttTerrain: P = PHelper().CreateToken32 (items, "Format", (u32*)&fmt, tfmt_token); P->Owner()->Enable(false); PHelper().CreateFlag32 (items, "Details\\Use As Diffuse", &flags, flDiffuseDetail); PHelper().CreateFlag32 (items, "Details\\Use As Bump (R2)",&flags, flBumpDetail); PHelper().CreateChoose (items, "Details\\Texture", &detail_name, smTexture); PHelper().CreateFloat (items, "Details\\Scale", &detail_scale, 0.1f,10000.f,0.1f,2); PHelper().CreateToken32 (items, "Material\\Base", (u32*)&material, tmtl_token); PHelper().CreateFloat (items, "Material\\Weight", &material_weight ); P = PHelper().CreateFlag32 (items, "Flags\\Implicit Lighted", &flags, flImplicitLighted); P->Owner()->Enable(false); break; } }
//------------------------------------------------------------------------------------- // Converts to a premultiplied alpha version of the texture (complex) //------------------------------------------------------------------------------------- _Use_decl_annotations_ HRESULT PremultiplyAlpha( const Image* srcImages, size_t nimages, const TexMetadata& metadata, ScratchImage& result ) { if ( !srcImages || !nimages ) return E_INVALIDARG; if ( IsCompressed(metadata.format) || IsVideo(metadata.format) || IsTypeless(metadata.format) || !HasAlpha(metadata.format) ) return HRESULT_FROM_WIN32( ERROR_NOT_SUPPORTED ); #ifdef _M_X64 if ( (metadata.width > 0xFFFFFFFF) || (metadata.height > 0xFFFFFFFF) ) return E_INVALIDARG; #endif if ( metadata.IsPMAlpha() ) { // Already premultiplied return E_FAIL; } TexMetadata mdata2 = metadata; mdata2.SetAlphaMode(TEX_ALPHA_MODE_PREMULTIPLIED); HRESULT hr = result.Initialize( mdata2 ); if ( FAILED(hr) ) return hr; if ( nimages != result.GetImageCount() ) { result.Release(); return E_FAIL; } const Image* dest = result.GetImages(); if ( !dest ) { result.Release(); return E_POINTER; } for( size_t index=0; index < nimages; ++index ) { const Image& src = srcImages[ index ]; if ( src.format != metadata.format ) { result.Release(); return E_FAIL; } #ifdef _M_X64 if ( (src.width > 0xFFFFFFFF) || (src.height > 0xFFFFFFFF) ) return E_FAIL; #endif const Image& dst = dest[ index ]; assert( dst.format == metadata.format ); if ( src.width != dst.width || src.height != dst.height ) { result.Release(); return E_FAIL; } hr = _PremultiplyAlpha( src, dst ); if ( FAILED(hr) ) { result.Release(); return hr; } } return S_OK; }