From 09f102c2b5a7ad0c07b6b662ccb3c9610fbc813c Mon Sep 17 00:00:00 2001 From: HHHHhg <2894700792@qq.com> Date: Sun, 3 Feb 2019 11:51:26 +0800 Subject: [PATCH 1/2] Update etcpack.cxx use pid to fit tmp file to fit parallelism --- source/etcpack.cxx | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/source/etcpack.cxx b/source/etcpack.cxx index f9cf60d..dcb4f60 100755 --- a/source/etcpack.cxx +++ b/source/etcpack.cxx @@ -9453,21 +9453,35 @@ void uncompressFile(char *srcfile, uint8* &img, uint8 *&alphaimg, int& active_wi // NO WARRANTY --- SEE STATEMENT IN TOP OF FILE (C) Ericsson AB 2005-2013. All Rights Reserved. void writeOutputFile(char *dstfile, uint8* img, uint8* alphaimg, int width, int height) { - char str[300]; + int pid = GetCurrentProcessId(); + //printf("pid %d\n", pid); + char str[2047]; + + char tmpppm[2047]; + sprintf(tmpppm, "%dtmp.ppm", pid); + char alphaoutpgm[2047]; + sprintf(alphaoutpgm, "%dalphaout.pgm", pid); + char delTmpFile[2047]; if(format!=ETC2PACKAGE_R_NO_MIPMAPS&&format!=ETC2PACKAGE_RG_NO_MIPMAPS) { fWritePPM("tmp.ppm",width,height,img,8,false); printf("Saved file tmp.ppm \n\n"); + sprintf(delTmpFile, "del %s\n", tmpppm); } else if(format==ETC2PACKAGE_RG_NO_MIPMAPS) { fWritePPM("tmp.ppm",width,height,img,16,false); + sprintf(delTmpFile, "del %s\n", tmpppm); + } + if (format == ETC2PACKAGE_RGBA_NO_MIPMAPS || format == ETC2PACKAGE_RGBA1_NO_MIPMAPS || format == ETC2PACKAGE_sRGBA_NO_MIPMAPS || format == ETC2PACKAGE_sRGBA1_NO_MIPMAPS) { + sprintf(delTmpFile, "del %s\n", alphaoutpgm); + fWritePGM("alphaout.pgm", width, height, alphaimg, false, 8); + } + if (format == ETC2PACKAGE_R_NO_MIPMAPS) { + fWritePGM("alphaout.pgm", width, height, alphaimg, false, 16); + sprintf(delTmpFile, "del %s\n", alphaoutpgm); } - if(format==ETC2PACKAGE_RGBA_NO_MIPMAPS||format==ETC2PACKAGE_RGBA1_NO_MIPMAPS||format==ETC2PACKAGE_sRGBA_NO_MIPMAPS||format==ETC2PACKAGE_sRGBA1_NO_MIPMAPS) - fWritePGM("alphaout.pgm",width,height,alphaimg,false,8); - if(format==ETC2PACKAGE_R_NO_MIPMAPS) - fWritePGM("alphaout.pgm",width,height,alphaimg,false,16); // Delete destination file if it exists if(fileExist(dstfile)) @@ -9480,7 +9494,8 @@ void writeOutputFile(char *dstfile, uint8* img, uint8* alphaimg, int width, int if(!strcmp(&dstfile[q],".ppm")&&format!=ETC2PACKAGE_R_NO_MIPMAPS) { // Already a .ppm file. Just rename. - sprintf(str,"move tmp.ppm %s\n",dstfile); + sprintf(str, "move %s %s\n", tmpppm, dstfile); + //sprintf(str,"move tmp.ppm %s\n",dstfile); printf("Renaming destination file to %s\n",dstfile); } else @@ -9512,18 +9527,19 @@ void writeOutputFile(char *dstfile, uint8* img, uint8* alphaimg, int width, int } else if(format==ETC2PACKAGE_R_NO_MIPMAPS) { - sprintf(str,"magick convert alphaout.pgm %s\n",dstfile); + sprintf(str, "magick convert %s %s\n", alphaoutpgm, dstfile); printf("Converting destination file from .pgm to %s\n",dstfile); } else { - sprintf(str,"magick convert tmp.ppm %s\n",dstfile); + sprintf(str, "magick convert %s %s\n", tmpppm, dstfile); printf("Converting destination file from .ppm to %s\n",dstfile); } } // Execute system call system(str); - + system(delTmpFile); + free(img); if(alphaimg!=NULL) free(alphaimg); From fa5ef69bdba3de6b9819ae3bf921c2bd7d2ca724 Mon Sep 17 00:00:00 2001 From: HHHHhg <2894700792@qq.com> Date: Sun, 3 Feb 2019 11:57:43 +0800 Subject: [PATCH 2/2] Update etcpack.cxx use pid to mark tmp file to fit parallelism --- source/etcpack.cxx | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/source/etcpack.cxx b/source/etcpack.cxx index dcb4f60..6630e11 100755 --- a/source/etcpack.cxx +++ b/source/etcpack.cxx @@ -9465,21 +9465,22 @@ void writeOutputFile(char *dstfile, uint8* img, uint8* alphaimg, int width, int if(format!=ETC2PACKAGE_R_NO_MIPMAPS&&format!=ETC2PACKAGE_RG_NO_MIPMAPS) { - fWritePPM("tmp.ppm",width,height,img,8,false); - printf("Saved file tmp.ppm \n\n"); + fWritePPM(tmpppm, width, height, img, 8, false); + printf("Saved file s \n\n", tmpppm); sprintf(delTmpFile, "del %s\n", tmpppm); } else if(format==ETC2PACKAGE_RG_NO_MIPMAPS) { - fWritePPM("tmp.ppm",width,height,img,16,false); + fWritePPM(tmpppm, width, height, img, 16, false); sprintf(delTmpFile, "del %s\n", tmpppm); } if (format == ETC2PACKAGE_RGBA_NO_MIPMAPS || format == ETC2PACKAGE_RGBA1_NO_MIPMAPS || format == ETC2PACKAGE_sRGBA_NO_MIPMAPS || format == ETC2PACKAGE_sRGBA1_NO_MIPMAPS) { + + fWritePGM(alphaoutpgm, width, height, alphaimg, false, 8); sprintf(delTmpFile, "del %s\n", alphaoutpgm); - fWritePGM("alphaout.pgm", width, height, alphaimg, false, 8); } if (format == ETC2PACKAGE_R_NO_MIPMAPS) { - fWritePGM("alphaout.pgm", width, height, alphaimg, false, 16); + fWritePGM(alphaoutpgm, width, height, alphaimg, false, 16); sprintf(delTmpFile, "del %s\n", alphaoutpgm); }