Guest User

Untitled

a guest
Jul 16th, 2014
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.94 KB | None | 0 0
  1. /*
  2. LodePNG Examples
  3.  
  4. Copyright (c) 2005-2012 Lode Vandevenne
  5.  
  6. This software is provided 'as-is', without any express or implied
  7. warranty. In no event will the authors be held liable for any damages
  8. arising from the use of this software.
  9.  
  10. Permission is granted to anyone to use this software for any purpose,
  11. including commercial applications, and to alter it and redistribute it
  12. freely, subject to the following restrictions:
  13.  
  14.     1. The origin of this software must not be misrepresented; you must not
  15.     claim that you wrote the original software. If you use this software
  16.     in a product, an acknowledgment in the product documentation would be
  17.     appreciated but is not required.
  18.  
  19.     2. Altered source versions must be plainly marked as such, and must not be
  20.     misrepresented as being the original software.
  21.  
  22.     3. This notice may not be removed or altered from any source
  23.     distribution.
  24. */
  25.  
  26. /*
  27. Compile command for Linux:
  28. gcc lodepng.c example_sdl.c -ansi -pedantic -Wall -Wextra -lSDL -O3 -o showpng
  29.  
  30. ls *.png | xargs ./showpng
  31. */
  32.  
  33. #include <stdio.h>
  34.  
  35. #include "lodepng.h"
  36.  
  37. void Banana(char* filename)
  38. {
  39.  
  40. unsigned error;
  41.  
  42. unsigned char* image;
  43.  
  44. unsigned char character;
  45.  
  46. unsigned w,h;
  47.  
  48. unsigned int counter;
  49.  
  50. FILE *file;
  51.  
  52. /*load the PNG in one function call*/
  53. error=lodepng_decode32_file(&image,&w,&h,filename);
  54.  
  55. /*stop if there is an error*/
  56. if (error)
  57. {
  58.  
  59. printf("decoder error %u: %s\n", error, lodepng_error_text(error));
  60.  
  61. return;
  62.  
  63. }
  64.  
  65. /******************************************/
  66.  
  67. counter=0;
  68.  
  69. while (1)
  70. {
  71.  
  72. character=filename[counter];
  73.  
  74. if (character=='.')
  75. {
  76.  
  77. filename[counter+1]='t';
  78.  
  79. filename[counter+2]='x';
  80.  
  81. filename[counter+3]='t';
  82.  
  83. break;
  84.  
  85. }
  86.  
  87. counter++;
  88.  
  89. }
  90.  
  91. /******************************************/
  92.  
  93. file=fopen(filename,"w");
  94.  
  95. /******************************************/
  96.  
  97. counter=0;
  98.  
  99. while (1)
  100. {
  101.  
  102. character=filename[counter];
  103.  
  104. if (character=='.')
  105. {
  106.  
  107. filename[counter+1]='p';
  108.  
  109. filename[counter+2]='n';
  110.  
  111. filename[counter+3]='g';
  112.  
  113. break;
  114.  
  115. }
  116.  
  117. counter++;
  118.  
  119. }
  120.  
  121. /******************************************/
  122.  
  123. fprintf(file,"<ImageAsset\n");
  124.  
  125. fprintf(file,"AssetName=\"Image_");
  126.  
  127. /******************************************/
  128.  
  129. counter=0;
  130.  
  131. while (1)
  132. {
  133.  
  134. character=filename[counter];
  135.  
  136. if (character=='.')
  137. {
  138.  
  139. fprintf(file,"\"\n");
  140.  
  141. break;
  142.  
  143. }
  144.  
  145. fprintf(file,"%c",filename[counter]);
  146.  
  147. counter++;
  148.  
  149. }
  150.  
  151. /******************************************/
  152.  
  153. fprintf(file,"ImageFile=\"");
  154.  
  155. fprintf(file,"%s\"\n",filename);
  156.  
  157. fprintf(file,"CellCountX=\"1\"\n");
  158.  
  159. fprintf(file,"CellCountY=\"1\"\n");
  160.  
  161. fprintf(file,"CellWidth=\"%d\"\n",w);
  162.  
  163. fprintf(file,"CellHeight=\"%d\"\n",h);
  164.  
  165. fprintf(file,"/>\n");
  166.  
  167. fclose(file);
  168.  
  169. /*cleanup*/
  170. free(image);
  171.  
  172. }
  173.  
  174. int main(int argc, char* argv[])
  175. {
  176.  
  177. int i;
  178.  
  179. if (argc<=1)
  180. {
  181.  
  182. printf("Please enter PNG file name(s) to display\n");
  183.  
  184. }
  185.  
  186. for (i=1;i<argc;i++)
  187. {
  188.  
  189. Banana(argv[i]);
  190.  
  191. }
  192.  
  193. return 0;
  194.  
  195. }
Advertisement
Add Comment
Please, Sign In to add comment