/** CORE FUNCTIONS */ int generateInitialHammingStringCoreFunction(char *input_string, char *hamming_string, MODE mode) { int i,j,input_string_len; j=0; /**Calculating the hamming message length*/ input_string_len = messageLength(input_string,mode); /**Loop to generate a hamming outline string with unset parity bits.*/ for (i = 0; i<input_string_len; ) { /**Condition check to verify if the bit position is a parity position or not.*/ if ((j+1)==closestPowerOfTwo((j+1), mode)) { /**Set the bit position as empty as indicated by the character _*/ *(hamming_string+j) = '_'; j++; } else { *(hamming_string+j) = *(input_string+i); j++; i++; } } *(hamming_string+j) = CHARACTER_TERMINATION; /**To check if the mode being executed was debug or not.*/ if(mode == eDEBUG) { /**function call to display the bitstring.*/ displayBits(hamming_string); } return 0; }
int hammingStringCopyWithParityResetCoreFunction(char *input_hamming_string, char *new_hamming_string, MODE mode) { int len,i; /**Calculating the incoming hamming message length*/ len = messageLength(input_hamming_string,mode); /**Loop which unsets all the parity bits in the hamming string.*/ for (i = 0; i < len; ++i) { /**Condition to check if the read bit position is a parity bit position or not.*/ if((i+1)==closestPowerOfTwo((i+1),mode)) { /**Set the bit position as empty as indicated by the character _ */ *(new_hamming_string+i) = '_'; } else { *(new_hamming_string+i) = *(input_hamming_string+i); } } *(new_hamming_string+i) = CHARACTER_TERMINATION; /**To check if the mode being executed was debug or not.*/ if(mode == eDEBUG) { /**function call to display the bitstring.*/ displayBits(new_hamming_string); } return 0; }
int parityVerificationCoreFunction(char *received_message, char *calculated_parity_message, MODE mode) { int len,i,error_bit=0; /**Calculating the incoming hamming message length*/ len = messageLength(received_message, mode); /**Loop which calculates the single bits error if present in the received message.*/ for (i = 0; i < len; ++i) { /**Condition to check if the read bit position is a parity bit position or not.*/ if((i+1)==closestPowerOfTwo((i+1), mode)) { /**Condition to check if the received parity message is different from the calculated one.*/ if(*(received_message+i) != *(calculated_parity_message+i)) { /**If different OR/concatenate the erroroneous bit position by performing logical OR.*/ error_bit |= (i+1); } } } /**To check if the mode being executed was debug or not.*/ if (mode == eDEBUG) { /**Printing the erroroneous bit position.*/ printf("Error Bit Position %d\n", error_bit); } /** Erroroneous bit position.*/ return error_bit; }
void FileSystemActor::onRender(uint flags) { #ifdef TESTING_ALTERNATE_RENDERING if (isActorType(Invisible)) return; // _isAnimatedTexture is always false right now since we don't robustly support animated gifs if (_isAnimatedTexture) { bool successful = true; // if this is an animated texture and we've never loaded the animation // then do so now if (!_animatedTextureSource.load()) _isAnimatedTexture = false; if (_animatedTextureSource.numFrames() <= 1) successful = false; else { AnimatedTextureFrame * frame = _animatedTextureSource.getCurrentTextureFrame(); Vec3 sz = getDims(); glPushAttribToken token(GL_ENABLE_BIT); glEnable(GL_DEPTH_TEST); glEnable(GL_BLEND); glEnable(GL_TEXTURE_2D); // Conditionals if (isSelected() || isActorType(Temporary)) glDisable(GL_DEPTH_TEST); if (isActorType(Invisible)) return; //transform our unit cube: glPushMatrix(); ShapeVis::setupGLMatrix(getGlobalPosition(), getGlobalOrientation()); glScaled(sz.x, sz.y, sz.z); // render the current index glBindTexture(GL_TEXTURE_2D, _animatedTextureSource.GLId()); glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, frame->width, frame->height, GL_BGRA, GL_UNSIGNED_BYTE, frame->pixelData); // Set the Texture glColor4f(1, 1, 1, getAlpha()); // Scale the image uint squareSize = closestPowerOfTwo(NxMath::max(frame->width, frame->height)); float w = (float) frame->width / squareSize; float h = (float) frame->height / squareSize; h = 1.0f - (h * w); glBegin(GL_QUADS); glNormal3f(0,0,1); glTexCoord2f(w,0); glVertex3f(1,1,1); glTexCoord2f(0,0); glVertex3f(-1,1,1); glTexCoord2f(0,h); glVertex3f(-1,-1,1); glTexCoord2f(w,h); glVertex3f(1,-1,1); glNormal3f(0,0,-1); glTexCoord2f(0,h); glVertex3f(1,-1,-1); glTexCoord2f(w,h); glVertex3f(-1,-1,-1); glTexCoord2f(w,0); glVertex3f(-1,1,-1); glTexCoord2f(0,0); glVertex3f(1,1,-1); glEnd(); glPopMatrix(); } // skip the normal rendering routine if (successful) return; } // Render the previous actor first Actor::onRender(flags); // Render an overlay bool isLinkOverlay = (isFileSystemType(Link) || isFileSystemType(DeadLink)) && GLOBAL(settings).manualArrowOverlay; bool isFileTypeOverlay = !getTextIcon().isEmpty(); if (isLinkOverlay || isFileTypeOverlay) { glPushAttribToken token(GL_ENABLE_BIT); glDisable(GL_DEPTH_TEST); glEnable(GL_BLEND); glEnable(GL_TEXTURE_2D); // Render the shortcut/file type icon Arrow QString renderTextureId = QT_NT("icon.linkOverlay"); Vec3 renderPos = getGlobalPosition(); Vec3 renderDims = getDims(); bool shouldScaleIcon = false; if (isFileTypeOverlay) { renderTextureId = getTextIcon(); shouldScaleIcon = true; } else if (isLinkOverlay) { // If the creator of the theme has a bad icon link overlay, we need to re-size it so it does not take up the entire actor // A "good" icon link overlay is 256x255; with the actual overlay part taking up 77x75 in the bottom-left corner Vec3 dimensions = texMgr->getTextureDims(renderTextureId); if (dimensions.x > 0 && dimensions.y > 0) { if ((closestPowerOfTwo(dimensions.x) != 256) || (closestPowerOfTwo(dimensions.y) != 256)) { shouldScaleIcon = true; // position the link icon to the corner of the actual actor (instead of scaling/stretching it) float maxSide = max(dimensions.x, dimensions.y); renderDims.x = renderDims.y = maxSide; } } } if (shouldScaleIcon) { Vec3 offset(getDims().x, -getDims().y, 0); // Scale the actor to proper size (256/77 =~ 3.4; 255/75 = 3.4) renderDims.x /= 3.4f; renderDims.y /= 3.4f; offset += Vec3(-renderDims.x - 0.25f, renderDims.y + 0.25f, 0); offset = getGlobalOrientation() * offset; renderPos += offset; } glBindTexture(GL_TEXTURE_2D, texMgr->getGLTextureId(renderTextureId)); glColor4f(1, 1, 1, getAlpha()); ShapeVis::renderSideLessBox(renderPos, getGlobalOrientation(), renderDims); } #elif !defined DXRENDER // _isAnimatedTexture is always false right now since we don't robustly support animated gifs if (_isAnimatedTexture) { bool successful = true; // if this is an animated texture and we've never loaded the animation // then do so now if (!_animatedTextureSource.load()) _isAnimatedTexture = false; if (_animatedTextureSource.numFrames() <= 1) successful = false; else { AnimatedTextureFrame * frame = _animatedTextureSource.getCurrentTextureFrame(); Vec3 sz = getDims(); glPushAttribToken token(GL_ENABLE_BIT); glEnable(GL_DEPTH_TEST); glEnable(GL_BLEND); glEnable(GL_TEXTURE_2D); // Conditionals if (isSelected() || isActorType(Temporary)) glDisable(GL_DEPTH_TEST); if (isActorType(Invisible)) return; //transform our unit cube: glPushMatrix(); ShapeVis::setupGLMatrix(getGlobalPosition(), getGlobalOrientation()); glScaled(sz.x, sz.y, sz.z); // render the current index glBindTexture(GL_TEXTURE_2D, _animatedTextureSource.GLId()); glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, frame->width, frame->height, GL_BGRA, GL_UNSIGNED_BYTE, frame->pixelData); // Set the Texture glColor4f(1, 1, 1, getAlpha()); // Scale the image uint squareSize = closestPowerOfTwo(NxMath::max(frame->width, frame->height)); float w = (float) frame->width / squareSize; float h = (float) frame->height / squareSize; h = 1.0f - (h * w); glBegin(GL_QUADS); glNormal3f(0,0,1); glTexCoord2f(w,0); glVertex3f(1,1,1); glTexCoord2f(0,0); glVertex3f(-1,1,1); glTexCoord2f(0,h); glVertex3f(-1,-1,1); glTexCoord2f(w,h); glVertex3f(1,-1,1); glNormal3f(0,0,-1); glTexCoord2f(0,h); glVertex3f(1,-1,-1); glTexCoord2f(w,h); glVertex3f(-1,-1,-1); glTexCoord2f(w,0); glVertex3f(-1,1,-1); glTexCoord2f(0,0); glVertex3f(1,1,-1); glEnd(); glPopMatrix(); } // skip the normal rendering routine if (successful) return; } // Render the previous actor first Actor::onRender(flags); // Render a link overlay arrow if ((isFileSystemType(Link) || isFileSystemType(DeadLink)) && !isActorType(Invisible)) { glPushAttribToken token(GL_ENABLE_BIT); glDisable(GL_DEPTH_TEST); glEnable(GL_BLEND); glEnable(GL_TEXTURE_2D); // Render the shortcut Arrow if (GLOBAL(settings).manualArrowOverlay) { glBindTexture(GL_TEXTURE_2D, texMgr->getGLTextureId("icon.linkOverlay")); bool scaleOverlayActor = false; //If the creator of the theme has a bad icon link overlay, we need to re-size it so it does not take up the entire actor Vec3 dimensions = texMgr->getTextureDims("icon.linkOverlay"); //A "good" icon link overlay is 256x255; with the actual overlay part taking up 77x75 in the bottom-left corner if(dimensions.x > 0 && dimensions.y > 0) { if((closestPowerOfTwo(dimensions.x) != 256)||(closestPowerOfTwo(dimensions.y) != 256)) scaleOverlayActor = true; } glColor4f(1, 1, 1, getAlpha()); // Render Shape Vec3 pos = getGlobalPosition(); Vec3 dims = getDims(); Vec3 normalizedDims = dims; // position the link icon to the corner of the actual actor (instead of scaling/stretching it) float maxSide = max(dims.x, dims.y); normalizedDims.x = normalizedDims.y = maxSide; // Scale the actor to proper size (256/77 =~ 3.4; 255/75 = 3.4) if(scaleOverlayActor){ normalizedDims.x /= 3.4f; normalizedDims.y /= 3.4f; } if(scaleOverlayActor) { Vec3 offset(dims.x, -dims.y, 0); offset = getGlobalOrientation() * offset; pos += offset; } else { pos.x -= normalizedDims.x - dims.x; pos.z += normalizedDims.y - dims.y; } ShapeVis::renderSideLessBox(pos, getGlobalOrientation(), normalizedDims); } } #elif defined DXRENDER // Render the previous actor first Actor::onRender(flags); // Render a link overlay arrow if ((isFileSystemType(Link) || isFileSystemType(DeadLink)) && !isActorType(Invisible)) { // Render the shortcut Arrow if (GLOBAL(settings).manualArrowOverlay) { bool scaleOverlayActor = false; //If the creator of the theme has a bad icon link overlay, we need to re-size it so it does not take up the entire actor Vec3 dimensions = texMgr->getTextureDims("icon.linkOverlay"); //A "good" icon link overlay is 256x255; with the actual overlay part taking up 77x75 in the bottom-left corner if(dimensions.x > 0 && dimensions.y > 0) { if((closestPowerOfTwo(dimensions.x) != 256)||(closestPowerOfTwo(dimensions.y) != 256)) scaleOverlayActor = true; } // Render Shape Vec3 pos = getGlobalPosition(); Vec3 dims = getDims(); Vec3 normalizedDims = dims; // position the link icon to the corner of the actual actor (instead of scaling/stretching it) float maxSide = max(dims.x, dims.y); normalizedDims.x = normalizedDims.y = maxSide; // Scale the actor to proper size (256/77 =~ 3.4; 255/75 = 3.4) if(scaleOverlayActor){ normalizedDims.x /= 3.4f; normalizedDims.y /= 3.4f; } if(scaleOverlayActor) { Vec3 offset(dims.x, -dims.y, 0); offset = getGlobalOrientation() * offset; pos += offset; } else { pos.x -= normalizedDims.x - dims.x; pos.z += normalizedDims.y - dims.y; } dxr->device->SetRenderState(D3DRS_ZENABLE, false); dxr->renderSideLessBox(pos, getGlobalOrientation(), normalizedDims, texMgr->getGLTextureId("icon.linkOverlay")); dxr->device->SetRenderState(D3DRS_ZENABLE, true); } } #endif }