///////////////////////////////////////////////////////////////////////////////
// GetData
///////////////////////////////////////////////////////////////////////////////
int8* cHierDatabaseIter::GetData(int32& length) const //throw (eArchive, eHierDatabase)
{
    ASSERT( HasData() );
    if( ! HasData() )
    {
        throw eHierDatabase( _T("Attempt to get data from a node when HasData() is false"));
    }

    //
    // note that we can only get data for reading; perhaps in the future I will add
    // support for retrieving data for writing as well.
    //
    return mpDb->GetDataForReading( cBlockRecordFile::tAddr(mIter->mData.mBlockNum, mIter->mData.mIndex), length );

}
示例#2
0
// Return true if data was changed
bool CAccount::SetData(const std::string& strKey, const std::string& strValue, int iType)
{
    if (strValue == "false" && iType == LUA_TBOOLEAN)
    {
        if (HasData(strKey))
        {
            RemoveData(strKey);
            return true;
        }
    }
    else
    {
        CAccountData* pData = GetDataPointer(strKey);

        if (pData)
        {
            if (pData->GetType() != iType || pData->GetStrValue() != strValue)
            {
                pData->SetStrValue(strValue);
                pData->SetType(iType);
                return true;
            }
        }
        else
        {
            MapSet(m_Data, strKey, CAccountData(strKey, strValue, iType));
            return true;
        }
    }
    return false;
}
示例#3
0
void ChmDoc::FixPathCodepage(AutoFree& path, UINT& fileCP) {
    if (!path || HasData(path))
        return;

    AutoFree utf8Path(ToUtf8((unsigned char*)path.Get()));
    if (HasData(utf8Path)) {
        path.Set(utf8Path.StealData());
        fileCP = codepage;
    } else if (fileCP != codepage) {
        utf8Path.Set(ToUtf8((unsigned char*)path.Get(), fileCP));
        if (HasData(utf8Path)) {
            path.Set(utf8Path.StealData());
            codepage = fileCP;
        }
    }
}
示例#4
0
int USBGetChar()
{
	for(;;)
	{
		USBSetupInterrupt();
		USBGeneralInterrupt();

		//	Read a char
		if (HasData(CDC_RX))
		{
			u8 c = Recv8();
			if (!ReadWriteAllowed())
				ReleaseRX();
			return c;
		} 

		if (!--_timeout) {
			Reboot();	// USB not connected, run firmware
		}
		
		_delay_us(100);	// stretch out the bootloader period to about 5 seconds after enumeration
		LEDPulse();
	}
	return -1;
}
示例#5
0
float DataSequence::operator[](unsigned int i) const
{
  if( !HasData(i) ) {
    throw DataUnavailableException("Out of range");
  }
  return y[(i-firstn) % y.size()];
}
示例#6
0
文件: Node.cpp 项目: jpjust/mobsink
int Node::GetRunTimeRL(void)
{
    // If there is no data to send or no energy, the RunTime RL is zero
    if ((!HasData()) || (power == 0))
        return 0;
    else
        return this->RL;
}
示例#7
0
文件: Node.cpp 项目: jpjust/mobsink
// Decrease the buffer and energy, simulating data transmission.
// Return how much energy was spent.
double Node::SendData(void)
{
    if (!IsActive())
        return 0;

    // 1 second has passed...
    //time_elapsed++;
    double txtime = 1;

    // Energy consumed
    double energy = 0;

    // While there are time to transmit, do it
    while (txtime >= TX_TIME)
    {
        // Decrease the time needed to transmit 1 PDU
        txtime -= TX_TIME;

        // If there is no data to be sent or no next hop, quit
        if ((HasData() == false) || (nexthop == NULL))
            break;

        // If there is no power to transmit data, give up and
        // zero power
        if (power < PWT)
        {
            energy = power;
            power = 0;
        }
        else // If there is power to transmit, go ahead
        {
            // Get how much energy the next hop will spend receiving
            double pwr_hop = nexthop->GetData();

            // Check if transmission was done
            if (pwr_hop < 0)
            	return 0;

            // Increase hops and tx counters
            hops += hops_to_sink;
            tx++;

            // If the next hop got the data or it is the sink, compute
            if ((pwr_hop > 0) || (hops_to_sink == 1))
            {
                power -= PWT;
                pdu--;
                energy += PWT;

                // Add next hop's PWR
                energy += pwr_hop;
            }
        }
    }

    return energy;
}
示例#8
0
文件: plot.cpp 项目: IGNF/wxfreechart
void Plot::Draw(wxDC &dc, wxRect rc)
{
	m_background->Draw(dc, rc);

	if (HasData()) {
		DrawData(dc, rc);
	}
	else {
		DrawNoDataMessage(dc, rc);
	}
}
示例#9
0
void MOCTriger::Init(MOCComponentMgr &mgr)
{
	m_mgr.EventType(m_nEventType);
	m_mgr.ConditionType(m_nConditionType);
	m_mgr.Value(m_dValue);
	m_mgr.ComponentID1(m_nComponentID1);
	m_mgr.ComponentID2(m_nComponentID2);
	m_mgr.Port1(m_nPort1);
	m_mgr.Port2(m_nPort2);
	m_mgr.HasTranData(HasData());
	m_mgr.ModelMgr(&mgr);
}
示例#10
0
CString CHallQueFrontView::GetData()
{
	m_Mlock.Lock();
	CString address;
	if(HasData())
	{
		address = m_list_address.GetHead();
		m_list_address.RemoveHead();
	}
	m_Mlock.Unlock();
	return address;
}
示例#11
0
bool ChmDoc::Load(const WCHAR *fileName)
{
    chmHandle = chm_open((WCHAR *)fileName);
    if (!chmHandle)
        return false;

    ParseWindowsData();
    if (!ParseSystemData())
        return false;

    UINT fileCodepage = codepage;
    char header[24] = { 0 };
    if (file::ReadN(fileName, header, sizeof(header))) {
        DWORD lcid = ByteReader(header, sizeof(header)).DWordLE(20);
        fileCodepage = LcidToCodepage(lcid);
    }
    if (!codepage)
        codepage = fileCodepage;
    // if file and #SYSTEM codepage disagree, prefer #SYSTEM's (unless it leads to wrong paths)
    FixPathCodepage(homePath, fileCodepage);
    FixPathCodepage(tocPath, fileCodepage);
    FixPathCodepage(indexPath, fileCodepage);
    if (GetACP() == codepage)
        codepage = CP_ACP;

    if (!HasData(homePath)) {
        const char *pathsToTest[] = {
            "/index.htm", "/index.html", "/default.htm", "/default.html"
        };
        for (int i = 0; i < dimof(pathsToTest); i++) {
            if (HasData(pathsToTest[i])) {
                homePath.SetCopy(pathsToTest[i]);
            }
        }
        if (!HasData(homePath))
            return false;
    }

    return true;
}
///////////////////////////////////////////////////////////////////////////////
// SetData
///////////////////////////////////////////////////////////////////////////////
void cHierDatabaseIter::SetData(int8* pData, int32 length) //throw (eArchive, eHierDatabase)
{
    ASSERT( ! Done() );
    ASSERT( ! HasData() );
    
    // remove the item's data, if there is any...
    //
    if( HasData() )
    {
        RemoveData();
    }
    //
    // add the data and set the entry's data pointer appropriately
    //
    cBlockRecordFile::tAddr addr = mpDb->AddItem( pData, length );
    mIter->mData = cHierAddr( addr.mBlockNum, addr.mIndex );
    //
    // update the entry on disk...
    //
    util_RewriteObject( mpDb, &(*mIter), GetCurrentAddr() );

}
示例#13
0
bool ChmDoc::Load(const WCHAR *fileName)
{
    chmHandle = chm_open((WCHAR *)fileName);
    if (!chmHandle)
        return false;

    ParseWindowsData();
    if (!ParseSystemData())
        return false;

    if (!HasData(homePath)) {
        const char *pathsToTest[] = {
            "/index.htm", "/index.html", "/default.htm", "/default.html"
        };
        for (int i = 0; i < dimof(pathsToTest); i++) {
            if (HasData(pathsToTest[i]))
                homePath.Set(str::Dup(pathsToTest[i]));
        }
    }
    if (!HasData(homePath))
        return false;

    if (!codepage) {
        char header[24];
        if (file::ReadAll(fileName, header, sizeof(header))) {
            DWORD lcid = ByteReader(header, sizeof(header)).DWordLE(20);
            codepage = LcidToCodepage(lcid);
        }
        else
            codepage = CP_CHM_DEFAULT;
    }
    if (GetACP() == codepage)
        codepage = CP_ACP;

    return true;
}
///////////////////////////////////////////////////////////////////////////////
// RemoveData
///////////////////////////////////////////////////////////////////////////////
void cHierDatabaseIter::RemoveData() //throw (eArchive, eHierDatabase)
{
    ASSERT( ! Done() );
    if( ! HasData() )
    {
        ASSERT( false );
        return;
    }

    mpDb->RemoveItem( cBlockRecordFile::tAddr( mIter->mData.mBlockNum, mIter->mData.mIndex ) );
    //
    // now, we need to update the node's data pointer and save the node to disk
    //
    mIter->mData = cHierAddr();
    util_RewriteObject( mpDb, &(*mIter), GetCurrentAddr() );
}
void AuxFaction::CheckData()
{
	SetParentExtendedFlag(HasData());
}
示例#16
0
bool ArpMessage::HasIndirect(const char* name, int32 index) const
{
	return HasData(name, B_RGB_COLOR_TYPE, index);
}
示例#17
0
bool ArpMessage::HasFont(const char* name, int32 index) const
{
	return HasData(name, FFont::FONT_TYPE, index);
}
示例#18
0
文件: ring.cpp 项目: arkose/openbabel
  void OBMol::FindSSSR()
  {
    if (HasSSSRPerceived())
      return;
    SetSSSRPerceived();
    obErrorLog.ThrowError(__FUNCTION__,
                          "Ran OpenBabel::FindSSSR", obAuditMsg);

    // Delete any old data before we start finding new rings
    // The following procedure is slow
    // So if client code is multi-threaded, we don't want to make them wait
    if (HasData("SSSR")) {
      DeleteData("SSSR");
    }

    OBRing *ring;
    vector<OBRing*>::iterator j;

    //get Frèrejacque taking int account multiple possible spanning graphs
    int frj = DetermineFRJ(*this);
    if (frj)
      {
        vector<OBRing*> vr;
        FindRingAtomsAndBonds();

        OBBond *bond;
        vector<OBBond*> cbonds;
        vector<OBBond*>::iterator k;

        //restrict search for rings around closure bonds
        for (bond = BeginBond(k);bond;bond = NextBond(k))
          if (bond->IsClosure())
            cbonds.push_back(bond);

        if (!cbonds.empty())
          {
            OBRingSearch rs;
            //search for all rings about closures
            vector<OBBond*>::iterator i;

            for (i = cbonds.begin();i != cbonds.end();++i)
              rs.AddRingFromClosure(*this,(OBBond*)*i);

            rs.SortRings();
            rs.RemoveRedundant(frj);
            //store the SSSR set

            for (j = rs.BeginRings();j != rs.EndRings();++j)
              {
                ring = new OBRing ((*j)->_path,NumAtoms()+1);
                ring->SetParent(this);
                vr.push_back(ring);
              }
            //rs.WriteRings();
          }

        OBRingData *rd = new OBRingData();
        rd->SetOrigin(perceived); // to separate from user or file input
        rd->SetAttribute("SSSR");
        rd->SetData(vr);
        SetData(rd);
      }
  }
