⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pngwutil.c

📁 Qt/Embedded是一个多平台的C++图形用户界面应用程序框架
💻 C
📖 第 1 页 / 共 5 页
字号:
       red_x + red_y > 1.0)   {      png_warning(png_ptr, "Invalid cHRM red point specified");      return;   }   itemp = (png_uint_32)(red_x * 100000.0 + 0.5);   png_save_uint_32(buf + 8, itemp);   itemp = (png_uint_32)(red_y * 100000.0 + 0.5);   png_save_uint_32(buf + 12, itemp);   if (green_x < 0 || green_x > 0.8 || green_y < 0 || green_y > 0.8 ||       green_x + green_y > 1.0)   {      png_warning(png_ptr, "Invalid cHRM green point specified");      return;   }   itemp = (png_uint_32)(green_x * 100000.0 + 0.5);   png_save_uint_32(buf + 16, itemp);   itemp = (png_uint_32)(green_y * 100000.0 + 0.5);   png_save_uint_32(buf + 20, itemp);   if (blue_x < 0 || blue_x > 0.8 || blue_y < 0 || blue_y > 0.8 ||       blue_x + blue_y > 1.0)   {      png_warning(png_ptr, "Invalid cHRM blue point specified");      return;   }   itemp = (png_uint_32)(blue_x * 100000.0 + 0.5);   png_save_uint_32(buf + 24, itemp);   itemp = (png_uint_32)(blue_y * 100000.0 + 0.5);   png_save_uint_32(buf + 28, itemp);   png_write_chunk(png_ptr, (png_bytep)png_cHRM, buf, (png_size_t)32);}#endif#ifdef PNG_FIXED_POINT_SUPPORTEDvoid /* PRIVATE */png_write_cHRM_fixed(png_structp png_ptr, png_fixed_point white_x,   png_fixed_point white_y, png_fixed_point red_x, png_fixed_point red_y,   png_fixed_point green_x, png_fixed_point green_y, png_fixed_point blue_x,   png_fixed_point blue_y){#ifdef PNG_USE_LOCAL_ARRAYS   PNG_cHRM;#endif   png_byte buf[32];   png_debug(1, "in png_write_cHRM\n");   /* each value is saved in 1/100,000ths */   if (white_x > 80000L || white_y > 80000L || white_x + white_y > 100000L)   {      png_warning(png_ptr, "Invalid fixed cHRM white point specified");#if !defined(PNG_NO_STDIO)      printf("white_x=%ld, white_y=%ld\n",white_x, white_y);#endif      return;   }   png_save_uint_32(buf, white_x);   png_save_uint_32(buf + 4, white_y);   if (red_x > 80000L || red_y > 80000L || red_x + red_y > 100000L)   {      png_warning(png_ptr, "Invalid cHRM fixed red point specified");      return;   }   png_save_uint_32(buf + 8, red_x);   png_save_uint_32(buf + 12, red_y);   if (green_x > 80000L || green_y > 80000L || green_x + green_y > 100000L)   {      png_warning(png_ptr, "Invalid fixed cHRM green point specified");      return;   }   png_save_uint_32(buf + 16, green_x);   png_save_uint_32(buf + 20, green_y);   if (blue_x > 80000L || blue_y > 80000L || blue_x + blue_y > 100000L)   {      png_warning(png_ptr, "Invalid fixed cHRM blue point specified");      return;   }   png_save_uint_32(buf + 24, blue_x);   png_save_uint_32(buf + 28, blue_y);   png_write_chunk(png_ptr, (png_bytep)png_cHRM, buf, (png_size_t)32);}#endif#endif#if defined(PNG_WRITE_tRNS_SUPPORTED)/* write the tRNS chunk */void /* PRIVATE */png_write_tRNS(png_structp png_ptr, png_bytep trans, png_color_16p tran,   int num_trans, int color_type){#ifdef PNG_USE_LOCAL_ARRAYS   PNG_tRNS;#endif   png_byte buf[6];   png_debug(1, "in png_write_tRNS\n");   if (color_type == PNG_COLOR_TYPE_PALETTE)   {      if (num_trans <= 0 || num_trans > (int)png_ptr->num_palette)      {         png_warning(png_ptr,"Invalid number of transparent colors specified");         return;      }      /* write the chunk out as it is */      png_write_chunk(png_ptr, (png_bytep)png_tRNS, trans, (png_size_t)num_trans);   }   else if (color_type == PNG_COLOR_TYPE_GRAY)   {      /* one 16 bit value */      png_save_uint_16(buf, tran->gray);      png_write_chunk(png_ptr, (png_bytep)png_tRNS, buf, (png_size_t)2);   }   else if (color_type == PNG_COLOR_TYPE_RGB)   {      /* three 16 bit values */      png_save_uint_16(buf, tran->red);      png_save_uint_16(buf + 2, tran->green);      png_save_uint_16(buf + 4, tran->blue);      png_write_chunk(png_ptr, (png_bytep)png_tRNS, buf, (png_size_t)6);   }   else   {      png_warning(png_ptr, "Can't write tRNS with an alpha channel");   }}#endif#if defined(PNG_WRITE_bKGD_SUPPORTED)/* write the background chunk */void /* PRIVATE */png_write_bKGD(png_structp png_ptr, png_color_16p back, int color_type){#ifdef PNG_USE_LOCAL_ARRAYS   PNG_bKGD;#endif   png_byte buf[6];   png_debug(1, "in png_write_bKGD\n");   if (color_type == PNG_COLOR_TYPE_PALETTE)   {      if (#ifdef PNG_WRITE_EMPTY_PLTE_SUPPORTED          (!png_ptr->empty_plte_permitted ||          (png_ptr->empty_plte_permitted && png_ptr->num_palette)) &&#endif         back->index > png_ptr->num_palette)      {         png_warning(png_ptr, "Invalid background palette index");         return;      }      buf[0] = back->index;      png_write_chunk(png_ptr, (png_bytep)png_bKGD, buf, (png_size_t)1);   }   else if (color_type & PNG_COLOR_MASK_COLOR)   {      png_save_uint_16(buf, back->red);      png_save_uint_16(buf + 2, back->green);      png_save_uint_16(buf + 4, back->blue);      png_write_chunk(png_ptr, (png_bytep)png_bKGD, buf, (png_size_t)6);   }   else   {      png_save_uint_16(buf, back->gray);      png_write_chunk(png_ptr, (png_bytep)png_bKGD, buf, (png_size_t)2);   }}#endif#if defined(PNG_WRITE_hIST_SUPPORTED)/* write the histogram */void /* PRIVATE */png_write_hIST(png_structp png_ptr, png_uint_16p hist, int num_hist){#ifdef PNG_USE_LOCAL_ARRAYS   PNG_hIST;#endif   int i;   png_byte buf[3];   png_debug(1, "in png_write_hIST\n");   if (num_hist > (int)png_ptr->num_palette)   {      png_debug2(3, "num_hist = %d, num_palette = %d\n", num_hist,         png_ptr->num_palette);      png_warning(png_ptr, "Invalid number of histogram entries specified");      return;   }   png_write_chunk_start(png_ptr, (png_bytep)png_hIST, (png_uint_32)(num_hist * 2));   for (i = 0; i < num_hist; i++)   {      png_save_uint_16(buf, hist[i]);      png_write_chunk_data(png_ptr, buf, (png_size_t)2);   }   png_write_chunk_end(png_ptr);}#endif#if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_pCAL_SUPPORTED) || \    defined(PNG_WRITE_iCCP_SUPPORTED) || defined(PNG_WRITE_sPLT_SUPPORTED)/* Check that the tEXt or zTXt keyword is valid per PNG 1.0 specification, * and if invalid, correct the keyword rather than discarding the entire * chunk.  The PNG 1.0 specification requires keywords 1-79 characters in * length, forbids leading or trailing whitespace, multiple internal spaces, * and the non-break space (0x80) from ISO 8859-1.  Returns keyword length. * * The new_key is allocated to hold the corrected keyword and must be freed * by the calling routine.  This avoids problems with trying to write to * static keywords without having to have duplicate copies of the strings. */png_size_t /* PRIVATE */png_check_keyword(png_structp png_ptr, png_charp key, png_charpp new_key){   png_size_t key_len;   png_charp kp, dp;   int kflag;   png_debug(1, "in png_check_keyword\n");   *new_key = NULL;   if (key == NULL || (key_len = png_strlen(key)) == 0)   {      png_chunk_warning(png_ptr, "zero length keyword");      return ((png_size_t)0);   }   png_debug1(2, "Keyword to be checked is '%s'\n", key);   *new_key = (png_charp)png_malloc(png_ptr, (png_uint_32)(key_len + 1));   /* Replace non-printing characters with a blank and print a warning */   for (kp = key, dp = *new_key; *kp != '\0'; kp++, dp++)   {      if (*kp < 0x20 || (*kp > 0x7E && (png_byte)*kp < 0xA1))      {#if !defined(PNG_NO_STDIO)         char msg[40];         sprintf(msg, "invalid keyword character 0x%02X", *kp);         png_chunk_warning(png_ptr, msg);#else         png_chunk_warning(png_ptr, "invalid character in keyword");#endif         *dp = ' ';      }      else      {         *dp = *kp;      }   }   *dp = '\0';   /* Remove any trailing white space. */   kp = *new_key + key_len - 1;   if (*kp == ' ')   {      png_chunk_warning(png_ptr, "trailing spaces removed from keyword");      while (*kp == ' ')      {        *(kp--) = '\0';        key_len--;      }   }   /* Remove any leading white space. */   kp = *new_key;   if (*kp == ' ')   {      png_chunk_warning(png_ptr, "leading spaces removed from keyword");      while (*kp == ' ')      {        kp++;        key_len--;      }   }   png_debug1(2, "Checking for multiple internal spaces in '%s'\n", kp);   /* Remove multiple internal spaces. */   for (kflag = 0, dp = *new_key; *kp != '\0'; kp++)   {      if (*kp == ' ' && kflag == 0)      {         *(dp++) = *kp;         kflag = 1;      }      else if (*kp == ' ')      {         key_len--;      }      else      {         *(dp++) = *kp;         kflag = 0;      }   }   *dp = '\0';   if (key_len == 0)   {      png_free(png_ptr, *new_key);      *new_key=NULL;      png_chunk_warning(png_ptr, "Zero length keyword");   }   if (key_len > 79)   {      png_chunk_warning(png_ptr, "keyword length must be 1 - 79 characters");      new_key[79] = '\0';      key_len = 79;   }   return (key_len);}#endif#if defined(PNG_WRITE_tEXt_SUPPORTED)/* write a tEXt chunk */void /* PRIVATE */png_write_tEXt(png_structp png_ptr, png_charp key, png_charp text,   png_size_t text_len){#ifdef PNG_USE_LOCAL_ARRAYS   PNG_tEXt;#endif   png_size_t key_len;   png_charp new_key;   png_debug(1, "in png_write_tEXt\n");   if (key == NULL || (key_len = png_check_keyword(png_ptr, key, &new_key))==0)   {      png_warning(png_ptr, "Empty keyword in tEXt chunk");      return;   }   if (text == NULL || *text == '\0')      text_len = 0;   else      text_len = png_strlen(text);   /* make sure we include the 0 after the key */   png_write_chunk_start(png_ptr, (png_bytep)png_tEXt, (png_uint_32)key_len+text_len+1);   /*    * We leave it to the application to meet PNG-1.0 requirements on the    * contents of the text.  PNG-1.0 through PNG-1.2 discourage the use of    * any non-Latin-1 characters except for NEWLINE.  ISO PNG will forbid them.    * The NUL character is forbidden by PNG-1.0 through PNG-1.2 and ISO PNG.    */   png_write_chunk_data(png_ptr, (png_bytep)new_key, key_len + 1);   if (text_len)      png_write_chunk_data(png_ptr, (png_bytep)text, text_len);   png_write_chunk_end(png_ptr);   png_free(png_ptr, new_key);}#endif#if defined(PNG_WRITE_zTXt_SUPPORTED)/* write a compressed text chunk */void /* PRIVATE */png_write_zTXt(png_structp png_ptr, png_charp key, png_charp text,   png_size_t text_len, int compression){#ifdef PNG_USE_LOCAL_ARRAYS   PNG_zTXt;#endif   png_size_t key_len;   char buf[1];   png_charp new_key;   compression_state comp;   png_debug(1, "in png_write_zTXt\n");   if (key == NULL || (key_len = png_check_keyword(png_ptr, key, &new_key))==0)   {      png_warning(png_ptr, "Empty keyword in zTXt chunk");      return;   }   if (text == NULL || *text == '\0' || compression==PNG_TEXT_COMPRESSION_NONE)   {      png_write_tEXt(png_ptr, new_key, text, (png_size_t)0);      png_free(png_ptr, new_key);      return;   }   text_len = png_strlen(text);   png_free(png_ptr, new_key);   /* compute the compressed data; do it now for the length */   text_len = png_text_compress(png_ptr, text, text_len, compression,       &comp);   /* write start of chunk */   png_write_chunk_start(png_ptr, (png_bytep)png_zTXt, (png_uint_32)      (key_len+text_len+2));   /* write key */   png_write_chunk_data(png_ptr, (png_bytep)key, key_len + 1);   buf[0] = (png_byte)compression;   /* write compression */   png_write_chunk_data(png_ptr, (png_bytep)buf, (png_size_t)1);   /* write the compressed data */   png_write_compressed_data_out(png_ptr, &comp);   /* close the chunk */   png_write_chunk_end(png_ptr);}#endif#if defined(PNG_WRITE_iTXt_SUPPORTED)/* write an iTXt chunk */void /* PRIVATE */png_write_iTXt(png_structp png_ptr, int compression, png_charp key,    png_charp lang, png_charp lang_key, png_charp text){#ifdef PNG_USE_LOCAL_ARRAYS   PNG_iTXt;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -