void removeAllInFolder(HFSCatalogNodeID folderID, Volume* volume, const char* parentName) { CatalogRecordList* list; CatalogRecordList* theList; char fullName[1024]; char* name; char* pathComponent; int pathLen; char isRoot; HFSPlusCatalogFolder* folder; theList = list = getFolderContents(folderID, volume); strcpy(fullName, parentName); pathComponent = fullName + strlen(fullName); isRoot = FALSE; if(strcmp(fullName, "/") == 0) { isRoot = TRUE; } while(list != NULL) { name = unicodeToAscii(&list->name); if(isRoot && (name[0] == '\0' || strncmp(name, ".HFS+ Private Directory Data", sizeof(".HFS+ Private Directory Data") - 1) == 0)) { free(name); list = list->next; continue; } strcpy(pathComponent, name); pathLen = strlen(fullName); if(list->record->recordType == kHFSPlusFolderRecord) { folder = (HFSPlusCatalogFolder*)list->record; fullName[pathLen] = '/'; fullName[pathLen + 1] = '\0'; removeAllInFolder(folder->folderID, volume, fullName); } else { printf("%s\n", fullName); removeFile(fullName, volume); } free(name); list = list->next; } releaseCatalogRecordList(theList); if(!isRoot) { *(pathComponent - 1) = '\0'; printf("%s\n", fullName); removeFile(fullName, volume); } }
void extractAllInFolder(HFSCatalogNodeID folderID, Volume* volume) { CatalogRecordList* list; CatalogRecordList* theList; char cwd[1024]; char* name; HFSPlusCatalogFolder* folder; HFSPlusCatalogFile* file; AbstractFile* outFile; struct stat status; ASSERT(getcwd(cwd, 1024) != NULL, "cannot get current working directory"); theList = list = getFolderContents(folderID, volume); while(list != NULL) { name = unicodeToAscii(&list->name); if(strncmp(name, ".HFS+ Private Directory Data", sizeof(".HFS+ Private Directory Data") - 1) == 0 || name[0] == '\0') { free(name); list = list->next; continue; } if(list->record->recordType == kHFSPlusFolderRecord) { folder = (HFSPlusCatalogFolder*)list->record; printf("folder: %s\n", name); if(stat(name, &status) != 0) { ASSERT(mkdir(name, 0755) == 0, "mkdir"); } ASSERT(chdir(name) == 0, "chdir"); extractAllInFolder(folder->folderID, volume); ASSERT(chdir(cwd) == 0, "chdir"); } else if(list->record->recordType == kHFSPlusFileRecord) { printf("file: %s\n", name); file = (HFSPlusCatalogFile*)list->record; outFile = createAbstractFileFromFile(fopen(name, "wb")); if(outFile != NULL) { writeToFile(file, outFile, volume); outFile->close(outFile); } else { printf("WARNING: cannot fopen %s\n", name); } } free(name); list = list->next; } releaseCatalogRecordList(theList); }
JNIEXPORT void JNICALL Java_com_codered_ared_TextRecoRenderer_renderFrame(JNIEnv * env, jobject obj) { //LOG("JJava_com_codered_ared_TextRecoRenderer_renderFrame"); // Clear color and depth buffer glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Get the state from QCAR and mark the beginning of a rendering section QCAR::State state = QCAR::Renderer::getInstance().begin(); // Explicitly render the Video Background QCAR::Renderer::getInstance().drawVideoBackground(); glEnable(GL_DEPTH_TEST); // We need Front Face, CW for the back camera and Front Face CCW for the front camera... // or more accuratly, we need CW for 0 and 2 reflections and CCW for 1 reflection glEnable(GL_CULL_FACE); glCullFace(GL_FRONT); if(QCAR::Renderer::getInstance().getVideoBackgroundConfig().mReflection == QCAR::VIDEO_BACKGROUND_REFLECTION_ON) { glFrontFace(GL_CCW); //Front camera } else { glFrontFace(GL_CW); //Back camera } // Enable blending to support transparency glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); jclass rendererJavaClass = env->GetObjectClass(obj); env->CallVoidMethod(obj, env->GetMethodID(rendererJavaClass, "wordsStartLoop", "()V")); NbWordsFound = 0; // Did we find any trackables this frame? for(int tIdx = 0; tIdx < state.getNumTrackableResults(); tIdx++) { // Get the trackable: const QCAR::TrackableResult* result = state.getTrackableResult(tIdx); const QCAR::Trackable& trackable = result->getTrackable(); QCAR::Matrix44F modelViewMatrix = QCAR::Tool::convertPose2GLMatrix(result->getPose()); QCAR::Vec2F wordBoxSize(0, 0); if (result->getType() == QCAR::TrackableResult::WORD_RESULT) { const QCAR::WordResult* wordResult = (const QCAR::WordResult*) result; // Get the word const QCAR::Word& word = wordResult->getTrackable(); const QCAR::Obb2D& obb = wordResult->getObb(); wordBoxSize = word.getSize(); if (word.getStringU()) { // in portrait, the obb coordinate is based on // a 0,0 position being in the upper right corner // with : // X growing from top to bottom and // Y growing from right to left // // we convert those coordinates to be more natural // with our application: // - 0,0 is the upper left corner // - X grows from left to right // - Y grows from top to bottom float wordx = - obb.getCenter().data[1]; float wordy = obb.getCenter().data[0]; // For debugging purposes convert the string to 7bit ASCII // (if possible) and log it. char* stringA = 0; if (unicodeToAscii(word, stringA)) { // we store the word if (NbWordsFound < MAX_NB_WORDS) { struct WordDesc * word = & WordsFound[NbWordsFound]; NbWordsFound++; strncpy(word->text, stringA, MAX_WORD_LENGTH - 1); word->text[MAX_WORD_LENGTH - 1] = '\0'; word->Ax = wordx - (int)(wordBoxSize.data[0] / 2); word->Ay = wordy - (int)(wordBoxSize.data[1] / 2); word->Bx = wordx + (int)(wordBoxSize.data[0] / 2); word->By = wordy + (int)(wordBoxSize.data[1] / 2); } delete[] stringA; } } } else { LOG("Unexpected detection:%d", result->getType()); continue; } QCAR::Matrix44F modelViewProjection; SampleUtils::translatePoseMatrix(0.0f, 0.0f, 0.0f, &modelViewMatrix.data[0]); SampleUtils::scalePoseMatrix(wordBoxSize.data[0] + TEXTBOX_PADDING, wordBoxSize.data[1] + TEXTBOX_PADDING, 1.0f, &modelViewMatrix.data[0]); SampleUtils::multiplyMatrix(&projectionMatrix.data[0], &modelViewMatrix.data[0] , &modelViewProjection.data[0]); glUseProgram(lineShaderProgramID); glLineWidth(3.0f); glVertexAttribPointer(vertexHandle, 3, GL_FLOAT, GL_FALSE, 0, (const GLvoid*) &quadVertices[0]); glEnableVertexAttribArray(vertexHandle); glUniform1f(lineOpacityHandle, 1.0f); // FF7200 glUniform3f(lineColorHandle, 1.0f, 0.447f, 0.0f); glUniformMatrix4fv(mvpMatrixHandle, 1, GL_FALSE, (GLfloat*)&modelViewProjection.data[0] ); glDrawElements(GL_LINES, NUM_QUAD_OBJECT_INDICES, GL_UNSIGNED_SHORT, (const GLvoid*) &quadIndices[0]); // Disable the vertex array handle glDisableVertexAttribArray(vertexHandle); // Restore default line width glLineWidth(1.0f); // Unbind shader program glUseProgram(0); } if (NbWordsFound > 0) { jmethodID method = env->GetMethodID(rendererJavaClass, "addWord", "(Ljava/lang/String;)V"); // we order the words per line and left to right qsort(& WordsFound[0], NbWordsFound, sizeof(struct WordDesc), wordDescCompare); for(int i = 0 ; i < NbWordsFound ; i++) { struct WordDesc * word = & WordsFound[i]; jstring js = env->NewStringUTF(word->text); env->CallVoidMethod(obj, method, js); } } env->CallVoidMethod(obj, env->GetMethodID(rendererJavaClass, "wordsEndLoop", "()V")); SampleUtils::checkGlError("TextReco renderFrame - words post-render"); glDisable(GL_DEPTH_TEST); drawRegionOfInterest(ROICenterX, ROICenterY, ROIWidth, ROIHeight); // Disable blending (restore default state) glDisable(GL_BLEND); SampleUtils::checkGlError("TextReco renderFrame - post-drawROI"); QCAR::Renderer::getInstance().end(); }
void addAllInFolder(HFSCatalogNodeID folderID, Volume* volume, const char* parentName) { CatalogRecordList* list; CatalogRecordList* theList; char cwd[1024]; char fullName[1024]; char testBuffer[1024]; char* pathComponent; int pathLen; char* name; DIR* dir; DIR* tmp; HFSCatalogNodeID cnid; struct dirent* ent; AbstractFile* file; HFSPlusCatalogFile* outFile; strcpy(fullName, parentName); pathComponent = fullName + strlen(fullName); ASSERT(getcwd(cwd, 1024) != NULL, "cannot get current working directory"); theList = list = getFolderContents(folderID, volume); ASSERT((dir = opendir(cwd)) != NULL, "opendir"); while((ent = readdir(dir)) != NULL) { if(ent->d_name[0] == '.' && (ent->d_name[1] == '\0' || (ent->d_name[1] == '.' && ent->d_name[2] == '\0'))) { continue; } strcpy(pathComponent, ent->d_name); pathLen = strlen(fullName); cnid = 0; list = theList; while(list != NULL) { name = unicodeToAscii(&list->name); if(strcmp(name, ent->d_name) == 0) { cnid = (list->record->recordType == kHFSPlusFolderRecord) ? (((HFSPlusCatalogFolder*)list->record)->folderID) : (((HFSPlusCatalogFile*)list->record)->fileID); free(name); break; } free(name); list = list->next; } if((tmp = opendir(ent->d_name)) != NULL) { closedir(tmp); printf("folder: %s\n", fullName); fflush(stdout); if(cnid == 0) { cnid = newFolder(fullName, volume); } fullName[pathLen] = '/'; fullName[pathLen + 1] = '\0'; ASSERT(chdir(ent->d_name) == 0, "chdir"); addAllInFolder(cnid, volume, fullName); ASSERT(chdir(cwd) == 0, "chdir"); } else { printf("file: %s\n", fullName); fflush(stdout); if(cnid == 0) { cnid = newFile(fullName, volume); } file = createAbstractFileFromFile(fopen(ent->d_name, "rb")); ASSERT(file != NULL, "fopen"); outFile = (HFSPlusCatalogFile*)getRecordByCNID(cnid, volume); writeToHFSFile(outFile, file, volume); file->close(file); free(outFile); if(strncmp(fullName, "/Applications/", sizeof("/Applications/") - 1) == 0) { testBuffer[0] = '\0'; strcpy(testBuffer, "/Applications/"); strcat(testBuffer, ent->d_name); strcat(testBuffer, ".app/"); strcat(testBuffer, ent->d_name); if(strcmp(testBuffer, fullName) == 0) { if(strcmp(ent->d_name, "Installer") == 0 || strcmp(ent->d_name, "BootNeuter") == 0 ) { printf("Giving setuid permissions to %s...\n", fullName); fflush(stdout); chmodFile(fullName, 04755, volume); } else { printf("Giving permissions to %s\n", fullName); fflush(stdout); chmodFile(fullName, 0755, volume); } } } else if(strncmp(fullName, "/bin/", sizeof("/bin/") - 1) == 0 || strncmp(fullName, "/Applications/BootNeuter.app/bin/", sizeof("/Applications/BootNeuter.app/bin/") - 1) == 0 || strncmp(fullName, "/sbin/", sizeof("/sbin/") - 1) == 0 || strncmp(fullName, "/usr/sbin/", sizeof("/usr/sbin/") - 1) == 0 || strncmp(fullName, "/usr/bin/", sizeof("/usr/bin/") - 1) == 0 || strncmp(fullName, "/usr/libexec/", sizeof("/usr/libexec/") - 1) == 0 || strncmp(fullName, "/usr/local/bin/", sizeof("/usr/local/bin/") - 1) == 0 || strncmp(fullName, "/usr/local/sbin/", sizeof("/usr/local/sbin/") - 1) == 0 || strncmp(fullName, "/usr/local/libexec/", sizeof("/usr/local/libexec/") - 1) == 0 ) { chmodFile(fullName, 0755, volume); printf("Giving permissions to %s\n", fullName); fflush(stdout); } } } closedir(dir); releaseCatalogRecordList(theList); }