Exemplo n.º 1
0
GIF_RETVAL readExtension(JNIEnv *env, GifDecoder *decoder, jobject currBlock) {
    unsigned char extensionSize = *(decoder->inputPtr+2);
    unsigned char extensionType;

    if(decoder->bytesInBuffer < extensionSize + 3) { // Stop, we need more data
        return STATUS_BUFFER_EMPTY;
    }

    decoder->inputPtr++; // Skip extension introducer

    extensionType = *(decoder->inputPtr);
    decoder->inputPtr += 2; // Skip size, already got it
    decoder->bytesInBuffer -= 3; // Decrease buffer size as we advanced

    switch(extensionType) {
    case GRAPHIC_CONTROL_EXTENSION:
        readGraphicControl(env, decoder, currBlock);
        break;

    case COMMENT_EXTENSION: {
        decoder->inputPtr -= 1; // No extension size, usual sub-blocks, go back
        decoder->bytesInBuffer += 1;
        decoder->state = STATE_READING_COMMENT;
        return readComment(env, decoder);
    }

    case APPLICATION_EXTENSION:
        if(extensionSize == SIZE_NETSCAPE_EXT &&
                !strncmp(decoder->inputPtr, "NETSCAPE2.0", SIZE_NETSCAPE_EXT)) {
            if(*(decoder->inputPtr + extensionSize) == 3) { // Magic size of the sub-block in netscape ext
                unsigned short loopCount;
                decoder->inputPtr += extensionSize;
                decoder->bytesInBuffer -= extensionSize;
                loopCount = *((unsigned short *) (decoder->inputPtr+2));
                (*env)->SetIntField(env, decoder->jDataStream, img_GIF_ds_loopCountID, loopCount);
                return skipData(decoder);
            } // If the extension is invalid proceed to default
        }

    case PLAIN_TEXT_EXTENSION:
    default:
        decoder->inputPtr += extensionSize;
        decoder->bytesInBuffer -= extensionSize;
        if(!(*(decoder->inputPtr))) { // No additional data
            decoder->inputPtr++;
            decoder->bytesInBuffer--;
            decoder->state = STATE_BLOCK_BEGINNING;
        } else {
            decoder->state = STATE_SKIPPING_BLOCKS;
            return skipData(decoder);
        }
    }

    return STATUS_OK;
}
Exemplo n.º 2
0
//------------------------------------------------------------------------------------------------
std::string readString( char * & data ) {
    int strCount = readData<int>( data );
    boost::shared_ptr<char> p( new char[strCount+1] );
    memset( p.get(), 0, strCount+1 );
    memcpy( p.get(), data, strCount );
    std::string str = p.get();
    skipData( data, strCount );
    return str;
}
Exemplo n.º 3
0
/** This method creates outputworkspace excluding monitors
 *@param file :: -pointer to file
 *@param period :: period number
 *@param monitorList :: a list containing the spectrum numbers for monitors
 *@param ws_sptr :: shared pointer to workspace
 */
