Beispiel #1
0
OSErr CPcx::initImageFromPCX(char *dataStart, UInt32 dataSize)
{
	OSErr myErr = noErr;
	unsigned char *palette;
	long filesize=0;
	char chartemp=0;
	unsigned char repeat=0, color=0;
	int x=0,y=0;
	short *ip;
	char *p;
	
	//
	// Get file length and make sure file is large enough to be a PCX
	//
	if (dataSize < 128) {
		myErr = kError_corruptdata;
		goto fail;
	}

	//
	// Check PCX manufacturer
	//
	p = dataStart;
	if (*p != 0xA) {
		myErr = kError_badversion;
		goto fail;
	}

		
	//
	// Get image dimensions
	//
	p = dataStart + 8;
	ip = (short*) p;
	
	UInt32 width = swapShort(*ip++);
	UInt32 height = swapShort(*ip++);

	//
	// Load 256 color palette.  Quit if not 256 colors (didn't bother adding support for 16 color pcx)
	//
	p = dataStart + dataSize - 769;
	if (!*p++ == 0xC) {
		myErr = kError_missingpalette;
		goto fail;
	}
	palette = (unsigned char*) p;
	p = dataStart + 128;
	return initImageFromPCXWithPalette(p, dataSize - (p-dataStart), width + 1, height + 1, palette);

fail:

	dprintf("could not load pcx\n");
	return myErr;	
}
/*
 * adfGetCacheEntry
 *
 * Returns a cache entry, starting from the offset p (the index into records[])
 * This offset is updated to the end of the returned entry.
 */
void adfGetCacheEntry(struct bDirCacheBlock *dirc, int *p, struct CacheEntry *cEntry)
{
    int ptr;

    ptr = *p;

/*printf("p=%d\n",ptr);*/

#ifdef LITT_ENDIAN
    cEntry->header = swapLong(dirc->records+ptr);
    cEntry->size = swapLong(dirc->records+ptr+4);
    cEntry->protect = swapLong(dirc->records+ptr+8);
    cEntry->days = swapShort(dirc->records+ptr+16);
    cEntry->mins = swapShort(dirc->records+ptr+18);
    cEntry->ticks = swapShort(dirc->records+ptr+20);
#else
    cEntry->header = Long(dirc->records+ptr);
    cEntry->size = Long(dirc->records+ptr+4);
    cEntry->protect = Long(dirc->records+ptr+8);
    cEntry->days = Short(dirc->records+ptr+16);
    cEntry->mins = Short(dirc->records+ptr+18);
    cEntry->ticks = Short(dirc->records+ptr+20);
#endif
    cEntry->type =(signed char) dirc->records[ptr+22];

    cEntry->nLen = dirc->records[ptr+23];
/*    cEntry->name = (char*)calloc(1,sizeof(char)*(cEntry->nLen+1));
    if (!cEntry->name)
         return;
*/    memcpy(cEntry->name, dirc->records+ptr+24, cEntry->nLen);
    cEntry->name[(int)(cEntry->nLen)]='\0';

    cEntry->cLen = dirc->records[ptr+24+cEntry->nLen];
    if (cEntry->cLen>0) {
/*        cEntry->comm =(char*)calloc(1,sizeof(char)*(cEntry->cLen+1));
        if (!cEntry->comm) {
            free( cEntry->name ); cEntry->name=NULL;
            return;
        }
*/        memcpy(cEntry->comm,dirc->records+ptr+24+cEntry->nLen+1,cEntry->cLen);
    }
        cEntry->comm[(int)(cEntry->cLen)]='\0';
/*printf("cEntry->nLen %d cEntry->cLen %d %s\n",cEntry->nLen,cEntry->cLen,cEntry->name);*/
    *p  = ptr+24+cEntry->nLen+1+cEntry->cLen;

    /* the starting offset of each record must be even (68000 constraint) */ 
    if ((*p%2)!=0)
        *p=(*p)+1;
}
Beispiel #3
0
//------------------------------------------------------------------------------
void swapAndCopySamples(short *srcBuffer, short *dstBuffer,
                        TINT32 sampleCount) {
  short *srcSample = srcBuffer;
  short *dstSample = dstBuffer;

  short *endSrcSample                           = srcSample + sampleCount;
  while (srcSample < endSrcSample) *dstSample++ = swapShort(*srcSample++);
}
Beispiel #4
0
int16_t
bigToNativeInt16(int16_t s)
{
	if(getEndianness() != ENDIANNESS_BIG)
		return swapShort(s);

	return s;
}
Beispiel #5
0
int16_t
littleToNativeInt16(int16_t s)
{
	if(getEndianness() == ENDIANNESS_BIG)
		return swapShort(s);

	return s;
}
Beispiel #6
0
static void outputBmp(const int width, const int height, 
		      unsigned char *color_array, const char *ofile){

  BmpHeader bmp;

  char bfType[2];
  bfType[0]          = 'B';
  bfType[1]          = 'M';
  bmp.bfSize         = width*height*3 + 54;
  bmp.bfReserved1    = 0;
  bmp.bfReserved2    = 0;
  bmp.bfOffBits      = 54;
  bmp.biSize         = 40;
  bmp.biWidth        = width;
  bmp.biHeight       = height;
  bmp.biPlanes       = 1;
  bmp.biBitCount     = 24;
  bmp.biCompression  = 0;
  bmp.biSizeImage    = 0;
  bmp.biXPixPerMeter = 0;
  bmp.biYPixPerMeter = 0;
  bmp.biClrUsed      = 0;
  bmp.biClrImporant  = 0;

#ifdef REVERSE_ENDIAN_OUTPUT
  bmp.bfSize         = swapInt(bmp.bfSize);
  bmp.bfOffBits      = swapInt(bmp.bfOffBits);
  bmp.biSize         = swapInt(bmp.biSize);
  bmp.biWidth        = swapInt(bmp.biWidth);
  bmp.biHeight       = swapInt(bmp.biHeight);
  bmp.biPlanes       = swapShort(bmp.biPlanes);
  bmp.biBitCount     = swapShort(bmp.biBitCount);
#endif

  FILE *outstream = fopen( ofile, "wb");
  fwrite( &bfType, sizeof(char), 2, outstream);
  fwrite( &bmp, sizeof(BmpHeader), 1, outstream);
  fwrite( color_array, sizeof(unsigned char), width*height*3, outstream);
  fclose( outstream);

}
Beispiel #7
0
/**
 * Reads a single fuel map (along with its multiplier factor) from the ECU
 * @param fuelMapId Index of the fuel map to read
 * @return True when the map was read successfully, false otherwise
 */
bool CUXInterface::readFuelMap(unsigned int fuelMapId)
{
    uint8_t *buffer = (uint8_t*)(m_fuelMaps[fuelMapId].data());
    uint16_t adjFactor = 0;
    bool status = false;

    if (c14cux_getFuelMap(&m_cuxinfo, (int8_t)fuelMapId, &adjFactor, &m_rowScaler, buffer) &&
        c14cux_readMem(&m_cuxinfo, C14CUX_MAFRowScalerOffset, 2, (uint8_t*)&m_mafScaler))
    {
        m_mafScaler = swapShort(m_mafScaler);
        m_fuelMapAdjFactors[fuelMapId] = adjFactor;
        m_fuelMapDataIsCurrent[fuelMapId] = true;
        status = true;
    }

    return status;
}
Beispiel #8
0
int main (int argc, const char *argv[])
{
	/* file buffers */
	int fp;
	char globalHeaderContent[sizeof(pcap_hdr_t)];
	char recordHeaderContent[sizeof(pcaprec_hdr_t)];
	char buffer[READ_BUFFER_SIZE];

	/* headers, headers, headers... */
	pcap_hdr_t* globalHeader = (pcap_hdr_t*) globalHeaderContent;
	pcaprec_hdr_t* recordHeader = (pcaprec_hdr_t*) recordHeaderContent;
	ether_header_t* etherHeader;
	ipv4_header_t* ipv4Header;
	udp_header_t* udpHeader;

	/* record count */
	unsigned int recordCount = 0;





	/* checking file input */
	if (argc<1) 
	{
		fprintf(stderr, "Error: No file input.\n");
		return 1;
	}

	/* file opening */
	fp = open(argv[1], O_RDONLY);
	if (fp == -1)
	{
		fprintf(stderr, "Error: Cannot open file.\n");
		return 2;
	}





	/* applying global header data structure */
	if (!fetchGlobalHeader(fp, globalHeader))
	{
		fprintf(stderr, "Error: File format not correct\n");
		return 4;
	}

	/* printing global header information */
	printf ("ver=%d.%d snaplen=%d network=%d\n",
		swapShort(globalHeader->version_major),
		swapShort(globalHeader->version_minor),
		swapInt(globalHeader->snaplen),
		swapInt(globalHeader->network));





	/* per-packet information */
	while(fetchRecordHeader(fp, recordHeader))
	{
		recordCount += 1;

		/* read file */
		read (fp, buffer, swapInt(recordHeader->incl_len));


		/* applying data structures */
		etherHeader = (ether_header_t *) (buffer);
		ipv4Header = (ipv4_header_t *) (buffer
				+sizeof(ether_header_t));



		/* printing
		 * 1234567890.098765 100/100 123.45.67.89 -> 98.76.54.32 (17) sport=12345 dport=9876 */
		printf ("%u.%06u %u/%u", 
				swapInt (recordHeader->ts_sec),
				swapInt (recordHeader->ts_usec),
				swapInt (recordHeader->incl_len),
				swapInt (recordHeader->orig_len)
			);
		printf (" %s", inet_ntoa (ipv4Header->ip_src));
		printf (" -> %s", inet_ntoa (ipv4Header->ip_dst));
		printf (" (%u)", ipv4Header->ip_p);



		/* UDP-specific information */
		if (ipv4Header->ip_p == 17)
		{

			/* applying UDP header data structure */
			udpHeader = (udp_header_t *) (buffer
					+ sizeof (ether_header_t)
					+ sizeof (ipv4_header_t));

			/* printing */
			printf(" sport=%u dport=%u",
					ntohs (udpHeader->port_src),
					ntohs (udpHeader->port_dst)
			      );

		}


		/* new line */
		printf("\n");
	}

	printf ("total %d packets read\n", recordCount);







	close(fp);

	return 0;
}