コード例 #1
0
ファイル: igzip.c プロジェクト: ceph/isa-l
static void isal_deflate_pass(struct isal_zstream *stream)
{
	struct isal_zstate *state = &stream->internal_state;
	struct isal_hufftables *hufftables = stream->hufftables;
	uint8_t *start_in = stream->next_in;

	if (state->state == ZSTATE_NEW_HDR || state->state == ZSTATE_HDR) {
		if (state->count == 0)
			/* Assume the final header is being written since the header
			 * stored in hufftables is the final header. */
			state->has_eob_hdr = 1;
		write_header(stream, hufftables->deflate_hdr, hufftables->deflate_hdr_count,
			     hufftables->deflate_hdr_extra_bits, ZSTATE_BODY,
			     !stream->end_of_stream);
	}

	if (state->state == ZSTATE_BODY)
		isal_deflate_body(stream);

	if (state->state == ZSTATE_FLUSH_READ_BUFFER)
		isal_deflate_finish(stream);

	if (state->state == ZSTATE_SYNC_FLUSH)
		sync_flush(stream);

	if (state->state == ZSTATE_FLUSH_WRITE_BUFFER)
		flush_write_buffer(stream);

	if (stream->gzip_flag)
		state->crc = crc32_gzip(state->crc, start_in, stream->next_in - start_in);

	if (state->state == ZSTATE_TRL)
		write_trailer(stream);
}
コード例 #2
0
ファイル: mp4_parser.cpp プロジェクト: dengxiayehu/flvpusher
int MP4Parser::process(void *opaque, FrameCb cb)
{
  FormatContext *ic = NULL;

  if (init_ffmpeg_context() < 0) {
    LOGE("init_ffmpeg_context() failed");
    return -1;
  }

  // |ic| is created after init_ffmpeg_context()
  ic = m_mp4->stream;
  ic->cb      = cb;
  ic->opaque  = opaque;

  unsigned i;
  while (!*ic->watch_variable) {
    i = choose_output(ic);

    if (process_input(ic, i) < 0)
      break;
  }

  write_trailer(ic);
  return 0;
}
コード例 #3
0
ファイル: archive-tar.c プロジェクト: XGodLike/Git
static int write_tar_archive(const struct archiver *ar,
			     struct archiver_args *args)
{
	int err = 0;