void LoadRaw3::excludeMonitors(FILE *file, const int &period,
                               const std::vector<specnum_t> &monitorList,
                               DataObjects::Workspace2D_sptr ws_sptr) {
  int64_t histCurrent = -1;
  int64_t wsIndex = 0;
  double histTotal = static_cast<double>(m_total_specs * m_numberOfPeriods);
  // loop through the spectra
  for (specnum_t i = 1; i <= m_numberOfSpectra; ++i) {
    specnum_t histToRead = i + period * (m_numberOfSpectra + 1);
    if ((i >= m_spec_min && i < m_spec_max) ||
        (m_list &&
         find(m_spec_list.begin(), m_spec_list.end(), i) !=
             m_spec_list.end())) {
      progress(m_prog, "Reading raw file data...");
      // skip monitor spectrum
      if (isMonitor(monitorList, i)) {
        skipData(file, histToRead);
        continue;
      }

      // read spectrum
      if (!readData(file, histToRead)) {
        throw std::runtime_error("Error reading raw file");
      }
      // set the workspace data
      setWorkspaceData(ws_sptr, m_timeChannelsVec, wsIndex, i, m_noTimeRegimes,
                       m_lengthIn, 1);
      // increment workspace index
      ++wsIndex;

      if (m_numberOfPeriods == 1) {
        if (++histCurrent % 100 == 0) {
          setProg(static_cast<double>(histCurrent) / histTotal);
        }
        interruption_point();
      }

    } // end of if loop for spec min,max check
    else {
      skipData(file, histToRead);
    }
  } // end of for loop
}
Exemplo n.º 4
0
void skipUselessChucks( WavFileHeader& header, QFile& file )
{
    // We only care about the 'data' chuck
    while ( memcmp( header.dataChuckID, "data", 4 ) != 0 )
    {
        int skipByteCount = header.dataSize;
        std::vector<char> skipData( skipByteCount );
        file.read( skipData.data(), skipByteCount );

        file.read( (char*)&header.dataChuckID, 4 );
        file.read( (char*)&header.dataSize, 4 );
    }
}
Exemplo n.º 5
0
void LoadRaw3::separateMonitors(FILE *file, const int64_t &period,
                                const std::vector<specnum_t> &monitorList,
                                DataObjects::Workspace2D_sptr ws_sptr,
                                DataObjects::Workspace2D_sptr mws_sptr) {
  int64_t histCurrent = -1;
  int64_t wsIndex = 0;
  int64_t mwsIndex = 0;
  double histTotal = static_cast<double>(m_total_specs * m_numberOfPeriods);
  // loop through spectra
  for (specnum_t i = 1; i <= m_numberOfSpectra; ++i) {
    int64_t histToRead = i + period * (m_numberOfSpectra + 1);
    if ((i >= m_spec_min && i < m_spec_max) ||
        (m_list &&
         find(m_spec_list.begin(), m_spec_list.end(), i) !=
             m_spec_list.end())) {
      progress(m_prog, "Reading raw file data...");

      // read spectrum from raw file
      if (!readData(file, histToRead)) {
        throw std::runtime_error("Error reading raw file");
      }
      // if this a monitor  store that spectrum to monitor workspace
      if (isMonitor(monitorList, i)) {
        setWorkspaceData(mws_sptr, m_timeChannelsVec, mwsIndex, i,
                         m_noTimeRegimes, m_lengthIn, 1);
        ++mwsIndex;
      } else {
        // not a monitor,store the spectrum to normal output workspace
        setWorkspaceData(ws_sptr, m_timeChannelsVec, wsIndex, i,
                         m_noTimeRegimes, m_lengthIn, 1);
        ++wsIndex;
      }

      if (m_numberOfPeriods == 1) {
        if (++histCurrent % 100 == 0) {
          setProg(static_cast<double>(histCurrent) / histTotal);
        }
        interruption_point();
      }

    } else {
      skipData(file, histToRead);
    }
  }
}
Exemplo n.º 6
0
bool PlaylistImporter::parsePlaylist_wpl(QFile &data, QStringList &fileList, const QDir &baseDir, const QDir &rootDir)
{
	bool foundAtLeastOneFile = false;

	QRegExp skipData("<!--(.+)-->", Qt::CaseInsensitive);
	QRegExp wplEntry("<(media|ref)[^<>]*(src|href)=\"([^\"]+)\"[^<>]*>", Qt::CaseInsensitive);
	
	skipData.setMinimal(true);

	QByteArray buffer = data.readAll();
	QString line = QString::fromUtf8(buffer.constData(), buffer.size()).simplified();
	buffer.clear();

	int index = 0;

	while((index = skipData.indexIn(line)) >= 0)
	{
		line.remove(index, skipData.matchedLength());
	}

	int offset = 0;

	while((offset = wplEntry.indexIn(line, offset) + 1) > 0)
	{
		QFileInfo filename(QDir::fromNativeSeparators(unescapeXml(wplEntry.cap(3)).trimmed()));
		filename.setCaching(false);
		fixFilePath(filename, baseDir, rootDir);

		if(filename.exists() && filename.isFile())
		{
			if(isPlaylist(filename.canonicalFilePath()) == notPlaylist)
			{
				fileList << filename.canonicalFilePath();
				foundAtLeastOneFile = true;
			}
		}
	}

	return foundAtLeastOneFile;
}
Exemplo n.º 7
0
/**This method creates outputworkspace including monitors
 *@param file :: -pointer to file
 *@param period :: period number
 *@param ws_sptr :: shared pointer to workspace
 */
void LoadRaw3::includeMonitors(FILE *file, const int64_t &period,
                               DataObjects::Workspace2D_sptr ws_sptr) {

  int64_t histCurrent = -1;
  int64_t wsIndex = 0;
  double histTotal = static_cast<double>(m_total_specs * m_numberOfPeriods);
  // loop through spectra
  for (specnum_t i = 1; i <= m_numberOfSpectra; ++i) {
    int64_t histToRead = i + period * (m_numberOfSpectra + 1);
    if ((i >= m_spec_min && i < m_spec_max) ||
        (m_list &&
         find(m_spec_list.begin(), m_spec_list.end(), i) !=
             m_spec_list.end())) {
      progress(m_prog, "Reading raw file data...");

      // read spectrum from raw file
      if (!readData(file, histToRead)) {
        throw std::runtime_error("Error reading raw file");
      }
      // set workspace data
      setWorkspaceData(ws_sptr, m_timeChannelsVec, wsIndex, i, m_noTimeRegimes,
                       m_lengthIn, 1);
      ++wsIndex;

      if (m_numberOfPeriods == 1) {
        if (++histCurrent % 100 == 0) {
          setProg(double(histCurrent) / histTotal);
        }
        interruption_point();
      }

    } else {
      skipData(file, histToRead);
    }
  }
  // loadSpectra(file,period,m_total_specs,ws_sptr,m_timeChannelsVec);
}
Exemplo n.º 8
0
/**
 * Skip all spectra in a period.
 * @param file :: -pointer to file
 * @param period :: period number
 */
