Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- LodePNG Examples
- Copyright (c) 2005-2012 Lode Vandevenne
- This software is provided 'as-is', without any express or implied
- warranty. In no event will the authors be held liable for any damages
- arising from the use of this software.
- Permission is granted to anyone to use this software for any purpose,
- including commercial applications, and to alter it and redistribute it
- freely, subject to the following restrictions:
- 1. The origin of this software must not be misrepresented; you must not
- claim that you wrote the original software. If you use this software
- in a product, an acknowledgment in the product documentation would be
- appreciated but is not required.
- 2. Altered source versions must be plainly marked as such, and must not be
- misrepresented as being the original software.
- 3. This notice may not be removed or altered from any source
- distribution.
- */
- /*
- Compile command for Linux:
- gcc lodepng.c example_sdl.c -ansi -pedantic -Wall -Wextra -lSDL -O3 -o showpng
- ls *.png | xargs ./showpng
- */
- #include <stdio.h>
- #include "lodepng.h"
- void Banana(char* filename)
- {
- unsigned error;
- unsigned char* image;
- unsigned char character;
- unsigned w,h;
- unsigned int counter;
- FILE *file;
- /*load the PNG in one function call*/
- error=lodepng_decode32_file(&image,&w,&h,filename);
- /*stop if there is an error*/
- if (error)
- {
- printf("decoder error %u: %s\n", error, lodepng_error_text(error));
- return;
- }
- /******************************************/
- counter=0;
- while (1)
- {
- character=filename[counter];
- if (character=='.')
- {
- filename[counter+1]='t';
- filename[counter+2]='x';
- filename[counter+3]='t';
- break;
- }
- counter++;
- }
- /******************************************/
- file=fopen(filename,"w");
- /******************************************/
- counter=0;
- while (1)
- {
- character=filename[counter];
- if (character=='.')
- {
- filename[counter+1]='p';
- filename[counter+2]='n';
- filename[counter+3]='g';
- break;
- }
- counter++;
- }
- /******************************************/
- fprintf(file,"<ImageAsset\n");
- fprintf(file,"AssetName=\"Image_");
- /******************************************/
- counter=0;
- while (1)
- {
- character=filename[counter];
- if (character=='.')
- {
- fprintf(file,"\"\n");
- break;
- }
- fprintf(file,"%c",filename[counter]);
- counter++;
- }
- /******************************************/
- fprintf(file,"ImageFile=\"");
- fprintf(file,"%s\"\n",filename);
- fprintf(file,"CellCountX=\"1\"\n");
- fprintf(file,"CellCountY=\"1\"\n");
- fprintf(file,"CellWidth=\"%d\"\n",w);
- fprintf(file,"CellHeight=\"%d\"\n",h);
- fprintf(file,"/>\n");
- fclose(file);
- /*cleanup*/
- free(image);
- }
- int main(int argc, char* argv[])
- {
- int i;
- if (argc<=1)
- {
- printf("Please enter PNG file name(s) to display\n");
- }
- for (i=1;i<argc;i++)
- {
- Banana(argv[i]);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment