예제 #1
0
파일: io.c 프로젝트: treblih/dip
int
write_bmp_calloc(u8** image, u8* color_buf, int width, int height, BMP_HEADER* p_header)
{
	int		char_test;
        BMP_HEADER      header;
        memcpy(&header, p_header, BMP_HEADER_SIZE);
        p_header                =       &header;

        int  i;
        int  color_len          =        p_header->bm_offset - BMP_HEADER_SIZE;
        p_header->bm_size       =        width * height;
        p_header->width         =        width;
        p_header->height        =        height;
        p_header->file_size     =        p_header->bm_size + p_header->bm_offset;

        char    out_name[16] = {0};
        printf("\n\n\nI have done as u said\ngive a name to the image output(15 chars max)\n");
        scanf("%s", out_name);
	while ((char_test = getchar()) != '\n' && char_test != EOF) ; /* essential ';' */

        FILE*  fd              =        fopen(out_name, "wb");
        if (!fd) {
                printf("Write Failure!\n");
                return -1;
        }

        write_bmp_header(p_header, fd);
        fwrite(color_buf, color_len, 1, fd);
        for (i = 0; i < height; i++) {
                fwrite(image[i], width, 1, fd);
        }
        fclose(fd);

        return 0;
}
예제 #2
0
/* This routine is used for all non-separated formats. */
static int
bmp_print_page(gx_device_printer * pdev, FILE * file)
{
    uint raster = gdev_prn_raster(pdev);
    /* BMP scan lines are padded to 32 bits. */
    uint bmp_raster = raster + (-(int)raster & 3);
    byte *row = gs_alloc_bytes(pdev->memory, bmp_raster, "bmp file buffer");
    int y;
    int code;		/* return code */

    if (row == 0)		/* can't allocate row buffer */
	return_error(gs_error_VMerror);
    memset(row+raster, 0, bmp_raster - raster); /* clear the padding bytes */

    /* Write the file header. */

    code = write_bmp_header(pdev, file);
    if (code < 0)
	goto done;

    /* Write the contents of the image. */
    /* BMP files want the image in bottom-to-top order! */

    for (y = pdev->height - 1; y >= 0; y--) {
	gdev_prn_copy_scan_lines(pdev, y, row, raster);
	fwrite((const char *)row, bmp_raster, 1, file);
    }

done:
    gs_free_object(pdev->memory, row, "bmp file buffer");

    return code;
}
예제 #3
0
파일: wrbmp.c 프로젝트: stormbay/jpeg.tools
finish_output_bmp (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo)
{
  bmp_dest_ptr dest = (bmp_dest_ptr) dinfo;
//  register FILE * outfile = dest->pub.output_file;
  JSAMPARRAY image_ptr;
  register JSAMPROW data_ptr;
  JDIMENSION row;
  register JDIMENSION col;
  cd_progress_ptr progress = (cd_progress_ptr) cinfo->progress;

#if 0
  /* removed by sandman */
  /* Write the header and colormap */
  if (dest->is_os2)
    write_os2_header(cinfo, dest);
  else
    write_bmp_header(cinfo, dest);
#endif

  /* Write the file body from our virtual array */
//  for (row = cinfo->output_height; row > 0; row--) {
  for (row = 1; row <= cinfo->output_height; row++){
    if (progress != NULL) {
      progress->pub.pass_counter = (long) (cinfo->output_height - row);
      progress->pub.pass_limit = (long) cinfo->output_height;
      (*progress->pub.progress_monitor) ((j_common_ptr) cinfo);
    }
    image_ptr = (*cinfo->mem->access_virt_sarray)
      ((j_common_ptr) cinfo, dest->whole_image, row-1, (JDIMENSION) 1, FALSE);
    data_ptr = image_ptr[0];
    for (col = dest->row_width; col > 0; col--) {
#if 0
      putc(GETJSAMPLE(*data_ptr), outfile);
#endif
	  *(cinfo->dst_buffer+cinfo->dst_position) = (unsigned char)GETJSAMPLE(*data_ptr);
      data_ptr++;
	  cinfo->dst_position++;
    }
  }
  if (progress != NULL)
    progress->completed_extra_passes++;

#if 0
  /* Make sure we wrote the output file OK */
  fflush(outfile);
  if (ferror(outfile))
    ERREXIT(cinfo, JERR_FILE_WRITE);
#endif
}
예제 #4
0
파일: jpt_bmp.c 프로젝트: daiyinger/piCode
void analyse_jpeg()
{
	struct jpeg_decompress_struct cinfo;
	struct jpeg_error_mgr jerr;
	unsigned char *src_buff;
	unsigned char *point;

	cinfo.err = jpeg_std_error(&jerr);    //一下为libjpeg函数,具体参看相关文档
	jpeg_create_decompress(&cinfo);
	jpeg_stdio_src(&cinfo, input_file);
	jpeg_read_header(&cinfo, TRUE);
	jpeg_start_decompress(&cinfo);

	uint32_t width = cinfo.output_width;
	uint32_t height = cinfo.output_height;
	uint16_t depth = cinfo.output_components;

	src_buff = (unsigned char *) malloc(width * height * depth);
	memset(src_buff, 0, sizeof(unsigned char) * width * height * depth);

/*
	buffer = (*cinfo.mem->alloc_sarray)((j_common_ptr) &cinfo, JPOOL_IMAGE,
			width * depth, 1);
*/

	point = src_buff;
	while (cinfo.output_scanline < height)
	{
		//jpeg_read_scanlines(&cinfo, buffer, 1);    //读取一行jpg图像数据到buffer
		//memcpy(point, *buffer, width * depth);    //将buffer中的数据逐行给src_buff
		jpeg_read_scanlines(&cinfo, &point, 1);
		point += width * depth;            //一次改变一行
	}

	write_bmp_header(&cinfo);            //写bmp文件头
	write_bmp_data(&cinfo, src_buff);    //写bmp像素数据

	jpeg_finish_decompress(&cinfo);
	jpeg_destroy_decompress(&cinfo);
	free(src_buff);
}
예제 #5
0
finish_output_bmp (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo)
{
  bmp_dest_ptr dest = (bmp_dest_ptr) dinfo;
  register FILE * outfile = dest->pub.output_file;
  JSAMPARRAY image_ptr;
  register JSAMPROW data_ptr;
  JDIMENSION row;
  register JDIMENSION col;
  cd_progress_ptr progress = (cd_progress_ptr) cinfo->progress;

  
  if (dest->is_os2)
    write_os2_header(cinfo, dest);
  else
    write_bmp_header(cinfo, dest);

  
  for (row = cinfo->output_height; row > 0; row--) {
    if (progress != NULL) {
      progress->pub.pass_counter = (long) (cinfo->output_height - row);
      progress->pub.pass_limit = (long) cinfo->output_height;
      (*progress->pub.progress_monitor) ((j_common_ptr) cinfo);
    }
    image_ptr = (*cinfo->mem->access_virt_sarray)
      ((j_common_ptr) cinfo, dest->whole_image, row-1, (JDIMENSION) 1, FALSE);
    data_ptr = image_ptr[0];
    for (col = dest->row_width; col > 0; col--) {
      putc(GETJSAMPLE(*data_ptr), outfile);
      data_ptr++;
    }
  }
  if (progress != NULL)
    progress->completed_extra_passes++;

  
  fflush(outfile);
  if (ferror(outfile))
    ERREXIT(cinfo, JERR_FILE_WRITE);
}
예제 #6
0
파일: io.c 프로젝트: treblih/dip
int
write_bmp(BMP_HEADER* p_header, u8* color_buf, u8* image_buf)
{
        getchar();
        char    out_name[16] = {0};
        printf("\n\n\nI have done as u said\ngive a name to the image output(15 chars max)\n");
        scanf("%s", out_name);

        FILE*                   fd              = fopen(out_name, "wb");
        if (!fd) {
                printf("write failure!\n");
                return -1;
        }

        write_bmp_header(p_header, fd);

        int             color_len         = p_header->bm_offset - BMP_HEADER_SIZE;
        int             image_len         = p_header->file_size - p_header->bm_offset;
        fwrite(color_buf, color_len, 1, fd);
        fwrite(image_buf, image_len, 1, fd);
        fclose(fd);

        return 0;
}
예제 #7
0
void write_bmp_file(FILE *fp)
{
 write_bmp_header(fp);
 fwrite(bitmap, 1, info.image_size, fp);
 fclose(fp);
}