void LoadRaw3::skipPeriod(FILE *file, const int64_t &period) {
  for (specnum_t i = 1; i <= m_numberOfSpectra; ++i) {
    int64_t histToRead = i + period * (m_numberOfSpectra + 1);
    skipData(file, histToRead);
  }
}
Exemplo n.º 9
0
/** Executes the algorithm. Reading in the file and creating and populating
 *  the output workspace
 *
 *  @throw Exception::FileError If the RAW file cannot be found/opened
 *  @throw std::invalid_argument If the optional properties are set to invalid values
 */
void LoadRawBin0::exec()
{
	// Retrieve the filename from the properties
	m_filename = getPropertyValue("Filename");

	bool bLoadlogFiles = getProperty("LoadLogFiles");

	//open the raw file
	FILE* file=openRawFile(m_filename);

	// Need to check that the file is not a text file as the ISISRAW routines don't deal with these very well, i.e 
	// reading continues until a bad_alloc is encountered.
	if( isAscii(file) )
	{
		g_log.error() << "File \"" << m_filename << "\" is not a valid RAW file.\n";
		throw std::invalid_argument("Incorrect file type encountered.");
	}
	std::string title;
	readTitle(file,title);

	readworkspaceParameters(m_numberOfSpectra,m_numberOfPeriods,m_lengthIn,m_noTimeRegimes);

	///
	setOptionalProperties();

	// to validate the optional parameters, if set
	checkOptionalProperties();

    // Calculate the size of a workspace, given its number of periods & spectra to read
     m_total_specs = calculateWorkspaceSize();

 //no real X values for bin 0,so initialize this to zero
  boost::shared_ptr<MantidVec> channelsVec(new MantidVec(1,0));
  m_timeChannelsVec.push_back(channelsVec);

  double histTotal = static_cast<double>(m_total_specs * m_numberOfPeriods);
  int64_t histCurrent = -1;
 
  // Create the 2D workspace for the output xlength and ylength is one 
  DataObjects::Workspace2D_sptr localWorkspace = createWorkspace(m_total_specs, 1,1,title);
  Run& run = localWorkspace->mutableRun();
  if (bLoadlogFiles)
  {
    runLoadLog(m_filename,localWorkspace, 0.0, 0.0);
    const int period_number = 1;
    createPeriodLogs(period_number, localWorkspace);
  }
  // Set the total proton charge for this run
  setProtonCharge(run);

  WorkspaceGroup_sptr ws_grp = createGroupWorkspace();
  setWorkspaceProperty("OutputWorkspace", title, ws_grp, localWorkspace,m_numberOfPeriods, false);
    
  // Loop over the number of periods in the raw file, putting each period in a separate workspace
  for (int period = 0; period < m_numberOfPeriods; ++period)
  {
    if (period > 0)
    {
      localWorkspace=createWorkspace(localWorkspace);

      if (bLoadlogFiles)
      {
        //remove previous period data
        std::stringstream prevPeriod;
        prevPeriod << "PERIOD " << (period);
        Run& runObj = localWorkspace->mutableRun();
        runObj.removeLogData(prevPeriod.str());
        runObj.removeLogData("current_period");
        //add current period data
        const int period_number = period + 1;
        createPeriodLogs(period_number, localWorkspace);
      }

    }
    skipData(file, period * (m_numberOfSpectra + 1));
    int64_t wsIndex = 0;
    for (specid_t i = 1; i <= m_numberOfSpectra; ++i)
    {
      int64_t histToRead = i + period * (m_numberOfSpectra + 1);
      if ((i >= m_spec_min && i < m_spec_max) || (m_list && find(m_spec_list.begin(), m_spec_list.end(),
          i) != m_spec_list.end()))
      {
        progress(m_prog, "Reading raw file data...");
        //readData(file, histToRead);
		  //read spectrum 
		  if (!readData(file, histToRead))
		  {
			  throw std::runtime_error("Error reading raw file");
		  }
		  int64_t binStart=0;
		  setWorkspaceData(localWorkspace, m_timeChannelsVec, wsIndex, i, m_noTimeRegimes,1,binStart);
		  ++wsIndex;

      if (m_numberOfPeriods == 1)
      {
        if (++histCurrent % 100 == 0)
        {
          m_prog = double(histCurrent) / histTotal;
        }
        interruption_point();
      }

    }
	  else
	  {
		  skipData(file, histToRead);
	  }
    
    }
	
	if(m_numberOfPeriods>1)
	{
		setWorkspaceProperty(localWorkspace, ws_grp, period, false);
		// progress for workspace groups 
		m_prog = static_cast<double>(period) / static_cast<double>(m_numberOfPeriods - 1);
	}
  
  } // loop over periods
  // Clean up
  isisRaw.reset();
  fclose(file);
}
Exemplo n.º 10
0
/*
 * Class:     org_apache_harmony_awt_gl_image_GifDecoder
 * Method:    decode
 * Signature: ([BIJLorg/apache/harmony/awt/gl/image/GifDecoder$GifDataStream;Lorg/apache/harmony/awt/gl/image/GifDecoder$GifGraphicBlock;)I
 */
