Exemplo n.º 1
0
int main(void)
{

	uint8_t nb_block_H = 2;
	uint8_t nb_block_V = 2;
	uint8_t h_factor = 1; 
	uint8_t v_factor = 1;
	uint32_t taille_bloc=64;
	uint32_t taille_init = nb_block_H*nb_block_V*taille_bloc;

	// construction du tableau
	uint8_t * MCU_ds = calloc(taille_init,sizeof(uint8_t));
       
	for (uint32_t i = 0; i < taille_bloc; i++){
		MCU_ds[i] = 10;
	}
	for (uint32_t i = 0; i < taille_bloc; i++){
		MCU_ds[i+64] = i;
	}
	for (uint32_t i = 0; i < taille_bloc; i++){
		MCU_ds[i+128] = 30;
	}
	for (uint32_t i = 0; i < taille_bloc; i++){
		MCU_ds[i+192] = 40;
	}

	// Affichage des blocs

	printf("\n Liste des blocs adjacents dans la MCU_ds : \n \n") ;
	for (uint32_t i = 0; i < taille_init; i++){
		printf("%2i ",MCU_ds[i]);
		if (((i+1) % (nb_block_H*_BWIDTH)) == 0){
			printf("\n");
		}
	}
	printf("\n");
	uint32_t new_size=(taille_init)/(h_factor*v_factor);
	uint8_t * MCU_us = calloc(new_size,sizeof(uint8_t)); 
	downsampler(MCU_ds,MCU_us,h_factor,v_factor,nb_block_H,nb_block_V);

	printf("tableau en sortie (de taille %u) : \n \n",new_size) ;

	for (uint32_t i = 0; i < new_size; i++){
		printf("%i ",MCU_us[i]);
		if (((i+1) % 8) == 0){
			printf("\n");
		}
		if (((i+1) % (taille_bloc)) == 0){
			printf("\n");
		}
	}

}
Exemplo n.º 2
0
/*
 * decode une MCU pixmap RGB en lisant les MCU frequentielles correspondantes
 * (de chaque composante) dans le fichier JPEG
 */
