Esempio n. 1
0
void AGOSEngine::loadVoice(uint speechId) {
	if (getGameType() == GType_PP && speechId == 99) {
		_sound->stopVoice();
		return;
	}

	if (getFeatures() & GF_ZLIBCOMP) {
		char filename[15];

		uint32 file, offset, srcSize, dstSize;
		if (getPlatform() == Common::kPlatformAmiga) {
			loadOffsets((const char*)"spindex.dat", speechId, file, offset, srcSize, dstSize);
		} else {
			loadOffsets((const char*)"speech.wav", speechId, file, offset, srcSize, dstSize);
		}

		// Voice segment doesn't exist
		if (offset == 0xFFFFFFFF && srcSize == 0xFFFFFFFF && dstSize == 0xFFFFFFFF) {
			debug(0, "loadVoice: speechId %d removed", speechId);
			return;
		}

		if (getPlatform() == Common::kPlatformAmiga)
			sprintf(filename, "sp%d.wav", file);
		else
			sprintf(filename, "speech.wav");

		byte *dst = (byte *)malloc(dstSize);
		decompressData(filename, dst, offset, srcSize, dstSize);
		_sound->playVoiceData(dst, speechId);
	} else {
		_sound->playVoice(speechId);
	}
}
void BinaryEchoParser::convertCompressedDataToAverage(int nRange, char* compressedBuffer, int nCompressedLength, char* averageBuffer) {
	//printf("start convertCompressedDataToAverage\n");
	char decomprBuffer[6000]; //TODO: 6000 or more?
	int nDecompressedLength = 0;

	decompressData(compressedBuffer, nCompressedLength, decomprBuffer, &nDecompressedLength);
// printf("decompressed len: %d\n", nDecompressedLength);
	unsigned int nCountPerMeassurment;
	unsigned int nSum = 0;

	if (nDecompressedLength <= 0) {
		printf("!!!!!!!!!!!!!!!!!!! received length <= 0\n");
		return;
	}

	int rangeLength[] = {10, 50, 100, 500, 1000, 1600}; //TODO: wrong place for this array

	// !!! Here is assuming that data from simulator applies to depth of 1600m.
	nCountPerMeassurment = ((unsigned int)nDecompressedLength - (unsigned int)nDecompressedLength*rangeLength[nRange]/1600)/ VERT_RESOLUTION;



	for (int i = 0; i < VERT_RESOLUTION; i++) {
		nSum = 0;
		for (int j = 0; j < (int)nCountPerMeassurment; j++) {
			nSum += decomprBuffer[i * nCountPerMeassurment + j];
		}


		averageBuffer[i] = (char)(nSum / nCountPerMeassurment);
	}
	//printf("end convertCompressedDataToAverage\n");
}
Esempio n. 3
0
 void Decompressor_M1::decompressData(
     std::vector< std::vector< unsigned char > >& outBuf,
     const std::vector< unsigned char >& inBuf)
 {
   outBuf.clear();
   std::vector< unsigned char >  tmpOutBuf;
   decompressData(tmpOutBuf, inBuf);
   // NOTE: this format does not support start addresses,
   // so use a fixed value of 0100H (program with EXOS 5 header)
   tmpOutBuf.insert(tmpOutBuf.begin(), 2, (unsigned char) 0x00);
   tmpOutBuf[1] = 0x01;
   outBuf.push_back(tmpOutBuf);
 }
Esempio n. 4
0
void AGOSEngine::loadSound(uint16 sound, int16 pan, int16 vol, uint16 type) {
	byte *dst;

	if (getGameId() == GID_DIMP) {
		Common::File in;
		char filename[15];

		assert(sound >= 1 && sound <= 32);
		sprintf(filename, "%s.wav", dimpSoundList[sound - 1]);

		in.open(filename);
		if (in.isOpen() == false)
			error("loadSound: Can't load %s", filename);

		uint32 dstSize = in.size();
		dst = (byte *)malloc(dstSize);
		if (in.read(dst, dstSize) != dstSize)
			error("loadSound: Read failed");
		in.close();
	} else if (getFeatures() & GF_ZLIBCOMP) {
		char filename[15];

		uint32 file, offset, srcSize, dstSize;
		if (getPlatform() == Common::kPlatformAmiga) {
			loadOffsets((const char*)"sfxindex.dat", _zoneNumber * 22 + sound, file, offset, srcSize, dstSize);
		} else {
			loadOffsets((const char*)"effects.wav", _zoneNumber * 22 + sound, file, offset, srcSize, dstSize);
		}

		if (getPlatform() == Common::kPlatformAmiga)
			sprintf(filename, "sfx%d.wav", file);
		else
			sprintf(filename, "effects.wav");

		dst = (byte *)malloc(dstSize);
		decompressData(filename, dst, offset, srcSize, dstSize);
	} else {
		if (_curSfxFile == NULL)
			return;

		dst = _curSfxFile + READ_LE_UINT32(_curSfxFile + sound * 4);
	}

	if (type == Sound::TYPE_AMBIENT)
		_sound->playAmbientData(dst, sound, pan, vol);
	else if (type == Sound::TYPE_SFX)
		_sound->playSfxData(dst, sound, pan, vol);
	else if (type == Sound::TYPE_SFX5)
		_sound->playSfx5Data(dst, sound, pan, vol);
}
Esempio n. 5
0
void
CGIFImage::
readAnimData(CFile *file, CGenImage *proto, CGIFAnim *image_anim, CGIFImageData *gif_data)
{
    int  inum              = 0;
    int  delay             = 0;
    bool transparent       = false;
    uint transparent_color = 0;
    int  dispose           = 0;
    int  user_input        = 0;

    uint file_size = file->getSize();

    while (true) {
        uchar id;

        try {
            if (! file->read(&id, 1))
                break;
        }
        catch (...) {
            break;
        }

        if      (id == IMAGE_ID) {
            ++inum;

            if (CGIFImage::getDebug())
                std::cerr << "Image Id" << std::endl;

            CGIFImageImageHeader *image_header = new CGIFImageImageHeader;

            try {
                uchar byte1;
                uchar byte2;

                file->read(&byte1, 1);
                file->read(&byte2, 1);

                image_header->left = (byte2 << 8) | byte1;

                file->read(&byte1, 1);
                file->read(&byte2, 1);

                image_header->top = (byte2 << 8) | byte1;

                file->read(&byte1, 1);
                file->read(&byte2, 1);

                image_header->width = (byte2 << 8) | byte1;

                file->read(&byte1, 1);
                file->read(&byte2, 1);

                image_header->height = (byte2 << 8) | byte1;

                file->read(&image_header->flags, 1);

                image_header->local_color_table = (image_header->flags >> 7) & 0x01;
                image_header->interlaced        = (image_header->flags >> 6) & 0x01;
                image_header->colors_sorted     = (image_header->flags >> 5) & 0x01;
                image_header->color_bits        = (image_header->flags     ) & 0x07;

                if (CGIFImage::getDebug()) {
                    std::cerr << "Left          " << image_header->left << std::endl;
                    std::cerr << "Top           " << image_header->top << std::endl;
                    std::cerr << "Width         " << image_header->width << std::endl;
                    std::cerr << "Height        " << image_header->height << std::endl;
                    std::cerr << "Local Colors  " << image_header->local_color_table << std::endl;
                    std::cerr << "Interlaced    " << image_header->interlaced << std::endl;
                    std::cerr << "Colors Sorted " << image_header->colors_sorted << std::endl;
                    std::cerr << "Num Colors    " << (1 << (image_header->color_bits + 1)) << std::endl;
                }

                if (image_header->local_color_table &&
                        image_header->color_bits > 0) {
                    gif_data->num_local_colors = 1 << (image_header->color_bits + 1);

                    gif_data->local_colors = new CGIFImageColorTable [gif_data->num_local_colors];

                    for (int i = 0; i < gif_data->num_local_colors; ++i)
                        file->read((uchar *) &gif_data->local_colors[i], 3);

                    if (CGIFImage::getDebug()) {
                        for (int i = 0; i < gif_data->num_local_colors; ++i)
                            std::cerr << gif_data->local_colors[i].r << " " <<
                                      gif_data->local_colors[i].g << " " <<
                                      gif_data->local_colors[i].b << std::endl;
                    }
                }

                file->read(&compress_data.code_size, 1);

                compress_data.clear_code = 1 << compress_data.code_size;
                compress_data.eof_code   = compress_data.clear_code + 1;
                compress_data.free_code  = compress_data.clear_code + 2;

                ++compress_data.code_size;

                compress_data.init_code_size = compress_data.code_size;

                compress_data.max_code  = 1 << compress_data.code_size;
                compress_data.code_mask = compress_data.max_code - 1;

                uint num_image_bytes = image_header->width*image_header->height;

                uchar *data = new uchar [file_size];

                uchar size;

                file->read(&size, 1);

                uint num_bytes_read = 0;

                while (size > 0) {
                    while (size--) {
                        file->read(&data[num_bytes_read], 1);

                        ++num_bytes_read;
                    }

                    file->read(&size, 1);
                }

                if (num_bytes_read < file_size)
                    memset(&data[num_bytes_read], 0, file_size - num_bytes_read);

                //------

                uchar *raw_data = new uchar [num_image_bytes];

                decompressData(data, num_bytes_read, raw_data, num_image_bytes);

                delete [] data;

                if (image_header->interlaced)
                    deInterlace(raw_data, image_header);

                //------

                CGenImage *image = proto->dup();

                image->setType(CFILE_TYPE_IMAGE_GIF);

                image->setColormap(true);

                image->setDataSize(image_header->width, image_header->height);

                int bottom = gif_data->header->height - image_header->height - image_header->top;
                int right  = gif_data->header->width  - image_header->width  - image_header->left;

                //image->setBorder(image_header->left, bottom, right, image_header->top);
                if (bottom != 0 || right != 0) std::cerr << "Unhandled border" << std::endl;

                if (gif_data->num_local_colors > 0) {
                    for (int i = 0; i < gif_data->num_local_colors; ++i) {
                        CRGBA rgba;

                        rgba.setRGBAI(gif_data->local_colors[i].r,
                                      gif_data->local_colors[i].g,
                                      gif_data->local_colors[i].b);

                        image->addColor(rgba);
                    }
                }
                else {
                    for (int i = 0; i < gif_data->num_global_colors; ++i) {
                        CRGBA rgba;

                        rgba.setRGBAI(gif_data->global_colors[i].r,
                                      gif_data->global_colors[i].g,
                                      gif_data->global_colors[i].b);

                        image->addColor(rgba);
                    }

                    //image->setBackground(image->getColor(gif_data->header->background));
                }

                //------

                if (transparent)
                    image->setTransparentColor(transparent_color);

                //------

                for (int y = 0, k = 0; y < image_header->height; ++y)
                    for (int x = 0; x < image_header->width; ++x, ++k)
                        image->setColorIndex(x, y, raw_data[k]);

                delete [] raw_data;

                //------

                CGIFFrame *frame = new CGIFFrame(image);

                frame->setDelay(delay);
                frame->setDispose(dispose);
                frame->setUserInput(user_input);

                image_anim->add(frame);

                //------

                delay             = 0;
                transparent       = false;
                transparent_color = 0;
                dispose           = 0;
                user_input        = 0;

                //------

                delete image_header;

                image_header = NULL;
            }
            catch (...) {
                delete image_header;

                CTHROW("Failed to read GIF file");
            }
        }
        else if (id == CONTROL_ID) {
Esempio n. 6
0
bool
CImageGIF::
readAnimData(CFile *file, CImageAnim *image_anim, CImageGIFData *gif_data)
{
  int  inum              = 0;
  int  delay             = 0;
  bool transparent       = false;
  uint transparent_color = 0;
  int  dispose           = 0;
  int  user_input        = 0;

  uint file_size = file->getSize();

  while (true) {
    uchar id;

    try {
      if (! file->read(&id, 1))
        break;
    }
    catch (...) {
      break;
    }

    if      (id == IMAGE_ID) {
      ++inum;

      if (CImageState::getDebug())
        CImage::infoMsg("Image Id");

      CImageGIFImageHeader *image_header = new CImageGIFImageHeader;

      try {
        uchar byte1;
        uchar byte2;

        file->read(&byte1, 1);
        file->read(&byte2, 1);

        image_header->left = (byte2 << 8) | byte1;

        file->read(&byte1, 1);
        file->read(&byte2, 1);

        image_header->top = (byte2 << 8) | byte1;

        file->read(&byte1, 1);
        file->read(&byte2, 1);

        image_header->width = (byte2 << 8) | byte1;

        file->read(&byte1, 1);
        file->read(&byte2, 1);

        image_header->height = (byte2 << 8) | byte1;

        file->read(&image_header->flags, 1);

        image_header->local_color_table = (image_header->flags >> 7) & 0x01;
        image_header->interlaced        = (image_header->flags >> 6) & 0x01;
        image_header->colors_sorted     = (image_header->flags >> 5) & 0x01;
        image_header->color_bits        = (image_header->flags     ) & 0x07;

        if (CImageState::getDebug()) {
          CImage::infoMsg("Left          " + std::to_string(image_header->left));
          CImage::infoMsg("Top           " + std::to_string(image_header->top));
          CImage::infoMsg("Width         " + std::to_string(image_header->width));
          CImage::infoMsg("Height        " + std::to_string(image_header->height));
          CImage::infoMsg("Local Colors  " + std::to_string(image_header->local_color_table));
          CImage::infoMsg("Interlaced    " + std::to_string(image_header->interlaced));
          CImage::infoMsg("Colors Sorted " + std::to_string(image_header->colors_sorted));
          CImage::infoMsg("Num Colors    " + std::to_string(1 << (image_header->color_bits + 1)));
        }

        if (image_header->local_color_table &&
            image_header->color_bits > 0) {
          gif_data->num_local_colors = 1 << (image_header->color_bits + 1);

          gif_data->local_colors = new CImageGIFColorTable [gif_data->num_local_colors];

          for (int i = 0; i < gif_data->num_local_colors; ++i)
            file->read((uchar *) &gif_data->local_colors[i], 3);

          if (CImageState::getDebug()) {
            for (int i = 0; i < gif_data->num_local_colors; ++i)
              CImage::infoMsg(std::to_string(gif_data->local_colors[i].r) + " " +
                              std::to_string(gif_data->local_colors[i].g) + " " +
                              std::to_string(gif_data->local_colors[i].b));
          }
        }

        file->read(&compress_data.code_size, 1);

        compress_data.clear_code = 1 << compress_data.code_size;
        compress_data.eof_code   = compress_data.clear_code + 1;
        compress_data.free_code  = compress_data.clear_code + 2;

        ++compress_data.code_size;

        compress_data.init_code_size = compress_data.code_size;

        compress_data.max_code  = 1 << compress_data.code_size;
        compress_data.code_mask = compress_data.max_code - 1;

        uint num_image_bytes = image_header->width*image_header->height;

        uchar *data = new uchar [file_size];

        uchar size;

        file->read(&size, 1);

        uint num_bytes_read = 0;

        while (size > 0) {
          while (size--) {
            file->read(&data[num_bytes_read], 1);

            ++num_bytes_read;
          }

          file->read(&size, 1);
        }

        if (num_bytes_read < file_size)
          memset(&data[num_bytes_read], 0, file_size - num_bytes_read);

        //------

        uchar *raw_data = new uchar [num_image_bytes];

        decompressData(data, num_bytes_read, raw_data, num_image_bytes);

        delete [] data;

        if (image_header->interlaced)
          deInterlace(raw_data, image_header);

        //------

        CImageNameSrc src("CImageGIF:" + file->getPath() + "/" + CStrUtil::toString(inum));

        CImagePtr image = CImageMgrInst->createImage(src);

        image->setType(CFILE_TYPE_IMAGE_GIF);

        image->setDataSize(image_header->width, image_header->height);

        int bottom = gif_data->header->height - image_header->height - image_header->top;
        int right  = gif_data->header->width  - image_header->width  - image_header->left;

        image->setBorder(image_header->left, bottom, right, image_header->top);

        if (gif_data->num_local_colors > 0) {
          for (int i = 0; i < gif_data->num_local_colors; ++i)
            image->addColorI(gif_data->local_colors[i].r,
                             gif_data->local_colors[i].g,
                             gif_data->local_colors[i].b);
        }
        else {
          for (int i = 0; i < gif_data->num_global_colors; ++i)
            image->addColorI(gif_data->global_colors[i].r,
                             gif_data->global_colors[i].g,
                             gif_data->global_colors[i].b);

          image->setBackground(image->getColor(gif_data->header->background));
        }

        //------

        if (transparent)
          image->setTransparentColor(transparent_color);

        //------

        image->setColorIndexData(raw_data);

        delete [] raw_data;

        //------

        CImageFrame *frame = new CImageFrame(image);

        frame->setDelay(delay);
        frame->setDispose(dispose);
        frame->setUserInput(user_input);

        image_anim->add(frame);

        //------

        delay             = 0;
        transparent       = false;
        transparent_color = 0;
        dispose           = 0;
        user_input        = 0;

        //------

        delete image_header;

        image_header = 0;
      }
      catch (...) {
        delete image_header;

        CImage::errorMsg("Failed to read GIF file");

        return false;
      }
    }
    else if (id == CONTROL_ID) {
/**
 * BmpDecoderReadImage
 * 
 * Decode the content of a bmp file. 
 *
 * in    : the input stream
 * image : a pointer to a ng_bitmap_image_t
 *
 * return: ERR_OK if the image was correctly built from the input stream
 *		   ERR_NG otherwise.
 */
ng_err_t NgBmpDecoderReadImage (ng_stream_t *in, ng_bitmap_image_t *image)
{
	BYTE4 *fileHeader = (BYTE4*) NgMalloc (5 * sizeof(BYTE4));
	BYTE1 *infoHeader, *data;
	BYTE4 width, height, stride, dataSize, cmp, pos;	
	BYTE2 depth;
	BYTE2 d0;
	
	NgStreamRead (in, (char *) &d0, sizeof(BYTE2));
	fileHeader[0] = (BYTE4)LittleEndianToSystemUBYTE2(d0);
	NgStreamRead (in, (char *) &fileHeader[1], sizeof(BYTE4));
	fileHeader[1] = LittleEndianToSystemUBYTE4(fileHeader[1]);
	NgStreamRead (in, (char *) &d0, sizeof(BYTE2));
	fileHeader[2] = (BYTE4)LittleEndianToSystemUBYTE2(d0);
	NgStreamRead (in, (char *) &d0, sizeof(BYTE2));
	fileHeader[3] = (BYTE4)LittleEndianToSystemUBYTE2(d0);
	NgStreamRead (in, (char *) &fileHeader[4], sizeof(BYTE4));
	fileHeader[4] = LittleEndianToSystemUBYTE4(fileHeader[4]);
	
	if (NgStreamEof (in))
	{
		NgFree (fileHeader);
		return NgError (ERR_NG, "Error invalid header file");
	}
	if (fileHeader[0] != 0x4D42)
	{
		NgFree (fileHeader);
		return NgError (ERR_NG, "Error not a BMP file");
	}
	
	infoHeader = (BYTE1*) NgMalloc (BMPHeaderFixedSize * sizeof (BYTE1));	
	NgStreamRead (in, infoHeader, BMPHeaderFixedSize * sizeof (BYTE1));
	
	if (NgStreamEof (in))
	{
		NgFree (fileHeader);
		NgFree (infoHeader);
		return NgError (ERR_NG, "Error invalid info header");
	}
	
	NgMemCpy (&width, &infoHeader[4], sizeof (BYTE4));
	width = LittleEndianToSystemUBYTE4(width);

	NgMemCpy (&height, &infoHeader[8], sizeof (BYTE4));
	height = LittleEndianToSystemUBYTE4(height);
	
	NgMemCpy (&depth, &infoHeader[14], sizeof (BYTE2));
	depth = LittleEndianToSystemUBYTE2(depth);

	stride = (width * depth + 7) / 8;
	stride = (stride + 3) / 4 * 4; /* Round up to 4 byte multiple */

	if (depth <= 8)
	{
		BYTE4 i, index;
		BYTE1 *colors;
		BYTE4 numColors;
		NgMemCpy (&numColors, &infoHeader[32], sizeof (BYTE4));
		numColors = LittleEndianToSystemUBYTE4(numColors);
		if (numColors == 0)
		{
			BYTE2 value;
			NgMemCpy (&value, &infoHeader[14], sizeof (BYTE2));
			value = LittleEndianToSystemUBYTE2(value);
			numColors = 1 << value;
		} else
		{
			if (numColors > 256)
				numColors = 256;
		}
		colors = (BYTE1*) NgMalloc (numColors * 4);
		NgStreamRead (in, colors, numColors * 4);
		
		if (NgStreamEof (in))
		{
			NgFree (fileHeader);
			NgFree (infoHeader);
			NgFree (colors);
			return NgError (ERR_NG, "Error invalid palette info");
		} 
		
		index = 0;
		
		NgBitmapImageSetSize(image, (UBYTE4)numColors, (UBYTE4)depth,
			(UBYTE4)width, (UBYTE4)height);
			
		for (i = 0; i < numColors; i++)
		{
			ng_color_map_entry_t *color_map = NgBitmapImageColorMap (image, i);
			color_map->blue = colors[index++];
			color_map->green = colors[index++];
			color_map->red = colors[index++];
			index++;
		}
		
		NgFree (colors);
	} else
	{
		/* direct - 16 and 24 bits */
		NgBitmapImageSetSize(image, 0, (UBYTE4)depth,
			(UBYTE4)width, (UBYTE4)height);
	}
	
	pos = NgStreamGetPosition (in);
	if (pos < fileHeader[4])
	{
		NgStreamSkip (in, fileHeader[4] - pos);
	}
	
	dataSize = height * stride;
	
	data = (BYTE1*)NgBitmapImageImageData(image);
	NgMemCpy (&cmp, &infoHeader[16], sizeof (BYTE4));
	cmp = LittleEndianToSystemUBYTE4(cmp);
	if (cmp == 0)
	{
		/* BMP_NO_COMPRESSION */
		BYTE4 cnt;
		cnt = NgStreamRead (in, data, dataSize);
		if (cnt != dataSize)
		{
			NgFree (fileHeader);
			NgFree (infoHeader);
			return NgError (ERR_NG, "Error failed reading uncompressed data");
		}
	} else
	{
		BYTE4 compressedSize;
		BYTE1 *compressed;
		BYTE4 cnt;
		ng_err_t res;
		NgMemCpy (&compressedSize, &infoHeader[20], sizeof (BYTE4));
		compressedSize = LittleEndianToSystemUBYTE4(compressedSize);
		compressed = (BYTE1*) NgMalloc (compressedSize * sizeof (BYTE1));
		cnt = NgStreamRead (in, compressed, compressedSize);
		if (cnt != compressedSize)
		{
			NgFree (fileHeader);
			NgFree (infoHeader);
			NgFree (compressed);
			return NgError (ERR_NG, "Error failed reading compressed data");
		}
		res = decompressData (compressed, compressedSize, data, dataSize, stride, cmp);
		if (res != ERR_OK)
		{
			NgFree (fileHeader);
			NgFree (infoHeader);
			NgFree (compressed);
			return NgError (res, "Error failed data decompression");			
		}
				
		NgFree (compressed);
	}
		
	flipScanLines(data, dataSize, stride, height);
	
	NgFree (fileHeader);
	NgFree (infoHeader);
	return ERR_OK;
}