JNIEXPORT jint JNICALL Java_org_apache_harmony_awt_gl_image_GifDecoder_decode
(JNIEnv *env,
 jobject obj,
 jbyteArray jInput,
 jint bytesInBuffer,
 jlong hDecoder,
 jobject dataStream,
 jobject currBlock) {

    GIF_RETVAL retval = STATUS_OK;
    GifDecoder *decoder = getDecoder(env, obj, dataStream, (GifDecoder*) ((IDATA)hDecoder));
    int scanlinesDecoded;

    decoder->input = decoder->inputPtr =
                         (*env)->GetPrimitiveArrayCritical(env, jInput, 0);
    decoder->bytesInBuffer += bytesInBuffer;
    bytesInBuffer = decoder->bytesInBuffer;

    while(retval == STATUS_OK && decoder->bytesInBuffer > 0) {
        switch(decoder->state) {
        case STATE_INIT: {
            retval = readHeader(env, decoder);
            break;
        }

        case STATE_AT_GLOBAL_COLOR_TABLE: {
            retval = loadColorTable(env, decoder->jGlobalColorTable, decoder);
            break;
        }

        case STATE_AT_LOCAL_COLOR_TABLE: {
            retval = loadColorTable(env, NULL, decoder);
            break;
        }

        case STATE_BLOCK_BEGINNING: {
            unsigned char blockLabel = *(decoder->inputPtr);
            switch(blockLabel) {
            case EXTENSION_INTRODUCER:
                retval = readExtension(env, decoder, currBlock);
                break;
            case IMAGE_SEPARATOR:
                retval = readImageDescriptor(env, currBlock, decoder);
                break;
            case GIF_TRAILER:
                retval = STATUS_EOF;
                break;
            }
            break;
        }

        case STATE_STARTING_DECOMPRESSION: {
            retval = initDecompression(env, decoder, currBlock);
            break;
        }

        case STATE_DECOMPRESSING: {
            if(!decoder->interlace)
                retval = decompress(env, currBlock, decoder);
            else
                retval = decompressInterlaced(env, currBlock, decoder);
            break;
        }

        case STATE_READING_COMMENT: {
            retval = readComment(env, decoder);
            break;
        }

        case STATE_SKIPPING_BLOCKS: {
            retval = skipData(decoder);
            break;
        }

        default:
            // Should never execute this!
            break;
        }
    }

    // Copy unconsumed data to the start of the input buffer
    if(decoder->bytesInBuffer > 0) {
        memmove(decoder->input, decoder->inputPtr, decoder->bytesInBuffer);
    }

    (*env)->ReleasePrimitiveArrayCritical(env, jInput, decoder->input, 0);

    (*env)->SetIntField(
        env,
        obj,
        img_GIF_bytesConsumedID,
        bytesInBuffer - decoder->bytesInBuffer
    );

    if(decoder->stateVars.imageDataStarted) {
        if(!decoder->interlace) {
            scanlinesDecoded = decoder->pixelsDecoded / decoder->currentWidth -
                               decoder->oldPixelsDecoded / decoder->currentWidth;
            decoder->oldPixelsDecoded = decoder->pixelsDecoded;
        } else {
            if(retval == STATUS_LINE_COMPLETED && decoder->pass < MAX_PASS) {
                scanlinesDecoded = 1;
                if(decoder->currScanline >= 0)
                    (*env)->SetIntField(env, currBlock, img_GIF_gb_currYID, decoder->currScanline);

                decoder->scanlineOffset = 0;
            } else {
                scanlinesDecoded = 0;
            }
        }
    } else {
        scanlinesDecoded = 0;
    }

    if(retval == STATUS_FRAME_COMPLETED) {
        decoder->oldPixelsDecoded = decoder->pixelsDecoded = 0;
    }

    // Free the decoder if decoding is finished
    if(retval == STATUS_EOF) {
        free(decoder);
        decoder = NULL;
    }

    (*env)->SetLongField(env, obj, img_GIF_hNativeDecoderID, (jlong) ((IDATA)decoder));

    return scanlinesDecoded;
}