示例#19
0
/**
 *   Read the serial FIFO and process complete GPS messages.
 */
void GPSNmea::Update() {
    uint32_t value;

    // This state machine handles each character as it is read from the GPS serial port.
    while (HasData()) {
        // Get the character value.
        value = ReadData();
        //this->gpsBuffer[this->gpsIndex++] = value;
        switch (gpsParseState) {
        ///////////////////////////////////////////////////////////////////////
        // Search for start of message '$'
        case STARTOFMESSAGE:
            if (value == '$') {
                calcChecksum = 0; // reset checksum
                index = 0; // reset index
                gpsParseState = COMMAND;
            }
            break;

            ///////////////////////////////////////////////////////////////////////
            // Retrieve command (NMEA Address)
        case COMMAND:
            if (value != ',' && value != '*') {
                commandBuffer[index++] = value;
                calcChecksum ^= value;

                // Check for command overflow
                if (index >= MAX_CMD_LEN)
                    gpsParseState = STARTOFMESSAGE;
            } else {
                commandBuffer[index] = '\0'; // terminate command
                calcChecksum ^= value;
                index = 0;
                gpsParseState = DATA; // goto get data state
            }
            break;

            // Store data and check for end of sentence or checksum flag
        case DATA:
            if (value == '*') { // checksum flag?
                dataBuffer[index] = '\0';
                gpsParseState = CHECKSUM_1;
            } else {
                // Check for end of sentence with no checksum
                if (value == '\r') {
                    dataBuffer[index] = '\0';
                    ProcessCommand(commandBuffer, dataBuffer);
                    gpsParseState = STARTOFMESSAGE;
                    return;
                }

                //
                // Store data and calculate checksum
                //
                calcChecksum ^= value;
                dataBuffer[index] = value;
                if (++index >= MAX_DATA_LEN) // Check for buffer overflow
                    gpsParseState = STARTOFMESSAGE;
            }
            break;

        case CHECKSUM_1:
            if ((value - '0') <= 9)
                receivedChecksum = (value - '0') << 4;
            else
                receivedChecksum = (value - 'A' + 10) << 4;

            gpsParseState = CHECKSUM_2;
            break;

        case CHECKSUM_2:
            if ((value - '0') <= 9)
                receivedChecksum |= (value - '0');
            else
                receivedChecksum |= (value - 'A' + 10);

            //FIXME: re-add verifying the checksum after testing is finished
            //if (calcChecksum == receivedChecksum)
                ProcessCommand(commandBuffer, dataBuffer);

            gpsParseState = STARTOFMESSAGE;
            break;

            ///////////////////////////////////////////////////////////////////////
        default:
            gpsParseState = STARTOFMESSAGE;
            break;
        }
    } // END while
}
示例#20
0
void AuxBuff::CheckData()
{
	SetParentExtendedFlag(HasData());
}
示例#21
0
status_t TPreferences::SetData(const char *name, type_code type, const void *data, ssize_t data_size) {
	if (HasData(name, type)) {
		return ReplaceData(name, type, 0, data, data_size);
	}
	return AddData(name, type, data, data_size);
}
void AuxSkillAbility::CheckData()
{
	SetParentExtendedFlag(HasData());
}
示例#23
0
static 
rc_t LoadObjects ( ObjectTable* data,  const VDatabase* db )
{
    const VTable* tbl;
    rc_t rc = VDatabaseOpenTableRead(db, &tbl, "OBJECTS");
    if (rc == 0)
    {
        rc_t rc2;
        const VCursor *cur;

        rc = VTableCreateCachedCursorRead( tbl, &cur, CursorCacheSize );
        if (rc == 0)
        {
            uint32_t id_idx, name_idx, proj_idx, dname_idx, size_idx, csum_idx, enc_idx;
            if (rc == 0) rc = VCursorAddColumn( cur, &id_idx,    "id" );
            if (rc == 0) rc = VCursorAddColumn( cur, &name_idx,  "name" );
            if (rc == 0) rc = VCursorAddColumn( cur, &proj_idx,    "project" );
            if (rc == 0) rc = VCursorAddColumn( cur, &dname_idx, "display_name" );
            if (rc == 0) rc = VCursorAddColumn( cur, &size_idx,  "size" );
            if (rc == 0) rc = VCursorAddColumn( cur, &csum_idx,  "checksum" );
            if (rc == 0) rc = VCursorAddColumn( cur, &enc_idx,   "encryption_key" );
            if (rc == 0 && HasData(tbl))
            {
                rc = VCursorOpen( cur );
                if (rc == 0)
                {
                    int64_t  first;
                    uint64_t count;
                    rc = VCursorIdRange( cur, 0, &first, &count );
                    if (rc == 0)
                    {
                        uint64_t i;
                        for (i=0; i < count; ++i)
                        {
                            const void* ptr;
                            uint32_t elem_count;
                            uint32_t id;
                            String name;
                            String project;
                            String display_name;
                            uint64_t size;
                            String checksum;
                            String encryption_key;

                            rc = VCursorSetRowId(cur, first + i);
                            if (rc == 0) rc = VCursorOpenRow( cur );
                            
                            if (rc == 0) rc = VCursorCellData( cur, id_idx, NULL, &ptr, NULL, NULL);
                            if (rc == 0) id = *(uint32_t*)ptr;
                            
                            if (rc == 0) rc = VCursorCellData( cur, name_idx, NULL, &ptr, NULL, &elem_count);
                            if (rc == 0) StringInit(&name, (const char*)ptr, elem_count, elem_count);
                            
                            if (rc == 0) rc = VCursorCellData( cur, proj_idx, NULL, &ptr, NULL, &elem_count);
                            if (rc == 0) StringInit(&project, (const char*)ptr, elem_count, elem_count);
                            
                            if (rc == 0) rc = VCursorCellData( cur, dname_idx, NULL, &ptr, NULL, &elem_count);
                            if (rc == 0) StringInit(&display_name, (const char*)ptr, elem_count, elem_count);
                            
                            if (rc == 0) rc = VCursorCellData( cur, size_idx, NULL, &ptr, NULL, NULL);
                            if (rc == 0) size = *(uint32_t*)ptr;
                            
                            if (rc == 0) rc = VCursorCellData( cur, enc_idx, NULL, &ptr, NULL, &elem_count);
                            if (rc == 0) StringInit(&encryption_key, (const char*)ptr, elem_count, elem_count);
                            
                            if (rc == 0) rc = VCursorCellData( cur, csum_idx, NULL, &ptr, NULL, &elem_count);
                            if (rc == 0) StringInit(&checksum, (const char*)ptr, elem_count, elem_count);

                            if (rc == 0) rc = KeyRingDataInsertObject(data, id, &name, &project, &display_name, size, &checksum, &encryption_key);
                            if (rc == 0) rc = VCursorCloseRow( cur );
                            if (rc != 0)
                                break;
                        }
                    }
                }
            }
            rc2 = VCursorRelease(cur);
            if (rc == 0)
                rc = rc2;
        }
        
        rc2 = VTableRelease(tbl);
        if (rc == 0)
            rc = rc2;
    }
    return rc;
}
示例#24
0
static 
rc_t LoadProjects( ProjectTable* data, const VDatabase* db )
{
    const VTable* tbl;
    rc_t rc = VDatabaseOpenTableRead(db, &tbl, "PROJECTS");
    if (rc == 0)
    {
        rc_t rc2;
        const VCursor *cur;

        rc = VTableCreateCachedCursorRead( tbl, &cur, CursorCacheSize );
        if (rc == 0)
        {
            uint32_t id_idx, name_idx, dl_idx, enc_idx;
            rc = VCursorAddColumn( cur, &id_idx,    "id" );
            if (rc == 0) rc = VCursorAddColumn( cur, &name_idx,  "name" );
            if (rc == 0) rc = VCursorAddColumn( cur, &dl_idx,    "download_ticket" );
            if (rc == 0) rc = VCursorAddColumn( cur, &enc_idx,   "encryption_key" );
            if (rc == 0 && HasData(tbl))
            {
                rc = VCursorOpen( cur );
                if (rc == 0)
                {
                    int64_t  first;
                    uint64_t count;
                    rc = VCursorIdRange( cur, 0, &first, &count );
                    if (rc == 0)
                    {
                        uint64_t i;
                        for (i=0; i < count; ++i)
                        {
                            const void* ptr;
                            uint32_t elem_count;
                            uint32_t id;
                            String name;
                            String download_ticket;
                            String encryption_key;

                            rc = VCursorSetRowId(cur, first + i);
                            if (rc == 0) rc = VCursorOpenRow( cur );
                            
                            if (rc == 0) rc = VCursorCellData( cur, id_idx, NULL, &ptr, NULL, NULL);
                            if (rc == 0) id = *(uint32_t*)ptr;
                            if (rc == 0) rc = VCursorCellData( cur, name_idx, NULL, &ptr, NULL, &elem_count);
                            if (rc == 0) StringInit(&name, (const char*)ptr, elem_count, elem_count);
                            if (rc == 0) rc = VCursorCellData( cur, dl_idx, NULL, &ptr, NULL, &elem_count);
                            if (rc == 0) StringInit(&download_ticket, (const char*)ptr, elem_count, elem_count);
                            if (rc == 0) rc = VCursorCellData( cur, enc_idx, NULL, &ptr, NULL, &elem_count);
                            if (rc == 0) StringInit(&encryption_key, (const char*)ptr, elem_count, elem_count);
                            
                            if (rc == 0) rc = KeyRingDataInsertProject(data, id, &name, &download_ticket, &encryption_key);
                            if (rc == 0) rc = VCursorCloseRow( cur );
                            if (rc != 0) 
                                break;
                        }
                    }
                }
            }
            rc2 = VCursorRelease(cur);
            if (rc == 0)
                rc = rc2;
        }
        
        rc2 = VTableRelease(tbl);
        if (rc == 0)
            rc = rc2;
    }
    return rc;
}
void CNativeTexture::SetData( void * data, void * palette )
{
	// It's pretty gross that we don't pass this in, or better yet, provide a way for
	// the caller to write directly to our buffers instead of setting the data.
	size_t data_len = GetBytesRequired();
	memcpy(mpData, data, data_len);

	if (mTextureFormat == TexFmt_CI4_8888)
	{
		memcpy(mpPalette, palette, kPalette4BytesRequired);
	}
	else if (mTextureFormat == TexFmt_CI8_8888)
	{
		memcpy(mpPalette, palette, kPalette8BytesRequired);
	}

	if (HasData())
	{
		glBindTexture( GL_TEXTURE_2D, mTextureId );
		glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );

		switch (mTextureFormat)
		{
		case TexFmt_5650:
			glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA,
						  mCorrectedWidth, mCorrectedHeight,
						  0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5_REV, data );
			break;
		case TexFmt_5551:
			glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA,
						  mCorrectedWidth, mCorrectedHeight,
						  0, GL_RGBA, GL_UNSIGNED_SHORT_1_5_5_5_REV, data );
			break;
		case TexFmt_4444:
			glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA,
						  mCorrectedWidth, mCorrectedHeight,
						  0, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4_REV, data );

			break;
		case TexFmt_8888:
			glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA,
						  mCorrectedWidth, mCorrectedHeight,
						  0, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, data );

			break;
		case TexFmt_CI4_8888:
			{
				// Convert palletised texture to non-palletised. This is wsteful - we should avoid generating these updated for OSX.
				const NativePfCI44 * pix_ptr = static_cast< const NativePfCI44 * >( data );
				const NativePf8888 * pal_ptr = static_cast< const NativePf8888 * >( palette );

				NativePf8888 * out = static_cast<NativePf8888 *>( malloc(mCorrectedWidth * mCorrectedHeight * sizeof(NativePf8888)) );
				NativePf8888 * out_ptr = out;

				u32 pitch = GetStride();

				for (u32 y = 0; y < mCorrectedHeight; ++y)
				{
					for (u32 x = 0; x < mCorrectedWidth; ++x)
					{
						NativePfCI44	colors  = pix_ptr[ x / 2 ];
						u8				pal_idx = (x&1) ? colors.GetIdxA() : colors.GetIdxB();

						*out_ptr = pal_ptr[ pal_idx ];
						out_ptr++;
					}

					pix_ptr = reinterpret_cast<const NativePfCI44 *>( reinterpret_cast<const u8 *>(pix_ptr) + pitch );
				}

				glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA,
							  mCorrectedWidth, mCorrectedHeight,
							  0, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, out );

				free(out);
			}
			break;

		case TexFmt_CI8_8888:
			{
				// Convert palletised texture to non-palletised. This is wsteful - we should avoid generating these updated for OSX.
				const NativePfCI8 *  pix_ptr = static_cast< const NativePfCI8 * >( data );
				const NativePf8888 * pal_ptr = static_cast< const NativePf8888 * >( palette );

				NativePf8888 * out = static_cast<NativePf8888 *>( malloc(mCorrectedWidth * mCorrectedHeight * sizeof(NativePf8888)) );
				NativePf8888 * out_ptr = out;

				u32 pitch = GetStride();

				for (u32 y = 0; y < mCorrectedHeight; ++y)
				{
					for (u32 x = 0; x < mCorrectedWidth; ++x)
					{
						u8	pal_idx = pix_ptr[ x ].Bits;

						*out_ptr = pal_ptr[ pal_idx ];
						out_ptr++;
					}

					pix_ptr = reinterpret_cast<const NativePfCI8 *>( reinterpret_cast<const u8 *>(pix_ptr) + pitch );
				}

				glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA,
							  mCorrectedWidth, mCorrectedHeight,
							  0, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, out );

				free(out);
			}
			break;

		default:
			DAEDALUS_ASSERT( !IsTextureFormatPalettised( mTextureFormat ), "Unhandled palette texture" );
			DAEDALUS_ASSERT( palette == NULL, "Palette provided when not needed" );
			break;
		}
	}
}
void AuxElement::CheckData()
{
	SetParentExtendedFlag(HasData());
}
示例#27
0
double MOCTriger::GetTransY(double dX,double dStmY)
{
	if(!HasData())
		return dStmY;
	return m_table.GetValue(dX,m_bRepeat);
}
void AuxPrimaryCategory::CheckData()
{
	SetParentExtendedFlag(HasData());
}
示例#29
0
bool
TexUnpackBlob::ConvertIfNeeded(WebGLContext* webgl, const char* funcName,
                               const uint8_t* srcBytes, uint32_t srcStride,
                               uint8_t srcBPP, WebGLTexelFormat srcFormat,
                               const webgl::DriverUnpackInfo* dstDUI,
                               const uint8_t** const out_bytes,
                               UniqueBuffer* const out_anchoredBuffer) const
{
    *out_bytes = srcBytes;

    if (!HasData() || !mWidth || !mHeight || !mDepth)
        return true;

    //////

    const auto totalSkipRows = mSkipRows + CheckedUint32(mSkipImages) * mImageHeight;
    const auto offset = mSkipPixels * CheckedUint32(srcBPP) + totalSkipRows * srcStride;
    if (!offset.isValid()) {
        webgl->ErrorOutOfMemory("%s: Invalid offset calculation during conversion.",
                                funcName);
        return false;
    }
    const uint32_t skipBytes = offset.value();

    auto const srcBegin = srcBytes + skipBytes;

    //////

    const auto srcOrigin = (webgl->mPixelStore_FlipY ? gl::OriginPos::TopLeft
                                                     : gl::OriginPos::BottomLeft);
    const auto dstOrigin = gl::OriginPos::BottomLeft;
    const bool isDstPremult = webgl->mPixelStore_PremultiplyAlpha;

    const auto pi = dstDUI->ToPacking();

    const auto dstBPP = webgl::BytesPerPixel(pi);
    const auto dstWidthBytes = CheckedUint32(dstBPP) * mWidth;
    const auto dstRowLengthBytes = CheckedUint32(dstBPP) * mRowLength;

    const auto dstAlignment = mAlignment;
    const auto dstStride = RoundUpToMultipleOf(dstRowLengthBytes, dstAlignment);

    //////

    const auto dstTotalRows = CheckedUint32(mDepth - 1) * mImageHeight + mHeight;
    const auto dstUsedSizeExceptLastRow = (dstTotalRows - 1) * dstStride;

    const auto dstSize = skipBytes + dstUsedSizeExceptLastRow + dstWidthBytes;
    if (!dstSize.isValid()) {
        webgl->ErrorOutOfMemory("%s: Invalid dstSize calculation during conversion.",
                                funcName);
        return false;
    }

    //////

    const auto dstFormat = FormatForPackingInfo(pi);

    bool premultMatches = (mIsSrcPremult == isDstPremult);
    if (!UnpackFormatHasColorAndAlpha(dstDUI->unpackFormat)) {
        premultMatches = true;
    }

    const bool needsPixelConversion = (srcFormat != dstFormat || !premultMatches);
    const bool originsMatch = (srcOrigin == dstOrigin);

    MOZ_ASSERT_IF(!needsPixelConversion, srcBPP == dstBPP);

    if (!needsPixelConversion &&
        originsMatch &&
        srcStride == dstStride.value())
    {
        // No conversion needed!
        return true;
    }

    //////
    // We need some sort of conversion, so create the dest buffer.

    *out_anchoredBuffer = calloc(1, dstSize.value());
    const auto dstBytes = (uint8_t*)out_anchoredBuffer->get();

    if (!dstBytes) {
        webgl->ErrorOutOfMemory("%s: Unable to allocate buffer during conversion.",
                                funcName);
        return false;
    }
    *out_bytes = dstBytes;
    const auto dstBegin = dstBytes + skipBytes;

    //////
    // Row conversion

    if (!needsPixelConversion) {
        webgl->GenerateWarning("%s: Incurred CPU row conversion, which is slow.",
                               funcName);

        const uint8_t* srcRow = srcBegin;
        uint8_t* dstRow = dstBegin;
        const auto widthBytes = dstWidthBytes.value();
        ptrdiff_t dstCopyStride = dstStride.value();

        if (!originsMatch) {
            dstRow += dstUsedSizeExceptLastRow.value();
            dstCopyStride = -dstCopyStride;
        }

        for (uint32_t i = 0; i < dstTotalRows.value(); i++) {
            memcpy(dstRow, srcRow, widthBytes);
            srcRow += srcStride;
            dstRow += dstCopyStride;
        }
        return true;
    }

    ////////////
    // Pixel conversion.

    MOZ_ASSERT(srcFormat != WebGLTexelFormat::FormatNotSupportingAnyConversion);
    MOZ_ASSERT(dstFormat != WebGLTexelFormat::FormatNotSupportingAnyConversion);

    webgl->GenerateWarning("%s: Incurred CPU pixel conversion, which is very slow.",
                           funcName);

    //////

    // And go!:
    bool wasTrivial;
    if (!ConvertImage(mWidth, dstTotalRows.value(),
                      srcBegin, srcStride, srcOrigin, srcFormat, mIsSrcPremult,
                      dstBegin, dstStride.value(), dstOrigin, dstFormat, isDstPremult,
                      &wasTrivial))
    {
        webgl->ErrorImplementationBug("%s: ConvertImage failed.", funcName);
        return false;
    }

    if (!wasTrivial) {
        webgl->GenerateWarning("%s: Chosen format/type incurred an expensive reformat:"
                               " 0x%04x/0x%04x",
                               funcName, dstDUI->unpackFormat, dstDUI->unpackType);
    }

    return true;
}
void AuxGroupMember::CheckData()
{
	SetParentExtendedFlag(HasData());
}