Пример #1
0
void plD_eop_png(PLStream *pls)
{
    png_Dev *dev=(png_Dev *)pls->dev;
    int im_size=0;
    void *im_ptr=NULL;

    if (pls->family || pls->page == 1) {

   if (dev->optimise)
     {
#if GD2_VERS >= 2
      if ( ( (((dev->truecolour>0) && (dev->palette>0)) ||     /* In an EXTREMELY convaluted */
             ((dev->truecolour==0) && (dev->palette==0))) &&   /* manner, all this is just   */
              ((pls->ncol1+pls->ncol0)<=256) ) ||             /* asking the question, do we */
           ( ((dev->palette>0)&&(dev->truecolour==0)) )  )   /* want truecolour or not ?   */
            {
#endif
             plD_gd_optimise(pls);

#if GD2_VERS >= 2
            }
#endif
        }


       /* image is written to output file by the driver
          since if the gd.dll is linked to a different c
          lib a crash occurs - this fix works also in Linux */
       /* gdImagePng(dev->im_out, pls->OutFile); */
       #if GD2_VERS >= 2
         im_ptr = gdImagePngPtrEx (dev->im_out, &im_size, pls->dev_compression >9 ? (pls->dev_compression/10) : pls->dev_compression);
       #else
         im_ptr = gdImagePngPtr(dev->im_out, &im_size);
       #endif
       if( im_ptr ) {
         fwrite(im_ptr, sizeof(char), im_size, pls->OutFile);
         gdFree(im_ptr);
       }

       gdImageDestroy(dev->im_out);
       dev->im_out = NULL;
    }
}
Пример #2
0
int CFunctions::imgPng ( lua_State* luaVM )
{
	// bool imagePng( userdata im, string fPath )
    if ( luaVM )
    {
        if ( lua_type ( luaVM, 1 ) == LUA_TLIGHTUSERDATA &&
            lua_type ( luaVM, 2 ) == LUA_TSTRING )
		{
			std::string mResource;
			if( pModuleManager->GetResourceName(luaVM, mResource) )
			{
				gdImagePtr im = mImgManager->GetImage( lua_touserdata( luaVM, 1 ) );
				if( im != NULL )
				{
					const char* fName = lua_tostring(luaVM, 2);
					std::string 
						fNewPath,
						fMetaPath;

					bool noDel = lua_toboolean(luaVM, 3)?true:false;

					if( ParseResourcePathInput( std::string(fName), mResource, fNewPath, fMetaPath ) )
					{
						std::fstream out(fNewPath.c_str(), std::fstream::out | std::fstream::binary );
						if( out.is_open() )
						{
							int sis = 0;
							char * result = (char *)gdImagePngPtrEx( im, &sis, 0 );

							out.write(result, sis);
							
							out.close();
							gdFree(result);

							if(!noDel) mImgManager->RemoveImage( lua_touserdata( luaVM, 1 ) );

							//printf( "%d", sis );

							lua_pushboolean( luaVM, true );
							return 1;
						}
						else
						{
							lua_pushboolean( luaVM, false );
							return 1;
						}
					}
					else
					{
						pModuleManager->DebugPrintf( luaVM, "Bad filepath in: imagePng" );
						lua_pushboolean( luaVM, false );
						return 1;
					}
				}
				else
				{
					lua_pushboolean( luaVM, false );
					return 1;
				}
			}
			lua_pushboolean( luaVM, false );
			return 1;
		}
		else
		{
			pModuleManager->DebugPrintf( luaVM, "Incorrect parameters in: imagePng" );
			lua_pushboolean( luaVM, false );
		}
		return 1;
    }
    return 0;
}