	write_global_extended_header(args);
	err = write_archive_entries(args, write_tar_entry);
	if (!err)
		write_trailer();
	return err;
}
コード例 #4
0
ファイル: igzip.c プロジェクト: ceph/isa-l
static void isal_deflate_icf_pass(struct isal_zstream *stream)
{
	uint8_t *start_in = stream->next_in;
	struct isal_zstate *state = &stream->internal_state;
	struct level_2_buf *level_buf = (struct level_2_buf *)stream->level_buf;

	do {
		if (state->state == ZSTATE_NEW_HDR)
			init_new_icf_block(stream);

		if (state->state == ZSTATE_BODY)
			isal_deflate_icf_body(stream);

		if (state->state == ZSTATE_FLUSH_READ_BUFFER)
			isal_deflate_icf_finish(stream);

		if (state->state == ZSTATE_CREATE_HDR)
			create_icf_block_hdr(stream);

		if (state->state == ZSTATE_HDR)
			/* Note that the header may be prepended by the
			 * remaining bits in the previous block, as such the
			 * toggle header flag cannot be used */
			write_header(stream, level_buf->deflate_hdr,
				     level_buf->deflate_hdr_count,
				     level_buf->deflate_hdr_extra_bits,
				     ZSTATE_FLUSH_ICF_BUFFER, 0);

		if (state->state == ZSTATE_FLUSH_ICF_BUFFER)
			flush_icf_block(stream);

	} while (state->state == ZSTATE_NEW_HDR);

	if (state->state == ZSTATE_SYNC_FLUSH)
		sync_flush(stream);

	if (state->state == ZSTATE_FLUSH_WRITE_BUFFER)
		flush_write_buffer(stream);

	if (stream->gzip_flag)
		state->crc = crc32_gzip(state->crc, start_in, stream->next_in - start_in);

	if (state->state == ZSTATE_TRL)
		write_trailer(stream);
}
コード例 #5
0
ファイル: igzip.c プロジェクト: 01org/isa-l
static void isal_deflate_int(struct isal_zstream *stream)
{
	struct isal_zstate *state = &stream->internal_state;
	if (state->state == ZSTATE_NEW_HDR || state->state == ZSTATE_HDR)
		write_header(stream);

	if (state->state == ZSTATE_BODY)
		isal_deflate_body(stream);

	if (state->state == ZSTATE_FLUSH_READ_BUFFER)
		isal_deflate_finish(stream);

	if (state->state == ZSTATE_SYNC_FLUSH)
		sync_flush(stream);

	if (state->state == ZSTATE_FLUSH_WRITE_BUFFER)
		flush_write_buffer(stream);

	if (state->state == ZSTATE_TRL)
		write_trailer(stream);
}
コード例 #6
0
unsigned char* zinjpeg_decompressor::decompress_zinjpeg(unsigned char* input_buffer, int buffer_size){
    
    //init of the decompression
    bitbuffer_construct();
    radio_init((char*)input_buffer, buffer_size);
    pkg_reader_construct();
    huff_table_init();
    huff_reset();
    concealment_initialize();
    
    //writting the header of the output buffer
    write_header(this->quality);
    
    
    //loop to transcode ZinJpeg in JPEG
    for (int i = 0; i < NUM_OF_BLOCKS; i++) {
        short coefficients[NUM_COEFF];
        // Check whether this index can be accepted
        //	check_index(&i);
        // Reading the block
        errorcode_t retval = read_block(coefficients);
        check_index(&i);
        
        if(retval == 0) {
            // i < NUM_OF_BLOCKS is necessary because we may encounter
            // a end of file in the check_index: in that case we sync
            // to the end of the image, but here we would try to write
            // one more block
            if(i < NUM_OF_BLOCKS) {
                DEBUG_BLOCK(i, "Valid block. I'm writing it");
                write_block(coefficients);
                concealment_block_written_success(i, coefficients);
            }
        } else error_handler(coefficients, retval, &i);
    }
    
    write_trailer();
    this->output_buffer = write_result_to_buffer(&(this->output_size));
    return this->output_buffer;
}
コード例 #7
0
ファイル: initrd-extract.c プロジェクト: legionus/make-initrd
int
main(int argc, char **argv)
{
	int c, fd, n_archive = 0;
	int option_index = 0;
	struct stat st;
	unsigned long offset;
	FILE *output = NULL;

	error_print_progname = my_error_print_progname;

	while ((c = getopt_long(argc, argv, cmdopts_s, cmdopts, &option_index)) != -1) {
		switch (c) {
			case 'a':
				n_archive = str2int(cmdopts[option_index].name, optarg);
				if (n_archive <= 0)
					bad_option_value(cmdopts[option_index].name, optarg);
				break;
			case 'o':
				if (output)
					fclose(output);
				if ((output = fopen(optarg, "w")) == NULL)
					error(EXIT_FAILURE, errno, "ERROR: %s: %d: fopen", __FILE__, __LINE__);
				break;
			case 'V':
				print_version();
			case 'h':
				print_help();
			default:
				exit(EXIT_FAILURE);
		}
	}

	if (optind >= argc)
		error(EXIT_FAILURE, 0, "Missing initrd file");

	if (!output)
		output = stdout;

	if (stat(argv[optind], &st) == -1)
		error(EXIT_FAILURE, errno, "ERROR: %s: %d: stat", __FILE__, __LINE__);

	if ((fd = open(argv[optind], O_RDONLY)) == -1)
		error(EXIT_FAILURE, errno, "ERROR: %s: %d: open", __FILE__, __LINE__);

	unsigned char *addr = mmap(NULL, (size_t) st.st_size, PROT_READ, MAP_PRIVATE | MAP_POPULATE, fd, 0);

	if (addr == MAP_FAILED)
		error(EXIT_FAILURE, errno, "ERROR: %s: %d: mmap", __FILE__, __LINE__);

	struct stream *s;
	struct list_tail *l, *h;
	struct result res;

	res.streams = NULL;
	res.cpios   = NULL;

	l = list_append(&res.streams, sizeof(struct stream));
	if (l == NULL)
		error(EXIT_FAILURE, errno, "unable to add element to list");
	s = l->data;

	s->addr      = addr;
	s->size      = (unsigned long) st.st_size;
	s->allocated = 0;

	read_stream("raw", s, &res);

	offset = 0;
	c      = 1;
	l      = res.cpios;
	while (l) {
		if (!n_archive || c == n_archive) {
			h = ((struct cpio *) l->data)->headers;
			while (h) {
				offset = write_cpio(h->data, offset, output);
				h      = h->next;
			}
		}
		l = l->next;
		c++;
	}

	write_trailer(offset, output);

	free_cpios(res.cpios);
	free_streams(res.streams);

	munmap(addr, (size_t) st.st_size);

	fclose(output);

	return EXIT_SUCCESS;
}
コード例 #8
0
ファイル: pnmtoddif.c プロジェクト: jhbsz/DIR-850L_A1
int main(int argc, char *argv[])
{
    FILE           *ifd;
    FILE       *ofd;
    int             rows, cols;
    xelval          maxval;
    int             format;
    const char     * const usage = "[-resolution x y] [pnmfile [ddiffile]]";
    int             i, j;
    char           *outfile;
    int       argn;
    int hor_resolution = 75;
    int ver_resolution = 75;
    imageparams ip;
    unsigned char  *data, *p;

    pnm_init(&argc, argv);

    for (argn = 1;argn < argc && argv[argn][0] == '-';argn++) {
        int arglen = strlen(argv[argn]);

        if (!strncmp (argv[argn],"-resolution", arglen)) {
            if (argn + 2 < argc) {
                hor_resolution = atoi(argv[argn+1]);
                ver_resolution = atoi(argv[argn+2]);
                argn += 2;
                continue;
            } else {
                pm_usage(usage);
            }
        } else {
            pm_usage(usage);
        }
    }

    if (hor_resolution <= 0 || ver_resolution <= 0) {
        fprintf(stderr,"Unreasonable resolution values: %d x %d\n",
                hor_resolution,ver_resolution);
        exit(1);
    }

    if (argn == argc - 2) {
        ifd = pm_openr(argv[argn]);
        outfile = argv[argn+1];
        if (!(ofd = fopen(outfile,"wb"))) {
            perror(outfile);
            exit(1);
        }
    } else if (argn == argc - 1) {
        ifd = pm_openr(argv[argn]);
        ofd = stdout;
    } else {
        ifd = stdin;
        ofd = stdout;
    }

    pnm_readpnminit(ifd, &cols, &rows, &maxval, &format);

    ip.width = cols;
    ip.height = rows;
    ip.h_res = hor_resolution;
    ip.v_res = ver_resolution;

    switch (PNM_FORMAT_TYPE(format)) {
    case PBM_TYPE:
        ip.bits_per_pixel = 1;
        ip.bytes_per_line = (cols + 7) / 8;
        ip.spectral = 2;
        ip.components = 1;
        ip.bits_per_component = 1;
        ip.polarity = 1;
        break;
    case PGM_TYPE:
        ip.bytes_per_line = cols;
        ip.bits_per_pixel = 8;
        ip.spectral = 2;
        ip.components = 1;
        ip.bits_per_component = 8;
        ip.polarity = 2;
        break;
    case PPM_TYPE:
        ip.bytes_per_line = 3 * cols;
        ip.bits_per_pixel = 24;
        ip.spectral = 5;
        ip.components = 3;
        ip.bits_per_component = 8;
        ip.polarity = 2;
        break;
    default:
        fprintf(stderr, "Unrecognized PBMPLUS format %d\n", format);
        exit(1);
    }

    if (!write_header(ofd,&ip)) {
        perror("Writing header");
        exit(1);
    }

    if (!(p = data = (unsigned char*)  malloc(ip.bytes_per_line))) {
        perror("allocating line buffer");
        exit(1);
    }

    switch (PNM_FORMAT_TYPE(format)) {
    case PBM_TYPE:
    {
        bit            *pixels;
        int             mask;
        int             k;

        pixels = pbm_allocrow(cols);

        for (i = 0; i < rows; i++) {
            pbm_readpbmrow(ifd, pixels, cols, format);
            mask = 0;
            p = data;
            for (j = 0, k = 0; j < cols; j++) {
                if (pixels[j] == PBM_BLACK) {
                    mask |= 1 << k;
                }
                if (k == 7) {
                    *p++ = mask;
                    mask = 0;
                    k = 0;
                } else {
                    k++;
                }
            }
            if (k != 7) {       /* Flush the rest of the column */
                *p = mask;
            }
            if (fwrite(data,1,ip.bytes_per_line,ofd) != ip.bytes_per_line) {
                perror("Writing image data\n");
                exit(1);
            }
        }
    }
    break;
    case PGM_TYPE:
    {
        gray          *pixels = pgm_allocrow(cols);

        for (i = 0; i < rows; i++) {
            p = data;
            pgm_readpgmrow(ifd, pixels, cols, maxval, format);
            for (j = 0; j < cols; j++) {
                *p++ = (unsigned char) pixels[j];
            }
            if (fwrite(data,1,ip.bytes_per_line,ofd) != ip.bytes_per_line) {
                perror("Writing image data\n");
                exit(1);
            }
        }
        pgm_freerow(pixels);
    }
    break;
    case PPM_TYPE:
    {
        pixel          *pixels = ppm_allocrow(cols);

        for (i = 0; i < rows; i++) {
            p = data;
            ppm_readppmrow(ifd, pixels, cols, maxval, format);
            for (j = 0; j < cols; j++) {
                *p++ = PPM_GETR(pixels[j]);
                *p++ = PPM_GETG(pixels[j]);
                *p++ = PPM_GETB(pixels[j]);
            }
            if (fwrite(data,1,ip.bytes_per_line,ofd) != ip.bytes_per_line) {
                perror("Writing image data\n");
                exit(1);
            }
        }
        ppm_freerow(pixels);
    }
    break;
    }

    pm_close(ifd);

    free(data);

    if (!write_trailer(ofd)) {
        perror("Writing trailer");
        exit(1);
    }

    if (fclose(ofd) == EOF) {
        perror("Closing output file");
        exit(1);
    };

    return(0);
}
コード例 #9
0
ファイル: pnmtoddif.c プロジェクト: Eleanor66613/CS131
int
main(int argc, char *argv[]) {
    FILE           *ifd;
    FILE           *ofd;
    int             rows, cols;
    xelval          maxval;
    int             format;
    const char     * const usage = "[-resolution x y] [pnmfile [ddiffile]]";
    char           *outfile;
    int       argn;
    int hor_resolution = 75;
    int ver_resolution = 75;
    imageparams ip;

    pnm_init(&argc, argv);

    for (argn = 1;argn < argc && argv[argn][0] == '-';argn++) {
        int arglen = strlen(argv[argn]);

        if (!strncmp (argv[argn],"-resolution", arglen)) {
            if (argn + 2 < argc) {
                hor_resolution = atoi(argv[argn+1]);
                ver_resolution = atoi(argv[argn+2]);
                argn += 2;
                continue;
            } else {
                pm_usage(usage);
            }
        } else {
            pm_usage(usage);
        }
    }

    if (hor_resolution <= 0 || ver_resolution <= 0) {
        fprintf(stderr,"Unreasonable resolution values: %d x %d\n",
                hor_resolution,ver_resolution);
        exit(1);
    }

    if (argn == argc - 2) {
        ifd = pm_openr(argv[argn]);
        outfile = argv[argn+1];
        if (!(ofd = fopen(outfile,"wb"))) {
            perror(outfile);
            exit(1);
        }
    } else if (argn == argc - 1) {
        ifd = pm_openr(argv[argn]);
        ofd = stdout;
    } else {
        ifd = stdin;
        ofd = stdout;
    }

    pnm_readpnminit(ifd, &cols, &rows, &maxval, &format);

    ip.width = cols;
    ip.height = rows;
    ip.h_res = hor_resolution;
    ip.v_res = ver_resolution;

    switch (PNM_FORMAT_TYPE(format)) {
    case PBM_TYPE:
        ip.bits_per_pixel = 1;
        ip.bytes_per_line = (cols + 7) / 8;
        ip.spectral = 2;
        ip.components = 1;
        ip.bits_per_component = 1;
        ip.polarity = 1;
        break;
    case PGM_TYPE:
        ip.bytes_per_line = cols;
        ip.bits_per_pixel = 8;
        ip.spectral = 2;
        ip.components = 1;
        ip.bits_per_component = 8;
        ip.polarity = 2;
        break;
    case PPM_TYPE:
        ip.bytes_per_line = 3 * cols;
        ip.bits_per_pixel = 24;
        ip.spectral = 5;
        ip.components = 3;
        ip.bits_per_component = 8;
        ip.polarity = 2;
        break;
    default:
        fprintf(stderr, "Unrecognized PBMPLUS format %d\n", format);
        exit(1);
    }

    if (!write_header(ofd,&ip)) {
        perror("Writing header");
        exit(1);
    }

    convertRaster(ifd, format, maxval, cols, rows, ofd, ip.bytes_per_line);

    pm_close(ifd);

    if (!write_trailer(ofd)) {
        perror("Writing trailer");
        exit(1);
    }

    if (fclose(ofd) == EOF) {
        perror("Closing output file");
        exit(1);
    };

    return(0);
}