StFormatEnum st::formatFromRatio(const GLfloat theRatio) { if(stAreEqual(theRatio, st::videoRatio::TV_SIDEBYSIDE, 0.18f) || stAreEqual(theRatio, st::videoRatio::WIDE_SIDEBYSIDE, 0.18f) || stAreEqual(theRatio, st::videoRatio::USERDEF_SIDEBYSIDE, 0.18f)) { return ST_V_SRC_SIDE_BY_SIDE; } return ST_V_SRC_MONO; }
void StGLMenuProgram::use(StGLContext& theCtx, const GLfloat theDispX) { StGLProgram::use(theCtx); if(!stAreEqual(myDispX, theDispX, 0.0001f)) { myDispX = theDispX; theCtx.core20fwd->glUniform4fv(uniDispLoc, 1, StGLVec4(theDispX, 0.0f, 0.0f, 0.0f)); } }
char* StPlayList::parseM3UIter(char* theIter, StFolder* theFolder, StString& theTitle) { if(*theIter == '\0') { return NULL; } char* aNextLine = nextLine(theIter); if(aNextLine > theIter + 1) { // replace LF or CRLF with '\0' *(aNextLine - 1) = '\0'; char* aTail = aNextLine - 2; if(*(aNextLine - 2) == '\x0D') { *(aNextLine - 2) = '\0'; --aTail; } // skip trailing spaces for(; *aTail == ' ' && aTail >= theIter; --aTail) { *aTail = '\0'; } } if(*theIter == '\0') { return aNextLine; // skip empty lines } if(*theIter != '#') { StString anItemPath = theIter; StFolder* aFolder = theFolder != NULL && StFileNode::isRelativePath(anItemPath) ? theFolder : &myFoldersRoot; StFileNode* aFileNode = new StFileNode(anItemPath, aFolder); aFolder->add(aFileNode); StPlayItem* anItem = new StPlayItem(aFileNode, myDefStParams); anItem->setTitle(theTitle); addPlayItem(anItem); theTitle = ""; } else if(stAreEqual(theIter, "#EXTINF:", 8)) { theIter += 8; for(; *theIter != '\0'; ++theIter) { if(*theIter == ',') { for(; *theIter == ' '; ++theIter) { // skip spaces in the beginning } theTitle = ++theIter; break; } } } return aNextLine; }
void StGLMenuProgram::use(StGLContext& theCtx, const StGLVec4& theColor, const GLfloat theOpacityValue, const GLfloat theDispX) { StGLProgram::use(theCtx); theCtx.core20fwd->glUniform4fv(uniColorLoc, 1, StGLVec4(theColor.rgb(), theColor.a() * theOpacityValue)); if(!stAreEqual(myDispX, theDispX, 0.0001f)) { myDispX = theDispX; theCtx.core20fwd->glUniform4fv(uniDispLoc, 1, StGLVec4(theDispX, 0.0f, 0.0f, 0.0f)); } }
void StGLRootWidget::setScale(const GLfloat theScale, const ScaleAdjust theScaleAdjust) { GLfloat aScale = theScale; switch(theScaleAdjust) { case ScaleAdjust_Small: aScale *= 0.8f; break; case ScaleAdjust_Big: aScale *= 1.2f; break; default: case ScaleAdjust_Normal: break; } if(stAreEqual(myScaleGUI, aScale, 0.001f)) { return; } myScaleGUI = aScale; myResolution = (unsigned int )(72.0f * aScale + 0.1f); myGlFontMgr->setResolution(myResolution); myMenuIconSize = scaleIcon(16); myClickThreshold = scale(3); setupTextures(); }
StHandle<StJpegParser::Image> StJpegParser::parseImage(const int theImgCount, const int theDepth, unsigned char* theDataStart, const bool theToFindSOI) { // check out of bounds if(theDataStart == NULL) { return StHandle<StJpegParser::Image>(); } unsigned char* aData = theDataStart; const unsigned char* aDataEnd = myBuffer + myLength; // search image beginning if(theToFindSOI) { ++aData; for(; aData < aDataEnd; ++aData) { if(aData[-1] == 0xFF && aData[0] == M_SOI) { --aData; break; } } } // check out of bounds if((aData + 2) > aDataEnd) { return StHandle<StJpegParser::Image>(); } // check the jpeg identifier if(aData[0] != 0xFF || aData[1] != M_SOI) { ST_DEBUG_LOG("StJpegParser, no SOI at position " + size_t(aData - myBuffer) + " / " + myLength); return StHandle<StJpegParser::Image>(); } aData += 2; // skip already read bytes // parse the data StHandle<StJpegParser::Image> anImg = new StJpegParser::Image(); anImg->Data = aData - 2; for(;;) { // search for the next marker in the file ++aData; // one byte forward size_t aSkippedBytes = 0; unsigned char aMarker = 0; for(; aData < aDataEnd; ++aSkippedBytes, ++aData) { aMarker = aData[0]; if(aData[-1] == 0xFF && aMarker != 0xFF && aMarker != 0x00) { ++aData; // skip marker id byte break; } } //ST_DEBUG_LOG(" #" + theImgCount + "." + theDepth + " [" + markerString(aMarker) + "] at position " + size_t(aData - myBuffer) + " / " + myLength); /// if(aMarker == M_EOI) { //ST_DEBUG_LOG("Jpeg, EOI at position " + size_t(aData - myBuffer) + " / " + myLength); anImg->Length = size_t(aData - anImg->Data); return anImg; } else if(aMarker == M_SOI) { // here the subimage (thumbnail)... //ST_DEBUG_LOG("Jpeg, SOI at position " + size_t(aData - myBuffer) + " / " + myLength); anImg->Thumb = StJpegParser::parseImage(theImgCount, theDepth + 1, aData - 2, false); if(!anImg->Thumb.isNull()) { //ST_DEBUG_LOG("anImg->Thumb->Length= " + anImg->Thumb->Length); aData += anImg->Thumb->Length - 2; } continue; } if(aData + 2 >= aDataEnd) { ST_DEBUG_LOG("Corrupt jpeg file or error in parser"); if(myImages.isNull()) { anImg->Data = myBuffer; anImg->Length = myLength; } return anImg; } else if(aSkippedBytes > 10) { //ST_DEBUG_LOG("Extraneous " + (aSkippedBytes - 1) + " padding bytes before section " + aMarker); } // read the length of the section (including these 2 bytes but excluding marker) const int anItemLen = StAlienData::Get16uBE(aData); if(anItemLen < 3 || (aData + anItemLen) > aDataEnd) { //ST_DEBUG_LOG("Invalid marker " + aMarker + " in jpeg (item lenght = " + anItemLen // + " from position " + int(aDataEnd - aData - 2) + ')'); // just ignore probably unknown sections continue; } switch(aMarker) { case M_SOF0: case M_SOF1: case M_SOF2: case M_SOF3: { if(anItemLen >= 7) { anImg->SizeY = StAlienData::Get16uBE(aData + 2 + 1); anImg->SizeX = StAlienData::Get16uBE(aData + 2 + 3); //ST_DEBUG_LOG(" SOF " + anImg->SizeX + "x" + anImg->SizeY); } aData += anItemLen; break; } case M_DRI: { if(anItemLen == 4) { //const int16_t aNbRestartBlocks = anImg->SizeY = StAlienData::Get16uBE(aData + 2); } aData += anItemLen; break; } case M_SOS: { // here the image data... //ST_DEBUG_LOG("Jpeg, SOS at position " + size_t(aData - myBuffer - 1) + " / " + myLength); aData += anItemLen; break; } case M_RST0: case M_RST1: case M_RST2: case M_RST3: case M_RST4: case M_RST5: case M_RST6: case M_RST7: { // aData += aNbRestartBlocks * aMcuSize; break; } case M_JFIF: { if(anItemLen >= 16 && stAreEqual(aData + 2, "JFIF\0", 5)) { myOffsets[Offset_Jfif] = aData - myBuffer - 2; //const int8_t aVerMaj = (int8_t )aData[7]; //const int8_t aVerMin = (int8_t )aData[8]; const JfifUnitsXY aUnits = (JfifUnitsXY )aData[9]; const uint16_t aDensityX = StAlienData::Get16uBE(aData + 10); const uint16_t aDensityY = StAlienData::Get16uBE(aData + 12); //const int8_t aThumbX = (int8_t )aData[14]; //const int8_t aThumbY = (int8_t )aData[15]; if(aUnits == JfifUnitsXY_AspectRatio) { anImg->ParX = aDensityX; anImg->ParY = aDensityY; } //ST_DEBUG_LOG(" ## JFIF" + aVerMaj + "." + aVerMin + " u" + (int )aUnits + " " + aDensityX + "x" + aDensityY // + " thumb " + aThumbX + "x" + aThumbY); } else if(stAreEqual(aData + 2, "JFXX\0", 5)) { // JFIF extension } aData += anItemLen; break; } case M_EXIF: case M_APP2: { myOffsets[aMarker == M_EXIF ? Offset_Exif : Offset_ExifExtra] = aData - myBuffer - 2; // there can be different section using the same marker if(stAreEqual(aData + 2, "Exif\0\0", 6)) { //ST_DEBUG_LOG("Exif section..."); StHandle<StExifDir> aSubDir = new StExifDir(); anImg->Exif.add(aSubDir); if(!aSubDir->parseExif(anImg->Exif, aData + 8, anItemLen - 8)) { // } } else if(stAreEqual(aData + 2, "MPF\0", 4)) { // MP Extensions (MPO) StHandle<StExifDir> aSubDir = new StExifDir(); aSubDir->Type = StExifDir::DType_MPO; anImg->Exif.add(aSubDir); if(!aSubDir->parseExif(anImg->Exif, aData + 6, anItemLen - 6)) { // } } else if(stAreEqual(aData + 2, "http:", 5)) { //ST_DEBUG_LOG("Image cotains XMP section"); } else { //ST_DEBUG_LOG(" @@@ APP2 " + StString((char* )aData + 2)); } // skip already read bytes aData += anItemLen; break; } case M_APP3: { if(anItemLen >= 16 && stAreEqual(aData + 2, "_JPSJPS_", 8)) { // outdated VRex section myOffsets[Offset_Jps] = aData - myBuffer - 2; //ST_DEBUG_LOG("Jpeg, _JPSJPS_ section (len= )" + anItemLen); //const uint16_t aBlockLen = StAlienData::Get16uBE(aData + 10); const uint32_t aStereoDesc = StAlienData::Get32uBE(aData + 12); #define SD_LAYOUT_INTERLEAVED 0x00000100 #define SD_LAYOUT_SIDEBYSIDE 0x00000200 #define SD_LAYOUT_OVERUNDER 0x00000300 #define SD_LAYOUT_ANAGLYPH 0x00000400 #define SD_HALF_HEIGHT 0x00010000 #define SD_HALF_WIDTH 0x00020000 #define SD_LEFT_FIELD_FIRST 0x00040000 if(aStereoDesc & 0x00000001) { const bool isLeftFirst = (aStereoDesc & SD_LEFT_FIELD_FIRST) != 0; switch(aStereoDesc & 0x0000FF00) { case SD_LAYOUT_INTERLEAVED: myStFormat = ST_V_SRC_ROW_INTERLACE; break; case SD_LAYOUT_SIDEBYSIDE: myStFormat = isLeftFirst ? ST_V_SRC_PARALLEL_PAIR : ST_V_SRC_SIDE_BY_SIDE; break; case SD_LAYOUT_OVERUNDER: myStFormat = isLeftFirst ? ST_V_SRC_OVER_UNDER_LR : ST_V_SRC_OVER_UNDER_RL; break; case SD_LAYOUT_ANAGLYPH: myStFormat = ST_V_SRC_ANAGLYPH_RED_CYAN; break; default: break; } } else { myStFormat = ST_V_SRC_MONO; } if(anItemLen > 18) { const uint16_t aStringLen = StAlienData::Get16uBE(aData + 16); char* aStrData = (char* )aData + 18; myJpsComment = StString(aStrData, aStringLen); } } // skip already read bytes aData += anItemLen; break; } case M_DQT: { myOffsets[Offset_Dqt] = aData - myBuffer - 2; aData += anItemLen; break; } case M_APP4: case M_APP5: case M_APP6: case M_APP7: case M_APP8: case M_APP9: case M_APP10: case M_APP11: case M_APP12: case M_APP13: case M_APP14: case M_APP15: case M_DHT: { aData += anItemLen; break; } case M_COM: { myOffsets[Offset_Comment] = aData - myBuffer - 2; if(anItemLen > 2) { myComment = StString((char* )aData + 2, anItemLen - 2); } //ST_DEBUG_LOG("StJpegParser, comment= '" + myComment + "'"); aData += anItemLen; break; } default: { // carefully skip unknown sections //aData += anItemLen; break; } } } }
bool StGLImageProgram::init(StGLContext& theCtx, const StImage::ImgColorModel theColorModel, const StImage::ImgColorScale theColorScale, const FragGetColor theFilter) { // re-configure shader parts when required bool isChanged = myActiveProgram.isNull(); isChanged = setFragmentShaderPart(theCtx, FragSection_Main, 0) || isChanged; isChanged = setFragmentShaderPart(theCtx, FragSection_Gamma, stAreEqual(params.gamma->getValue(), 1.0f, 0.0001f) ? FragGamma_Off : FragGamma_On) || isChanged; isChanged = setFragmentShaderPart(theCtx, FragSection_Correct, params.brightness->isDefaultValue() && params.saturation->isDefaultValue() && hasNoColorScale() ? FragCorrect_Off : FragCorrect_On) || isChanged; int aToRgb = getColorShader(theColorModel, theColorScale); if(aToRgb >= FragToRgb_FromYuvFull && theFilter == FragGetColor_Cubemap) { aToRgb += FragToRgb_CUBEMAP; } isChanged = setFragmentShaderPart(theCtx, FragSection_ToRgb, aToRgb) || isChanged; isChanged = setFragmentShaderPart(theCtx, FragSection_GetColor, theFilter) || isChanged; isChanged = setVertexShaderPart (theCtx, 0, theFilter == FragGetColor_Cubemap ? VertMain_Cubemap : VertMain_Normal) || isChanged; if(isChanged) { if(!initProgram(theCtx)) { return false; } myActiveProgram->uniProjMatLoc = myActiveProgram->getUniformLocation(theCtx, "uProjMat"); myActiveProgram->uniModelMatLoc = myActiveProgram->getUniformLocation(theCtx, "uModelMat"); uniTexMainDataLoc = myActiveProgram->getUniformLocation(theCtx, "uTexData"); uniTexUVDataLoc = myActiveProgram->getUniformLocation(theCtx, "uTexUVData"); uniTexSizePxLoc = myActiveProgram->getUniformLocation(theCtx, "uTexSizePx"); uniTexelSizePxLoc = myActiveProgram->getUniformLocation(theCtx, "uTexelSize"); uniColorProcessingLoc = myActiveProgram->getUniformLocation(theCtx, "uColorProcessing"); uniGammaLoc = myActiveProgram->getUniformLocation(theCtx, "uGamma"); myActiveProgram->atrVVertexLoc = myActiveProgram->getAttribLocation(theCtx, "vVertex"); myActiveProgram->atrVTCoordLoc = myActiveProgram->getAttribLocation(theCtx, "vTexCoord"); StGLVarLocation uniTextureLoc = myActiveProgram->getUniformLocation(theCtx, "uTexture"); StGLVarLocation uniTextureULoc = myActiveProgram->getUniformLocation(theCtx, "uTextureU"); StGLVarLocation uniTextureVLoc = myActiveProgram->getUniformLocation(theCtx, "uTextureV"); myActiveProgram->use(theCtx); theCtx.core20fwd->glUniform1i(uniTextureLoc, StGLProgram::TEXTURE_SAMPLE_0); theCtx.core20fwd->glUniform1i(uniTextureULoc, StGLProgram::TEXTURE_SAMPLE_1); theCtx.core20fwd->glUniform1i(uniTextureVLoc, StGLProgram::TEXTURE_SAMPLE_2); myActiveProgram->unuse(theCtx); /*if (!uniModelMatLoc.isValid() || !uniTexMainDataLoc.isValid() //|| !uniTexSizePxLoc.isValid() //|| !uniTexelSizePxLoc.isValid() //|| !uniSmoothFilterLoc.isValid() //|| !uniColorProcessingLoc || !atrVVertexLoc.isValid() || !atrVTCoordLoc.isValid() || !uniTextureLoc.isValid()) { return false; }*/ } if(!isValid()) { return false; } myActiveProgram->use(theCtx); if(getFragmentShaderPart(FragSection_Gamma) != FragGamma_Off) { GLfloat aReversed = 1.0f / params.gamma->getValue(); StGLVec4 aVec(aReversed, aReversed, aReversed, 1.0f); theCtx.core20fwd->glUniform4fv(uniGammaLoc, 1, aVec); } setupCorrection(theCtx); myActiveProgram->unuse(theCtx); const StGLResources aShaders("StGLWidgets"); return true; }