示例#1
0
   void save_pbm(const char* name, uchar* im, int height, int width )
   {
      std::ofstream file(name, std::ios::out | std::ios::binary);

      file << "P4\n" << width << " " << height << "\n";
      for (int i = 0; i < height; i++)
         write_packed(im+(width*i), width, file);
   }
示例#2
0
文件: msicon.c 项目: arsane/mp4sdk
static int
write_bitmapinfoheader(i_io_glue_t *ig, ico_image_t const *image, int *error,
			int bit_count, int clr_used) {
  if (!write_packed(ig, "d dd w w d d dd dd", 
		    40UL, /* biSize */
		    (unsigned long)image->width, 
                    (unsigned long)2 * image->height, /* biWidth/biHeight */
		    1, bit_count, /* biPlanes, biBitCount */
		    0UL, 0UL, /* biCompression, biSizeImage */
		    0UL, 0UL, /* bi(X|Y)PetsPerMeter */
		    (unsigned long)clr_used, /* biClrUsed */
                    0UL)) { /* biClrImportant */
    *error = ICOERR_Write_Failure;
    return 0;
  }

  return 1;
}
示例#3
0
文件: msicon.c 项目: arsane/mp4sdk
int
ico_write(i_io_glue_t *ig, ico_image_t const *images, int image_count,
	  int type, int *error) {
  int i;
  int start_offset = 6 + 16 * image_count;
  int current_offset = start_offset;

  if (type != ICON_ICON && type != ICON_CURSOR) {
    *error = ICOERR_Bad_File_Type;
    return 0;
  }

  /* validate the images */
  if (!ico_write_validate(images, image_count, error))
    return 0;

  /* write the header */
  if (!write_packed(ig, "www", 0, type, image_count)) {
    *error = ICOERR_Write_Failure;
    return 0;
  }

  /* work out the offsets of each image */
  for (i = 0; i < image_count; ++i) {
    ico_image_t const *image = images + i;
    int bits, colors;
    int size = ico_image_size(image, &bits, &colors);

    if (type == ICON_ICON) {
      if (!write_packed(ig, "bbbbwwdd", image->width, image->height,
			colors, 0, 1, bits, (unsigned long)size, 
			(unsigned long)current_offset)) {
	*error = ICOERR_Write_Failure;
	return 0;
      }
    }
    else {
      int hotspot_x = image->hotspot_x;
      int hotspot_y = image->hotspot_y;

      if (hotspot_x < 0)
	hotspot_x = 0;
      else if (hotspot_x >= image->width)
	hotspot_x = image->width - 1;
      if (hotspot_y < 0)
	hotspot_y = 0;
      else if (hotspot_y >= image->height)
	hotspot_y = image->height - 1;

      if (!write_packed(ig, "bbbbwwdd", image->width, image->height,
			colors, 0, hotspot_x, hotspot_y, (unsigned long)size, 
			(unsigned long)current_offset)) {
	*error = ICOERR_Write_Failure;
	return 0;
      }
    }
    current_offset += size;
  }
  
  /* write out each image */
  for (i = 0; i < image_count; ++i) {
    ico_image_t const *image = images + i;

    if (image->direct) {
      if (!write_32_bit(ig, image, error))
	return 0;
    }
    else {
      if (image->palette_size <= 2) {
	if (!write_1_bit(ig, image, error))
	  return 0;
      }
      else if (image->palette_size <= 16) {
	if (!write_4_bit(ig, image, error))
	  return 0;
      }
      else {
	if (!write_8_bit(ig, image, error))
	  return 0;
      }
    }
    if (!write_mask(ig, image, error))
      return 0;
  }

  return 1;
}