void change_RGB_MCU(uint32_t *in_RGB_MCU, uint32_t *out_RGB_MCU, image_t *im,
                    uint8_t MCU_size[2], uint8_t quality)
{
    /* conversion ARGB vers YCbCr */
    printbody2(" => Conversion vers YCbCr...\n");
    uint8_t *YCbCr_MCU[3] = {NULL,NULL,NULL};
    for (uint32_t i = 0; i < im->nb_comp; i++) {
        YCbCr_MCU[i] = calloc(MCU_size[0] * MCU_size[1],
                              sizeof(uint8_t *));
    }
    ARGB_to_YCbCr(in_RGB_MCU,YCbCr_MCU,MCU_size[0]/8,MCU_size[1]/8);


    for (uint32_t i = 0; i < im->nb_comp; i++) {
        uint32_t nb_block = im->comp[i].echV * im->comp[i].echH;
        printbody2(" Composante %u : %u bloc(s) a creer\n",
                   im->comp[i].ic,nb_block);

        /* sous-echantillonnage */
        printbody2("   ├── downsampler...\n");
        uint8_t tab_bck[_BSIZE * nb_block];
        uint8_t tab_bck2[_BSIZE * nb_block];
        uint8_t h_factor = (MCU_size[0] / 8) / im->comp[i].echH;
        uint8_t v_factor = (MCU_size[1] / 8) / im->comp[i].echV;
        downsampler(YCbCr_MCU[i],tab_bck,h_factor,v_factor,MCU_size[0]/8,
                    MCU_size[1]/8);

        for (uint32_t j = 0; j < nb_block; j++) {
            printbody2("   ├── Bloc %u :\n",j+1);

            /* extraction du bloc */
            uint8_t bck[_BSIZE];
            for (uint32_t k = 0; k < _BSIZE; k++) {
                bck[k] = tab_bck[_BSIZE * j + k];
            }

            /* ENCODAGE / DECODAGE du bloc */
            uint8_t bck2[_BSIZE];
            change_pixmap_block(bck,bck2);

            /* remplacement du bloc */
            for (uint32_t k = 0; k < _BSIZE; k++) {
                tab_bck2[_BSIZE * j + k] = bck2[k];
            }
        }

        /* sur-echantillonnage */
        printbody2("   └── Upsampler...\n");
        YCbCr_MCU[i] = calloc(MCU_size[0] * MCU_size[1],
                              sizeof(uint8_t *));
        upsampler(tab_bck2,YCbCr_MCU[i],h_factor,v_factor,MCU_size[0]/8,
                  MCU_size[1]/8);
    }

    /* conversion YCbCr vers ARGB */
    printbody2(" => Conversion vers RGB...\n");
    YCbCr_to_ARGB(YCbCr_MCU,out_RGB_MCU,MCU_size[0]/8,MCU_size[1]/8);
    for (uint32_t i = 0; i < im->nb_comp; i++) {
        free(YCbCr_MCU[i]);
    }
}
Exemplo n.º 3
0
        bool Worker::operator() (const Tractography::Streamline<>& in, Tractography::Streamline<>& out) const
        {

          out.clear();
          out.index = in.index;
          out.weight = in.weight;

          if (!thresholds (in)) {
            // Want to test thresholds before wasting time on upsampling; but if -inverse is set,
            //   still need to apply both the upsampler and downsampler before writing to output
            if (inverse) {
              std::vector< Point<float> > tck (in);
              upsampler (tck);
              downsampler (tck);
              tck.swap (out);
            }
            return true;
          }

          // Upsample track before mapping to ROIs
          std::vector< Point<float> > tck (in);
          upsampler (tck);

          // Assign to ROIs
          if (properties.include.size() || properties.exclude.size()) {

            include_visited.assign (properties.include.size(), false);
            for (std::vector< Point<float> >::const_iterator p = tck.begin(); p != tck.end(); ++p) {
              properties.include.contains (*p, include_visited);
              if (properties.exclude.contains (*p)) {
                if (inverse) {
                  downsampler (tck);
                  tck.swap (out);
                }
                return true;
              }
            }

            // Make sure all of the include regions were visited
            for (std::vector<bool>::const_iterator i = include_visited.begin(); i != include_visited.end(); ++i) {
              if (!*i) {
                if (inverse) {
                  downsampler (tck);
                  tck.swap (out);
                }
                return true;
              }
            }

          }

          if (properties.mask.size()) {

            // Split tck into separate tracks based on the mask
            std::vector< std::vector< Point<float> > > cropped_tracks;
            std::vector< Point<float> > temp;

            for (std::vector< Point<float> >::const_iterator p = tck.begin(); p != tck.end(); ++p) {
              const bool contains = properties.mask.contains (*p);
              if (contains == inverse) {
                if (temp.size() >= 2)
                  cropped_tracks.push_back (temp);
                temp.clear();
              } else {
                temp.push_back (*p);
              }
            }
            if (temp.size() >= 2)
              cropped_tracks.push_back (temp);

            if (cropped_tracks.empty())
              return true;

            // Apply downsampler independently to each
            for (std::vector< std::vector< Point<float> > >::iterator i = cropped_tracks.begin(); i != cropped_tracks.end(); ++i)
              downsampler (*i);

            if (cropped_tracks.size() == 1) {
              cropped_tracks[0].swap (out);
              return true;
            }

            // Stitch back together in preparation for sending down queue as a single track
            out.push_back (Point<float>());
            for (std::vector< std::vector< Point<float> > >::const_iterator i = cropped_tracks.begin(); i != cropped_tracks.end(); ++i) {
              for (std::vector< Point<float> >::const_iterator p = i->begin(); p != i->end(); ++p)
                out.push_back (*p);
              out.push_back (Point<float>());
            }
            out.push_back (Point<float>());
            return true;

          } else {

            if (!inverse) {
              downsampler (tck);
              tck.swap (out);
            }
            return true;

          }

        }