/** * Converts from premultiplied alpha to plain alpha. * @param p pointer to a 4-byte endian-dependent color. */ static void decode_pixel(unsigned char *p) { // Assume everything not compiled with gcc to be on a little endian platform. #if defined(__GNUC__) && defined(__BIG_ENDIAN__) int alpha = p[0]; #else int alpha = p[3]; #endif if (alpha == 0) return; int div = decode_table.values[alpha - 1]; #define DECODE(i) \ do { \ unsigned color = p[i]; \ color = color * div / 256; \ if (color > 255) color = 255; \ p[i] = color; \ } while (0) #if defined(__GNUC__) && defined(__BIG_ENDIAN__) DECODE(3); #else DECODE(0); #endif DECODE(1); DECODE(2); }
int main() { PlaySoundA("skyrim.wav", NULL, SND_ASYNC | SND_LOOP | SND_FILENAME);//Play Music string choice;//choice while (1)//infinite loop { cout << "Team RAN (Ravi :) , Ajay :'( , Neha <3)" << endl << endl; cout << "Song: Elder Scrolls V: Skyrim Theme" << endl << endl; cout << "Would you like to encode or decode a phrase?" << endl << "'E' for Encoding" << endl << "'D' for Decoding" << endl << "'QQ' to Quit" << endl; getline(cin, choice);//get whole line if (choice == "E" || choice == "e")//call ENCODE ENCODE(); else if (choice == "D" || choice == "d")//call DECODE DECODE(); else if (choice == "QQ" || choice == "qq" || choice == "Qq" || choice == "qQ")//QUIT { cout << "Thank you for using this program!" << endl; system("pause"); break; } else cout << "INVALID RESPONSE" << endl << endl;//if none of the others system("pause"); system("CLS");//clears screen } return 0; }
CPLErr LERC_Band::Decompress(buf_mgr &dst, buf_mgr &src) { const Byte *ptr = (Byte *)(src.buffer); Lerc2::HeaderInfo hdInfo; Lerc2 lerc2; if (!lerc2.GetHeaderInfo(ptr, hdInfo)) return DecompressLERC(dst, src, img); // It is lerc2 here bool success = false; BitMask2 bitMask(img.pagesize.x, img.pagesize.y); switch (img.dt) { #define DECODE(T) success = lerc2.Decode(&ptr, reinterpret_cast<T *>(dst.buffer), bitMask.Bits()) case GDT_Byte: DECODE(GByte); break; case GDT_UInt16: DECODE(GUInt16); break; case GDT_Int16: DECODE(GInt16); break; case GDT_Int32: DECODE(GInt32); break; case GDT_UInt32: DECODE(GUInt32); break; case GDT_Float32: DECODE(float); break; case GDT_Float64: DECODE(double); break; default: CPLAssert(FALSE); break; #undef DECODE } if (!success) { CPLError(CE_Failure, CPLE_AppDefined, "MRF: Error during LERC2 decompression"); return CE_Failure; } if (!img.hasNoData) return CE_None; // Fill in no data values switch (img.dt) { #define UNMASK(T) UnMask(bitMask, reinterpret_cast<T *>(dst.buffer), img) case GDT_Byte: UNMASK(GByte); break; case GDT_UInt16: UNMASK(GUInt16); break; case GDT_Int16: UNMASK(GInt16); break; case GDT_Int32: UNMASK(GInt32); break; case GDT_UInt32: UNMASK(GUInt32); break; case GDT_Float32: UNMASK(float); break; case GDT_Float64: UNMASK(double); break; default: CPLAssert(FALSE); break; #undef DECODE } return CE_None; }
xml_node<TCHAR>* CXmlConfig::SetNode(const TCHAR* chNodePath, const TCHAR* chNodeValue) { LockToWrite(); TCHAR* pNodePath = m_xmlDoc.allocate_string(chNodePath); // 分配字符串并将Path复制进去 TCHAR* pNodeValue = m_xmlDoc.allocate_string(DECODE(chNodeValue)); // 分配字符串并将Value复制进去 xml_node<TCHAR>* node = m_xmlRoot->set_node(pNodePath,pNodeValue); UnLock(); return node; }
int main(int unused_argc, char **unused_argv) { ACL_VSTRING *b1 = vstring_alloc(1); ACL_VSTRING *b2 = vstring_alloc(1); char *test = "this is a test"; #define DECODE(b,x,l) { \ if (acl_hex_decode((b),(x),(l)) == 0) \ acl_msg_panic("bad hex: %s", (x)); \ } #define VERIFY(b,t) { \ if (strcmp((b), (t)) != 0) \ acl_msg_panic("bad test: %s", (b)); \ } acl_hex_encode(b1, test, strlen(test)); DECODE(b2, STR(b1), LEN(b1)); VERIFY(STR(b2), test); acl_hex_encode(b1, test, strlen(test)); acl_hex_encode(b2, STR(b1), LEN(b1)); acl_hex_encode(b1, STR(b2), LEN(b2)); DECODE(b2, STR(b1), LEN(b1)); DECODE(b1, STR(b2), LEN(b2)); DECODE(b2, STR(b1), LEN(b1)); VERIFY(STR(b2), test); acl_hex_encode(b1, test, strlen(test)); acl_hex_encode(b2, STR(b1), LEN(b1)); acl_hex_encode(b1, STR(b2), LEN(b2)); acl_hex_encode(b2, STR(b1), LEN(b1)); acl_hex_encode(b1, STR(b2), LEN(b2)); DECODE(b2, STR(b1), LEN(b1)); DECODE(b1, STR(b2), LEN(b2)); DECODE(b2, STR(b1), LEN(b1)); DECODE(b1, STR(b2), LEN(b2)); DECODE(b2, STR(b1), LEN(b1)); VERIFY(STR(b2), test); vstring_free(b1); vstring_free(b2); return (0); }
_tstring CXmlConfig::GetChildText(const TCHAR* szChildName) { _tstring strRet = _T(""); LockToRead(); xml_node<TCHAR>* pXmlNode = FindChild(szChildName); if ( pXmlNode) { strRet = DECODE(pXmlNode->value()); } UnLock(); return strRet; }
_tstring CXmlConfig::GetAttributeValue(const TCHAR* attributeName,const TCHAR* attributeDefaultValue,bool* pResult){ LockToRead(); xml_node<TCHAR>* node = FindChild(attributeName); bool bNodeExists = node? true:false; if(pResult) (*pResult) = bNodeExists; _tstring strRetValue = bNodeExists? DECODE(node->value()):attributeDefaultValue; UnLock(); if(!bNodeExists) SetNode(attributeName,attributeDefaultValue); return strRetValue; }
static void b64_decode(const char *ptr) { ACL_VSTRING *str = acl_vstring_alloc(1); const char *p; #define DECODE(b,x,l) { \ if (acl_vstring_base64_decode((b),(x),(l)) == 0) { \ printf("bad base64 encoded string: %s\r\n", (x)); \ exit (1); \ } \ } DECODE(str, ptr, strlen(ptr)); p = acl_vstring_str(str); printf(">>>decode result:|%s|\n>>>orignal str: {%s}, len: %d\n", p, ptr, (int) ACL_VSTRING_LEN(str)); b64_encode(p); printf("len: %d, %d\n", (int) ACL_VSTRING_LEN(str), (int) strlen(p)); acl_vstring_free(str); }
void decode_word_list(char *word_list, int word_list_pos) { int index = 0; unsigned short x; return; while(index < word_list_pos) { if (!word_list[index]) { index++; continue; } x = *(unsigned short*)&word_list[index]; x = DECODE(x); *(unsigned short*)&word_list[index] = x; index += 2; } }
uint8_t v = 0; ret = Decode(buf, size, offset, v); if (0 > ret) { return ret; } data = (0 != v); return S_OK; } int32_t CCodeEngine::Decode(const uint8_t *buf, const uint32_t size, uint32_t& offset, int8_t& data) { DECODE(buf, size, offset, data, int8_t) } int32_t CCodeEngine::Decode(const uint8_t *buf, const uint32_t size, uint32_t& offset, int16_t& data) { DECODE(buf, size, offset, data, int16_t) } int32_t CCodeEngine::Decode(const uint8_t *buf, const uint32_t size, uint32_t& offset, int32_t& data) { DECODE(buf, size, offset, data, int32_t) } int32_t CCodeEngine::Decode(const uint8_t *buf, const uint32_t size, uint32_t& offset, int64_t& data) { DECODE(buf, size, offset, data, int64_t)
void PETRI::places::loadInPlcs() { /* Data Model Changed string sql= " \ SELECT A.PLACE_ID,DECODE(E.ARC_TYPE,'P',1,0) PLACE_TYPE,C.PLACE_CUR_STATE,C.TOKEN_CNT \ FROM P_TRANSITION_PLACE_RELA A,P_PLACE_ATTR C,P_ARC_ATTR D,P_ARC_CHART_ATTR E \ WHERE A.TRANSITION_ID = :TRANSID \ AND A.PLACE_ID=C.PLACE_ID \ AND A.PLACE_TYPE='INT' \ AND D.ARC_START_TYPE='P' \ AND D.ARC_END_TYPE='T' \ AND D.ARC_START_ID=A.PLACE_ID \ AND D.ARC_ID=E.ARC_ID \ AND D.ARC_END_ID=A.TRANSITION_ID ORDER BY PLACE_TYPE \ "; */ try { string sql = " \ SELECT DISTINCT A.PLACE_ID,DECODE(E.ARC_TYPE,'P',1,0) PLACE_TYPE,NVL(C.PLACE_CUR_STATE,'0'),C.TOKEN_CNT ,C.DRAW_ID,C.PLACE_NAME \ FROM P_TRANSITION_PLACE_RELA A,P_PLACE_ATTR C,P_ARC_CHART_ATTR E \ WHERE A.TRANSITION_ID = :TRANSID \ AND A.PLACE_ID=C.PLACE_ID \ AND A.PLACE_TYPE='INT' \ AND A.ARC_ID=E.ARC_ID \ ORDER BY PLACE_TYPE \ "; DEFINE_PETRI_QUERY(query); query.close(); query.setSQL(sql.c_str()); query.setParameter("TRANSID",l_transID); query.open(); while(query.next()) { /* inPlcs.v_plcID.push_back(query.field(0).asInteger()); inPlcs.v_plcType.push_back(query.field(1).asInteger()); inPlcs.v_plcState.push_back(query.field(2).asString()); inPlcs.v_plcToknum.push_back(query.field(3).asInteger()); */ a_plcID[i_size] = query.field(0).asInteger(); a_plcType[i_size] = query.field(1).asInteger(); a_plcState[i_size] = query.field(2).asString(); a_plcToknum[i_size] = query.field(3).asInteger(); a_plcDrawID[i_size] = query.field(4).asLong(); strncpy(a_plcName[i_size],query.field(5).asString(),NAME_LENGTH); i_size++; } query.close(); }catch (TOCIException & toe){ LOG(toe.getErrMsg()); LOG(toe.getErrSrc()); } catch(...) { return; } return; };