Ejemplo n.º 1
0
void
shufflePixels(int image_size, BYTE* image) {
	int i;
	int* image_pixel_indexes = generateShuffledArray(image_size);
	BYTE* copied_image = copyByteArray(image, image_size);
//	printRow(image_pixel_indexes, image_size);
	for (i = 0; i < image_size; i++) {
		image[i] = copied_image[image_pixel_indexes[i]];
	}
}
  /**
   * Same as {@code copyByteArray(src, dest, src.length)}.
   * @param      src       the source array.
   * @param      srcSize   the size of the source array.
   * @param      dest      the destination array.
   * @param      destSize  the size of the destination array.
   */
  void CryptoHelper::copyByteArray(const byte src[], size_t srcSize, byte dest[], size_t destSize)
  {
    ASSERT(src);
    ASSERT(srcSize);
    ASSERT(dest);
    ASSERT(destSize);
    ASSERT(destSize >= srcSize);

    // The called overload tests for ptr wrap
    return copyByteArray(src, srcSize, dest, destSize, srcSize);
  }
Ejemplo n.º 3
0
//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
void RivReservoirViewPartMgr::computeVisibility(cvf::UByteArray* cellVisibility, RivCellSetEnum geometryType, RigGridBase* grid, size_t gridIdx)
{
    RigEclipseCaseData* eclipseCase = m_reservoirView->eclipseCase()->eclipseCaseData();
    RigActiveCellInfo* activeCellInfo = m_reservoirView->currentActiveCellInfo();

    switch (geometryType)
    {
    case OVERRIDDEN_CELL_VISIBILITY:
        computeOverriddenCellVisibility(cellVisibility, grid);
    break;
    case ACTIVE:
        computeNativeVisibility(cellVisibility, grid, activeCellInfo, eclipseCase->wellCellsInGrid(gridIdx), false, false, true, m_reservoirView->showMainGrid() );
        break;
    case ALL_WELL_CELLS:
        copyByteArray(cellVisibility, eclipseCase->wellCellsInGrid(gridIdx));
        break;
    case VISIBLE_WELL_CELLS:
        {
            cvf::ref<cvf::UByteArray> allWellCellsVisibility;
            ensureStaticGeometryPartsCreated(ALL_WELL_CELLS);

            allWellCellsVisibility = m_geometries[ALL_WELL_CELLS].cellVisibility(gridIdx);

            m_reservoirView->calculateVisibleWellCellsIncFence(cellVisibility, grid);

#pragma omp parallel for
            for (int cellIdx = 0; cellIdx < static_cast<int>(cellVisibility->size()); ++cellIdx)
            {
                (*cellVisibility)[cellIdx] = (*allWellCellsVisibility)[cellIdx] && (*cellVisibility)[cellIdx];
            }
        }
        break;
    case VISIBLE_WELL_FENCE_CELLS:
        {
            cvf::ref<cvf::UByteArray> allWellCellsVisibility;
            ensureStaticGeometryPartsCreated(ALL_WELL_CELLS);

            allWellCellsVisibility = m_geometries[ALL_WELL_CELLS].cellVisibility(gridIdx);

            m_reservoirView->calculateVisibleWellCellsIncFence(cellVisibility, grid);

#pragma omp parallel for
            for (int cellIdx = 0; cellIdx < static_cast<int>(cellVisibility->size()); ++cellIdx)
            {
                (*cellVisibility)[cellIdx] = !(*allWellCellsVisibility)[cellIdx] && (*cellVisibility)[cellIdx];
            }
        }
        break;
    case INACTIVE:
        computeNativeVisibility(cellVisibility, grid, activeCellInfo, eclipseCase->wellCellsInGrid(gridIdx),  m_reservoirView->showInvalidCells(), true, false, m_reservoirView->showMainGrid());
        break;
    case RANGE_FILTERED:
        {
            cvf::ref<cvf::UByteArray> nativeVisibility;
            ensureStaticGeometryPartsCreated(ACTIVE);

            nativeVisibility = m_geometries[ACTIVE].cellVisibility(gridIdx);
            computeRangeVisibility(geometryType, cellVisibility, grid, nativeVisibility.p(), m_reservoirView->rangeFilterCollection());
        }
        break;
    case RANGE_FILTERED_INACTIVE:
        {
            cvf::ref<cvf::UByteArray> nativeVisibility;
            ensureStaticGeometryPartsCreated(INACTIVE);

            nativeVisibility = m_geometries[INACTIVE].cellVisibility(gridIdx);
            computeRangeVisibility(geometryType, cellVisibility, grid, nativeVisibility.p(), m_reservoirView->rangeFilterCollection());
        }
        break;
    case RANGE_FILTERED_WELL_CELLS:
        {
            cvf::ref<cvf::UByteArray> nativeVisibility;
            ensureStaticGeometryPartsCreated(ALL_WELL_CELLS);

            nativeVisibility = m_geometries[ALL_WELL_CELLS].cellVisibility(gridIdx);
            computeRangeVisibility(geometryType, cellVisibility, grid, nativeVisibility.p(), m_reservoirView->rangeFilterCollection());
        }
        break;
    case VISIBLE_WELL_CELLS_OUTSIDE_RANGE_FILTER:
        {
            cvf::ref<cvf::UByteArray> visibleWellCells;
            cvf::ref<cvf::UByteArray> rangeFilteredWellCells;

            ensureStaticGeometryPartsCreated(VISIBLE_WELL_CELLS);
            ensureStaticGeometryPartsCreated(RANGE_FILTERED_WELL_CELLS);

            visibleWellCells = m_geometries[VISIBLE_WELL_CELLS].cellVisibility(gridIdx);
            rangeFilteredWellCells = m_geometries[RANGE_FILTERED_WELL_CELLS].cellVisibility(gridIdx);

            cellVisibility->resize(visibleWellCells->size());

#pragma omp parallel for
            for (int cellIdx = 0; cellIdx < static_cast<int>(cellVisibility->size()); ++cellIdx)
            {
                (*cellVisibility)[cellIdx] = (*visibleWellCells)[cellIdx] && !(*rangeFilteredWellCells)[cellIdx];
            }
        }
        break;
    case VISIBLE_WELL_FENCE_CELLS_OUTSIDE_RANGE_FILTER:
        {
            cvf::ref<cvf::UByteArray> visibleWellCells;
            cvf::ref<cvf::UByteArray> rangeFilteredWellCells;

            ensureStaticGeometryPartsCreated(VISIBLE_WELL_FENCE_CELLS);
            ensureStaticGeometryPartsCreated(RANGE_FILTERED);

            visibleWellCells = m_geometries[VISIBLE_WELL_FENCE_CELLS].cellVisibility(gridIdx);
            rangeFilteredWellCells = m_geometries[RANGE_FILTERED].cellVisibility(gridIdx);

            cellVisibility->resize(visibleWellCells->size());

#pragma omp parallel for
            for (int cellIdx = 0; cellIdx < static_cast<int>(cellVisibility->size()); ++cellIdx)
            {
                (*cellVisibility)[cellIdx] = (*visibleWellCells)[cellIdx] && !(*rangeFilteredWellCells)[cellIdx];
            }
        }
        break;
    default:
        CVF_ASSERT(false); // Call special function for property filtered stuff
        break;
    }
}
Ejemplo n.º 4
0
int my_decompress(FILE *source, FILE *dest, myFilter myfilter)
{
	FILE* temp;
	header fhp;
    int ret, i;
	int CHUNK;
    unsigned have;
    z_stream strm;
    unsigned char *in;
    unsigned char *out;
    unsigned char *prev;
	unsigned char *aux_header;

	CHUNK = 128*KBYTES;
	
    /* allocate inflate state */
    strm.zalloc = Z_NULL;
    strm.zfree = Z_NULL;
    strm.opaque = Z_NULL;
    strm.avail_in = 0;
    strm.next_in = Z_NULL;
    ret = inflateInit(&strm);
    if (ret != Z_OK)
        return ret;

    /* decompress until deflate stream ends or end of file */
    do {
		
		strm.avail_in = fread(in, 1, CHUNK, source);
        if (ferror(source)) {
            (void)inflateEnd(&strm);
            return Z_ERRNO;
        }
        if (strm.avail_in == 0)
            break;
        strm.next_in = in;

        /* run inflate() on input until output buffer not full */
        do {
            strm.avail_out = CHUNK;
            strm.next_out = out;
            ret = inflate(&strm, Z_NO_FLUSH);
            assert(ret != Z_STREAM_ERROR);  /* state not clobbered */
            switch (ret) {
            case Z_NEED_DICT:
                ret = Z_DATA_ERROR;     /* and fall through */
            case Z_DATA_ERROR:
            case Z_MEM_ERROR:
                (void)inflateEnd(&strm);
                return ret;
            }
            have = CHUNK - strm.avail_out;
            if (fwrite(out, 1, have, dest) != have || ferror(dest)) {
                (void)inflateEnd(&strm);
                return Z_ERRNO;
            }
        } while (strm.avail_out == 0);

        /* done when inflate() says it's done */
    } while (ret != Z_STREAM_END);

    /* clean up and return */
    (void)inflateEnd(&strm);
	
	/* unfilter file */
	
	temp=dest;
	dest=source;
	source=temp;
	fseek(source,0, SEEK_SET);
	fseek(dest,0, SEEK_SET);
	
	myfilter.nbrChars=processFileHeader(myfilter.sourceName,&fhp);
	myfilter.bpp=(fhp.magicValue>3 ? 3:1);
	myfilter.lineSize=fhp.imageWidth*myfilter.bpp;
	myfilter.firstLine=true;
	CHUNK=myfilter.lineSize+1;
	
	for(i=0; i<myfilter.lineSize+1; ++i)
		prev[i]=0;
	
	aux_header = (unsigned char *) (malloc(myfilter.nbrChars));
	in = (unsigned char *) (malloc(CHUNK));
	out = (unsigned char *) (malloc(CHUNK));
	prev = (unsigned char *) (malloc(CHUNK));
	
	do {	
		if (myfilter.firstLine){
			(*aux_header) = fread(aux_header, 1, myfilter.nbrChars, source);
		}
		else
			(*in) = fread(in, 1, CHUNK, source);
			
		if (myfilter.type!=-1 && !myfilter.firstLine){
			unfilterPNG(in, prev, out, myfilter.lineSize, myfilter.bpp);
			copyByteArray(in, prev, CHUNK);
		}
		myfilter.firstLine = false;
	
		fwrite(out, 1, CHUNK-1, dest);
	} while((*in) == EOF || (*aux_header) == EOF);
	
	/* clear the space reserved in the beggining */
	free(in);
	free(out);
	free(prev);
	free(aux_header);

	
	
    return ret == Z_STREAM_END ? Z_OK : Z_DATA_ERROR;
}
Ejemplo n.º 5
0
int my_compress(FILE *source, FILE *dest, int level, myFilter myfilter)
{
	int CHUNK;
    int ret, flush, i;
    unsigned have;
    z_stream strm;
    unsigned char *in;
    unsigned char *out;
    unsigned char *prev;
	unsigned char *aux_header;
	
	CHUNK = myfilter.lineSize+1;
	
	aux_header = (unsigned char *) (malloc(myfilter.nbrChars));
	in = (unsigned char *) (malloc(CHUNK));
	out = (unsigned char *) (malloc(CHUNK));
	prev = (unsigned char *) (malloc(CHUNK));
	
	for(i=0; i<myfilter.lineSize+1; ++i)
		prev[i]=0;
	
	
    /* allocate deflate state */
    strm.zalloc = Z_NULL;
    strm.zfree = Z_NULL;
    strm.opaque = Z_NULL;
    ret = deflateInit(&strm, level);
    if (ret != Z_OK)
        return ret;

    /* compress until end of file */
    do {
		
		if (myfilter.firstLine){
			strm.avail_in = fread(aux_header, 1, myfilter.nbrChars, source);
		}
		else
			strm.avail_in = fread(in, 1, CHUNK, source);
			
        if (ferror(source)) {
            (void)deflateEnd(&strm);
            return Z_ERRNO;
        }
        flush = feof(source) ? Z_FINISH : Z_NO_FLUSH;
		
		if (myfilter.type!=-1 && !myfilter.firstLine){
			filterPNG(in, prev, out, myfilter.lineSize, myfilter.bpp, myfilter.type);
			copyByteArray(in, prev, CHUNK);
			copyByteArray(out, in, CHUNK);
		}
		myfilter.firstLine = false;

        /* run deflate() on input until output buffer not full, finish
           compression if all of source has been read in */
        do {		
            strm.avail_out = CHUNK;
            strm.next_out = out;
            ret = deflate(&strm, flush);    /* no bad return value */
            assert(ret != Z_STREAM_ERROR);  /* state not clobbered */
            have = CHUNK - strm.avail_out;
            if (fwrite(out, 1, have, dest) != have || ferror(dest)) {
                (void)deflateEnd(&strm);
                return Z_ERRNO;
            }
        } while (strm.avail_out == 0);
        assert(strm.avail_in == 0);     /* all input will be used */

        /* done when last data in file processed */
    } while (flush != Z_FINISH);
    assert(ret == Z_STREAM_END);        /* stream will be complete */

    /* clean up and return */
    (void)deflateEnd(&strm);
	
	/* clear the space reserved in the beggining */
	free(in);
	free(out);
	free(prev);
	free(aux_header);
	
    return Z_OK;
}