void outSize(char* dName){ struct stat statbuf; stat(dName, &statbuf); DIR *dir_ptr; struct dirent *direntp; if(isDir(dName)) { printf ("%s is a directory.\n", dName); printf ("%s has %ld bytes.\n", dName, statbuf.st_size); if((dir_ptr = opendir( dName)) == NULL) fprintf(stderr, "Can not open %s\n", dName); else { while((direntp = readdir( dir_ptr)) != NULL && strcmp(dName, ".") != 0 && strcmp(dName, "..") != 0) outSize(direntp->d_name); closedir(dir_ptr); } } else { printf ("%s is a regular file.\n", dName); printf ("%s has %ld bytes.\n", dName, statbuf.st_size); } }
ComUInt32 LmParameter::actualOutDataSize(void *data) const { if (outVCLenIndSize_ == 0) return outSize(); else return vcDataSize((char*)data, outVCLenIndOffset_, outVCLenIndSize_); }
int main(){ auto pLogger = CB::Log::CLogger::GetInstance(); pLogger->AddStream(CB::IO::File::Open(L"main.log", CB::IO::File::AccessType::WriteOnly, CB::IO::File::OpenAction::AlwaysCreate).Cast<CB::IO::IStream>()); pLogger->AddStream(CB::IO::Console::Create().Cast<CB::IO::IStream>(), CB::Log::CTextFormatter::Create(CB::String::Encoding::ANSI).Cast<CB::Log::IEntryFormatter>()); pLogger->SetDebugMode(true); try{ auto pWinDriver = CB::Window::LoadDriver(L"MSWindowDriver"); auto pGraphicDriver = CB::Graphic::LoadDriver(L"OGLGraphicDriver"); { auto pWinManager = pWinDriver->CreateManager(); auto pGraphicManager = pGraphicDriver->CreateManager(pWinManager); CB::Math::CSize outSize(640, 480); auto pWindow = pWinManager->CreateWindow(L"GraphicTest", CB::Window::Style::Single, outSize); auto pGraphicAdapter = pGraphicManager->GetDefaultAdapter(); CB::Graphic::CDisplayMode dispMode(pWindow->GetSize(), 0, CB::Graphic::BufferFormat::B8G8R8X8); CB::Graphic::CDeviceDesc devDesc(pWindow, dispMode, CB::Graphic::BufferFormat::D24S8, false); CB::Collection::CList<CB::Graphic::FeatureLevel> featureLevels; featureLevels.Add(CB::Graphic::FeatureLevel::Level_1); auto pGraphicDevice = pGraphicAdapter->CreateDevice(pWindow, devDesc, featureLevels); pWindow->OnClose += CB::Signals::CFunc<const bool, CB::CRefPtr<CB::Window::IWindow>>(CloseEvent); pWindow->SetVisible(true); CB::Graphic::CDepthStencilStateDesc depthDesc; depthDesc.bDepthTestEnabled = true; depthDesc.uDepthFunction = CB::Graphic::CompareFunc::LessEqual; auto pDepthState = pGraphicDevice->CreateState(depthDesc); pGraphicDevice->SetState(pDepthState.Cast<CB::Graphic::IDeviceState>()); CB::Graphic::CRasterizerStateDesc rastDesc; rastDesc.uCullMode = CB::Graphic::CullMode::None; auto pRastState = pGraphicDevice->CreateState(rastDesc); pGraphicDevice->SetState(pRastState.Cast<CB::Graphic::IDeviceState>()); CB::Graphic::CBlendStateDesc blendDesc; blendDesc.ColorBlend.uDestOperand = CB::Graphic::BlendOption::OneMinusSourceAlpha; blendDesc.ColorBlend.uSourceOperand = CB::Graphic::BlendOption::SourceAlpha; blendDesc.ColorBlend.uOperation = CB::Graphic::BlendOperation::Add; blendDesc.AlphaBlend.uDestOperand = CB::Graphic::BlendOption::OneMinusSourceAlpha; blendDesc.AlphaBlend.uSourceOperand = CB::Graphic::BlendOption::SourceAlpha; blendDesc.AlphaBlend.uOperation = CB::Graphic::BlendOperation::Add; blendDesc.bEnabled[0] = true; auto pBlendState = pGraphicDevice->CreateState(blendDesc); pGraphicDevice->SetState(pBlendState.Cast<CB::Graphic::IDeviceState>()); auto pFontManager = CB::Font::CManager::Create(); auto pFontStream = CB::IO::File::Open(L"Assets/font.ttf").Cast<CB::IO::IStream>(); auto pFont = pFontManager->Load(pFontStream); pFont->SelectFace(0); pFont->SetSize(24); CB::Collection::CList<CB::Tools::CFontCharDesc> charDescs; CB::Tools::CFontTextureGenerator fontGen(pGraphicDevice); fontGen.MaxTextureSize.Set(512, 512); auto pTexture = fontGen.Generate(pFont, charDescs); CB::Tools::CTextMeshGenerator textGen(charDescs); CB::Tools::CMeshRawIVT textMesh; textGen.Generate(L"Marek M³ynarski!", textMesh); CB::Collection::CList<CB::Graphic::CVertexElement> vEls; vEls.Add(CB::Graphic::CVertexElement(0, L"vinput.vPosition", CB::Graphic::VertexType::Float, 3, 0)); vEls.Add(CB::Graphic::CVertexElement(1, L"vinput.vTexCoord", CB::Graphic::VertexType::Float, 2, 0)); GraphicTest::CShaderLoader shaders(pGraphicDevice, L"Shaders/TextureShader.cg"); auto pTextDecl = pGraphicDevice->CreateVertexDeclaration(shaders.pVertexShader, vEls); auto pTextVertexBuffer = pGraphicDevice->CreateBuffer(CB::Graphic::BufferType::Vertex, CB::Graphic::BufferUsage::Dynamic, CB::Graphic::BufferAccess::Write, textMesh.Vertices); auto pTextTCoordBuffer = pGraphicDevice->CreateBuffer(CB::Graphic::BufferType::Vertex, CB::Graphic::BufferUsage::Dynamic, CB::Graphic::BufferAccess::Write, textMesh.TexCoords); auto pTextIndexBuffer = pGraphicDevice->CreateBuffer(CB::Graphic::BufferType::Index, CB::Graphic::BufferUsage::Dynamic, CB::Graphic::BufferAccess::Write, textMesh.Indices); float32 fAspect = (float32)outSize.Width / (float32)outSize.Height; CB::Math::CMatrix mProj = CB::Math::CMatrix::GetPerspective(fAspect, 60.0f, 1.0f, 100.0f); CB::Math::CMatrix mView = CB::Math::CMatrix::GetTranslation(-4.0f, 0.0f, -3.4f); CB::Math::CMatrix mModel = CB::Math::CMatrix::GetIdentity(); shaders.pFragmentShader->SetSampler(L"texDiffuse", pTexture.Cast<CB::Graphic::IBaseTexture>()); pTexture->SetFilters(CB::Graphic::TextureFilter::Linear, CB::Graphic::TextureFilter::Linear, CB::Graphic::TextureFilter::Linear); pTexture->SetAnisotropy(8); //g_pTexture = texture.pTexture; while(g_bRun){ pGraphicDevice->Clear(1.0f, 1); pGraphicDevice->Clear(CB::Math::CColor(1.0f, 0.5f, 0.0f, 1.0f)); pGraphicDevice->BeginRender(); pGraphicDevice->SetShader(shaders.pVertexShader); pGraphicDevice->SetShader(shaders.pFragmentShader); static float32 fV = 0.0f; fV += 20 * g_Timer.GetTimeDelta(); mModel = CB::Math::CMatrix::GetRotation(CB::Math::AxisOrientation::AxisX, fV); shaders.pVertexShader->SetUniform(L"vinput.mProj", mProj); shaders.pVertexShader->SetUniform(L"vinput.mView", mView); shaders.pVertexShader->SetUniform(L"vinput.mModel", mModel); pGraphicDevice->SetVertexDeclaration(pTextDecl); pGraphicDevice->SetVertexBuffer(0, pTextVertexBuffer); pGraphicDevice->SetVertexBuffer(1, pTextTCoordBuffer); pGraphicDevice->SetIndexBuffer(pTextIndexBuffer); pGraphicDevice->RenderIndexed(textMesh.uNumberOfPolygons); pGraphicDevice->EndRender(); g_Timer.Update(); pWinManager->ProcessEvents(); float fFPS = 1.0f / (g_Timer.GetTimeDelta() == 0.0f ? 1.0f : g_Timer.GetTimeDelta()); uint32 uFPS = (uint32)fFPS; textMesh.Clear(); textGen.Generate(L"FPS: " + CB::String::ToString(uFPS), textMesh); pTextVertexBuffer->LoadData(textMesh.Vertices); pTextTCoordBuffer->LoadData(textMesh.TexCoords); pTextIndexBuffer->LoadData(textMesh.Indices); pGraphicDevice->Swap(); } g_pTexture.Release(); } } catch(CB::Exception::CException& Exception){ CB::Log::Write(Exception, CB::Log::LogLevel::Fatal); CB::Message::Show(Exception, CB::Message::Icon::Error); } return 0; }
int main(int argc, char* argv[]){ struct stat st_buf; outSize(argv[1]); }
static void setup_qt(QImage& image, png_structp png_ptr, png_infop info_ptr, QSize scaledSize, bool *doScaledRead, float screen_gamma=0.0, float file_gamma=0.0) { if (screen_gamma != 0.0 && file_gamma != 0.0) png_set_gamma(png_ptr, 1.0f / screen_gamma, file_gamma); png_uint_32 width; png_uint_32 height; int bit_depth; int color_type; png_bytep trans_alpha = 0; png_color_16p trans_color_p = 0; int num_trans; png_colorp palette = 0; int num_palette; int interlace_method; png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, &interlace_method, 0, 0); png_set_interlace_handling(png_ptr); if (color_type == PNG_COLOR_TYPE_GRAY) { // Black & White or 8-bit grayscale if (bit_depth == 1 && png_get_channels(png_ptr, info_ptr) == 1) { png_set_invert_mono(png_ptr); png_read_update_info(png_ptr, info_ptr); if (image.size() != QSize(width, height) || image.format() != QImage::Format_Mono) { image = QImage(width, height, QImage::Format_Mono); if (image.isNull()) return; } image.setColorCount(2); image.setColor(1, qRgb(0,0,0)); image.setColor(0, qRgb(255,255,255)); if (png_get_tRNS(png_ptr, info_ptr, &trans_alpha, &num_trans, &trans_color_p) && trans_color_p) { const int g = trans_color_p->gray; // the image has white in the first position of the color table, // black in the second. g is 0 for black, 1 for white. if (g == 0) image.setColor(1, qRgba(0, 0, 0, 0)); else if (g == 1) image.setColor(0, qRgba(255, 255, 255, 0)); } } else if (bit_depth == 16 && png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) { png_set_expand(png_ptr); png_set_strip_16(png_ptr); png_set_gray_to_rgb(png_ptr); if (image.size() != QSize(width, height) || image.format() != QImage::Format_ARGB32) { image = QImage(width, height, QImage::Format_ARGB32); if (image.isNull()) return; } if (QSysInfo::ByteOrder == QSysInfo::BigEndian) png_set_swap_alpha(png_ptr); png_read_update_info(png_ptr, info_ptr); } else if (bit_depth == 8 && !png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) { png_set_expand(png_ptr); if (image.size() != QSize(width, height) || image.format() != QImage::Format_Grayscale8) { image = QImage(width, height, QImage::Format_Grayscale8); if (image.isNull()) return; } png_read_update_info(png_ptr, info_ptr); } else { if (bit_depth == 16) png_set_strip_16(png_ptr); else if (bit_depth < 8) png_set_packing(png_ptr); int ncols = bit_depth < 8 ? 1 << bit_depth : 256; png_read_update_info(png_ptr, info_ptr); if (image.size() != QSize(width, height) || image.format() != QImage::Format_Indexed8) { image = QImage(width, height, QImage::Format_Indexed8); if (image.isNull()) return; } image.setColorCount(ncols); for (int i=0; i<ncols; i++) { int c = i*255/(ncols-1); image.setColor(i, qRgba(c,c,c,0xff)); } if (png_get_tRNS(png_ptr, info_ptr, &trans_alpha, &num_trans, &trans_color_p) && trans_color_p) { const int g = trans_color_p->gray; if (g < ncols) { image.setColor(g, 0); } } } } else if (color_type == PNG_COLOR_TYPE_PALETTE && png_get_PLTE(png_ptr, info_ptr, &palette, &num_palette) && num_palette <= 256) { // 1-bit and 8-bit color if (bit_depth != 1) png_set_packing(png_ptr); png_read_update_info(png_ptr, info_ptr); png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, 0, 0, 0); QImage::Format format = bit_depth == 1 ? QImage::Format_Mono : QImage::Format_Indexed8; if (image.size() != QSize(width, height) || image.format() != format) { image = QImage(width, height, format); if (image.isNull()) return; } png_get_PLTE(png_ptr, info_ptr, &palette, &num_palette); image.setColorCount(num_palette); int i = 0; if (png_get_tRNS(png_ptr, info_ptr, &trans_alpha, &num_trans, &trans_color_p) && trans_alpha) { while (i < num_trans) { image.setColor(i, qRgba( palette[i].red, palette[i].green, palette[i].blue, trans_alpha[i] ) ); i++; } } while (i < num_palette) { image.setColor(i, qRgba( palette[i].red, palette[i].green, palette[i].blue, 0xff ) ); i++; } } else { // 32-bit if (bit_depth == 16) png_set_strip_16(png_ptr); png_set_expand(png_ptr); if (color_type == PNG_COLOR_TYPE_GRAY_ALPHA) png_set_gray_to_rgb(png_ptr); QImage::Format format = QImage::Format_ARGB32; // Only add filler if no alpha, or we can get 5 channel data. if (!(color_type & PNG_COLOR_MASK_ALPHA) && !png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) { png_set_filler(png_ptr, 0xff, QSysInfo::ByteOrder == QSysInfo::BigEndian ? PNG_FILLER_BEFORE : PNG_FILLER_AFTER); // We want 4 bytes, but it isn't an alpha channel format = QImage::Format_RGB32; } QSize outSize(width,height); if (!scaledSize.isEmpty() && quint32(scaledSize.width()) <= width && quint32(scaledSize.height()) <= height && interlace_method == PNG_INTERLACE_NONE) { // Do inline downscaling outSize = scaledSize; if (doScaledRead) *doScaledRead = true; } if (image.size() != outSize || image.format() != format) { image = QImage(outSize, format); if (image.isNull()) return; } if (QSysInfo::ByteOrder == QSysInfo::BigEndian) png_set_swap_alpha(png_ptr); png_read_update_info(png_ptr, info_ptr); } // Qt==ARGB==Big(ARGB)==Little(BGRA) if (QSysInfo::ByteOrder == QSysInfo::LittleEndian) { png_set_bgr(png_ptr); } }