Re: [pygame] Pygame surface

2014-09-10 Thread diliup gabadamudalige
thanks Christopher. The haze cleared a bit. The fog now looks like mist...:)

On Wed, Sep 10, 2014 at 9:49 PM, Christopher Night 
wrote:

> No, in pygame, both screenshots and images loaded from files are simply
> Surface objects. In this case, this fact is documented in the description
> for pygame.image.load. Hopefully that makes it clear that it returns a
> Surface:
> http://www.pygame.org/docs/ref/image.html#pygame.image.load
>
> Good luck!
>
>
> On Wed, Sep 10, 2014 at 11:54 AM, diliup gabadamudalige  > wrote:
>
>> I am asking how to save a SURFACE and NOT an image that was loaded.
>> Aren't those two different things?
>>
>> Pardon my ignorance but some of the Pygame documentation is not very
>> clear to me. Also none of the suggested methods delivered results that were
>> fast enough to be used in a practical situation.
>> The fastest so far is the normal save to disk and reload as jpeg and then
>> the rest.
>>
>> Also PIL does not compile well with py2exe.
>> Not all packages and modules do.
>>
>> Hence the question.
>> So looks like my best option is the save to disk and load which is also
>> the fastest.
>>
>> Thanks to everyone  all for the support which is invaluable.
>>
>>
>>
>> --
>>
>>
>> On Wed, Sep 10, 2014 at 9:11 PM, Christopher Night <
>> cosmologi...@gmail.com> wrote:
>>
>>> For reference, here's the discussion from the last time Diliup asked
>>> this same question, a month ago:
>>>
>>> https://groups.google.com/forum/#!topic/pygame-mirror-on-google-groups/WIuIlmXvqow
>>>
>>>
>>> On Tue, Sep 9, 2014 at 7:57 AM, diliup gabadamudalige >> > wrote:
>>>
 How can a Pygame surface be converted to an image file say a jpeg or a
 png WITHOUT writing the file to disk? Say after a screen grab?

>>>
>>>
>>
>>
>> --
>> Diliup Gabadamudalige
>>
>> http://www.diliupg.com
>> http://soft.diliupg.com/
>>
>>
>> **
>> This e-mail is confidential. It may also be legally privileged. If you
>> are not the intended recipient or have received it in error, please delete
>> it and all copies from your system and notify the sender immediately by
>> return e-mail. Any unauthorized reading, reproducing, printing or further
>> dissemination of this e-mail or its contents is strictly prohibited and may
>> be unlawful. Internet communications cannot be guaranteed to be timely,
>> secure, error or virus-free. The sender does not accept liability for any
>> errors or omissions.
>>
>> **
>>
>>
>


-- 
Diliup Gabadamudalige

http://www.diliupg.com
http://soft.diliupg.com/

**
This e-mail is confidential. It may also be legally privileged. If you are
not the intended recipient or have received it in error, please delete it
and all copies from your system and notify the sender immediately by return
e-mail. Any unauthorized reading, reproducing, printing or further
dissemination of this e-mail or its contents is strictly prohibited and may
be unlawful. Internet communications cannot be guaranteed to be timely,
secure, error or virus-free. The sender does not accept liability for any
errors or omissions.
**


Re: [pygame] Pygame surface

2014-09-10 Thread Christopher Night
No, in pygame, both screenshots and images loaded from files are simply
Surface objects. In this case, this fact is documented in the description
for pygame.image.load. Hopefully that makes it clear that it returns a
Surface:
http://www.pygame.org/docs/ref/image.html#pygame.image.load

Good luck!


On Wed, Sep 10, 2014 at 11:54 AM, diliup gabadamudalige 
wrote:

> I am asking how to save a SURFACE and NOT an image that was loaded. Aren't
> those two different things?
>
> Pardon my ignorance but some of the Pygame documentation is not very clear
> to me. Also none of the suggested methods delivered results that were fast
> enough to be used in a practical situation.
> The fastest so far is the normal save to disk and reload as jpeg and then
> the rest.
>
> Also PIL does not compile well with py2exe.
> Not all packages and modules do.
>
> Hence the question.
> So looks like my best option is the save to disk and load which is also
> the fastest.
>
> Thanks to everyone  all for the support which is invaluable.
>
>
>
> --
>
>
> On Wed, Sep 10, 2014 at 9:11 PM, Christopher Night  > wrote:
>
>> For reference, here's the discussion from the last time Diliup asked this
>> same question, a month ago:
>>
>> https://groups.google.com/forum/#!topic/pygame-mirror-on-google-groups/WIuIlmXvqow
>>
>>
>> On Tue, Sep 9, 2014 at 7:57 AM, diliup gabadamudalige 
>> wrote:
>>
>>> How can a Pygame surface be converted to an image file say a jpeg or a
>>> png WITHOUT writing the file to disk? Say after a screen grab?
>>>
>>
>>
>
>
> --
> Diliup Gabadamudalige
>
> http://www.diliupg.com
> http://soft.diliupg.com/
>
>
> **
> This e-mail is confidential. It may also be legally privileged. If you are
> not the intended recipient or have received it in error, please delete it
> and all copies from your system and notify the sender immediately by return
> e-mail. Any unauthorized reading, reproducing, printing or further
> dissemination of this e-mail or its contents is strictly prohibited and may
> be unlawful. Internet communications cannot be guaranteed to be timely,
> secure, error or virus-free. The sender does not accept liability for any
> errors or omissions.
>
> **
>
>


Re: [pygame] Pygame surface

2014-09-10 Thread diliup gabadamudalige
can anybody give me some code guide to use tempfile with the above question
please?

On Wed, Sep 10, 2014 at 9:24 PM, diliup gabadamudalige 
wrote:

> I am asking how to save a SURFACE and NOT an image that was loaded. Aren't
> those two different things?
>
> Pardon my ignorance but some of the Pygame documentation is not very clear
> to me. Also none of the suggested methods delivered results that were fast
> enough to be used in a practical situation.
> The fastest so far is the normal save to disk and reload as jpeg and then
> the rest.
>
> Also PIL does not compile well with py2exe.
> Not all packages and modules do.
>
> Hence the question.
> So looks like my best option is the save to disk and load which is also
> the fastest.
>
> Thanks to everyone  all for the support which is invaluable.
>
>
>
> --
>
>
> On Wed, Sep 10, 2014 at 9:11 PM, Christopher Night  > wrote:
>
>> For reference, here's the discussion from the last time Diliup asked this
>> same question, a month ago:
>>
>> https://groups.google.com/forum/#!topic/pygame-mirror-on-google-groups/WIuIlmXvqow
>>
>>
>> On Tue, Sep 9, 2014 at 7:57 AM, diliup gabadamudalige 
>> wrote:
>>
>>> How can a Pygame surface be converted to an image file say a jpeg or a
>>> png WITHOUT writing the file to disk? Say after a screen grab?
>>>
>>
>>
>
>
> --
> Diliup Gabadamudalige
>
> http://www.diliupg.com
> http://soft.diliupg.com/
>
>
> **
> This e-mail is confidential. It may also be legally privileged. If you are
> not the intended recipient or have received it in error, please delete it
> and all copies from your system and notify the sender immediately by return
> e-mail. Any unauthorized reading, reproducing, printing or further
> dissemination of this e-mail or its contents is strictly prohibited and may
> be unlawful. Internet communications cannot be guaranteed to be timely,
> secure, error or virus-free. The sender does not accept liability for any
> errors or omissions.
>
> **
>
>


-- 
Diliup Gabadamudalige

http://www.diliupg.com
http://soft.diliupg.com/

**
This e-mail is confidential. It may also be legally privileged. If you are
not the intended recipient or have received it in error, please delete it
and all copies from your system and notify the sender immediately by return
e-mail. Any unauthorized reading, reproducing, printing or further
dissemination of this e-mail or its contents is strictly prohibited and may
be unlawful. Internet communications cannot be guaranteed to be timely,
secure, error or virus-free. The sender does not accept liability for any
errors or omissions.
**


Re: [pygame] Pygame surface

2014-09-10 Thread diliup gabadamudalige
I am asking how to save a SURFACE and NOT an image that was loaded. Aren't
those two different things?

Pardon my ignorance but some of the Pygame documentation is not very clear
to me. Also none of the suggested methods delivered results that were fast
enough to be used in a practical situation.
The fastest so far is the normal save to disk and reload as jpeg and then
the rest.

Also PIL does not compile well with py2exe.
Not all packages and modules do.

Hence the question.
So looks like my best option is the save to disk and load which is also the
fastest.

Thanks to everyone  all for the support which is invaluable.



-- 


On Wed, Sep 10, 2014 at 9:11 PM, Christopher Night 
wrote:

> For reference, here's the discussion from the last time Diliup asked this
> same question, a month ago:
>
> https://groups.google.com/forum/#!topic/pygame-mirror-on-google-groups/WIuIlmXvqow
>
>
> On Tue, Sep 9, 2014 at 7:57 AM, diliup gabadamudalige 
> wrote:
>
>> How can a Pygame surface be converted to an image file say a jpeg or a
>> png WITHOUT writing the file to disk? Say after a screen grab?
>>
>
>


-- 
Diliup Gabadamudalige

http://www.diliupg.com
http://soft.diliupg.com/

**
This e-mail is confidential. It may also be legally privileged. If you are
not the intended recipient or have received it in error, please delete it
and all copies from your system and notify the sender immediately by return
e-mail. Any unauthorized reading, reproducing, printing or further
dissemination of this e-mail or its contents is strictly prohibited and may
be unlawful. Internet communications cannot be guaranteed to be timely,
secure, error or virus-free. The sender does not accept liability for any
errors or omissions.
**


Re: [pygame] Pygame surface

2014-09-10 Thread Christopher Night
For reference, here's the discussion from the last time Diliup asked this
same question, a month ago:
https://groups.google.com/forum/#!topic/pygame-mirror-on-google-groups/WIuIlmXvqow


On Tue, Sep 9, 2014 at 7:57 AM, diliup gabadamudalige 
wrote:

> How can a Pygame surface be converted to an image file say a jpeg or a png
> WITHOUT writing the file to disk? Say after a screen grab?
>


Re: [pygame] Pygame surface

2014-09-10 Thread Weeble
If you save to a file-like object, it will be in TGA format. Your
filename hint when loading (iname) needs to end in ".tga". TGA format
isn't compressed, so there's not a lot of value doing this compared to
doing fromstring/tostring. If you want use JPEG format your options
are to use a temporary file on disk, or to use a library like PIL. I
don't think pygame gives you any other way.

On 10 September 2014 08:14, diliup gabadamudalige  wrote:
> Thank you for the response Peter. Pygame image to string code below
>
> def displayscreen():
> ## image_filename = str(va.page) + ".jpeg"  # va.page is the current
> page no
> filename = "zxs" + str(va.page) + ".ada"
> ## images are saved in runs.py and to use it storeno = 2
> image2blit = getfrompy.main(filename, storeno = 2)
> if image2blit == None:
> ## no image saved in file so draw the screen with make_screen_text
> make_screen_text()
> ## now grab the screen
> screen = SCREEN.subsurface(0, 0, SCREENW, SCREENH)
> ## convert to string
> screenstr = pygame.image.tostring(screen, "RGBA", Falsey)
> ## nowencode and write to dict in runs.py
> strA = XOR(screenstr, coder)
> str1 = base64.b64encode(strA)
> scrnstore [filename] = str1
> image2blit = pygame.image.frombuffer(screenstr, ( SCREENW, SCREENH
> ), 'RGBA')
> va.getscr = True
> return image2blit
>
> this code took too long to convert back and fourth. around 6 seconds.
>
> screen = SCREEN.subsurface(0, 0, SCREENW, SCREENH)
> image2blit = pygame.Surface.convert_alpha(screen)
> memsave = StringIO()
> pygame.image.save(image2blit, memsave)
> memsave.seek(0)
> pygame.image.load(memsave, iname)  <- code crashes here
> strA = XOR(iname, coder)
> str1 = base64.b64encode(strA)
> scrnstore [filename] = str1
>
> the above code crashes at the point marked with the message pygame.error:
> unsupported image format. What I want to do is to grab the screen surface,
> convert it to a string format and save to a dictionary.
> The dictionary will be pickled and saved to a file.
> I want all my images in this file and NOT AS IMAGE FILES ON DISK.
> Please help to resolve this.
>
>
>
>
>
> On Wed, Sep 10, 2014 at 10:05 AM, Peter Shinners  wrote:
>>
>> On 09/09/2014 04:57 AM, diliup gabadamudalige wrote:
>>>
>>>
>>> How can a Pygame surface be converted to an image file say a jpeg or a
>>> png WITHOUT writing the file to disk? Say after a screen grab?
>>>
>>
>>
>> It is not highly documented, but you can pass a file-like object to
>> pygame.image.save. So instead of a filename you could create a StringIO
>> buffer and write into that. Or you could use something crazy like an html
>> post request and upload directly to a website.
>>
>> If you are trying to load the image into a different library, it will be
>> easier to use the "tobuffer" or "tostring" methods on the Surface. Then hope
>> the other library you are using has a fromstring, frombuffer, or fromdata
>> style function.
>>
>>
>
>
>
> --
> Diliup Gabadamudalige
>
> http://www.diliupg.com
> http://soft.diliupg.com/
>
> **
> This e-mail is confidential. It may also be legally privileged. If you are
> not the intended recipient or have received it in error, please delete it
> and all copies from your system and notify the sender immediately by return
> e-mail. Any unauthorized reading, reproducing, printing or further
> dissemination of this e-mail or its contents is strictly prohibited and may
> be unlawful. Internet communications cannot be guaranteed to be timely,
> secure, error or virus-free. The sender does not accept liability for any
> errors or omissions.
> **
>


Re: [pygame] Pygame surface

2014-09-10 Thread diliup gabadamudalige
Thank you for the response Peter. Pygame image to string code below

def displayscreen():
## image_filename = str(va.page) + ".jpeg"  # va.page is the current
page no
filename = "zxs" + str(va.page) + ".ada"
## images are saved in runs.py and to use it storeno = 2
image2blit = getfrompy.main(filename, storeno = 2)
if image2blit == None:
## no image saved in file so draw the screen with make_screen_text
make_screen_text()
## now grab the screen
screen = SCREEN.subsurface(0, 0, SCREENW, SCREENH)
## convert to string
screenstr = pygame.image.tostring(screen, "RGBA", Falsey)
## nowencode and write to dict in runs.py
strA = XOR(screenstr, coder)
str1 = base64.b64encode(strA)
scrnstore [filename] = str1
image2blit = pygame.image.frombuffer(screenstr, ( SCREENW, SCREENH
), 'RGBA')
va.getscr = True
return image2blit

this code took too long to convert back and fourth. around 6 seconds.

screen = SCREEN.subsurface(0, 0, SCREENW, SCREENH)
image2blit = pygame.Surface.convert_alpha(screen)
memsave = StringIO()
pygame.image.save(image2blit, memsave)
memsave.seek(0)
pygame.image.load(memsave, iname)  <- code crashes here
strA = XOR(iname, coder)
str1 = base64.b64encode(strA)
scrnstore [filename] = str1

the above code crashes at the point marked with the message pygame.error:
unsupported image format. What I want to do is to grab the screen surface,
convert it to a string format and save to a dictionary.
The dictionary will be pickled and saved to a file.
I want all my images in this file and NOT AS IMAGE FILES ON DISK.
Please help to resolve this.





On Wed, Sep 10, 2014 at 10:05 AM, Peter Shinners  wrote:

> On 09/09/2014 04:57 AM, diliup gabadamudalige wrote:
>
>>
>> How can a Pygame surface be converted to an image file say a jpeg or a
>> png WITHOUT writing the file to disk? Say after a screen grab?
>>
>>
>
> It is not highly documented, but you can pass a file-like object to
> pygame.image.save. So instead of a filename you could create a StringIO
> buffer and write into that. Or you could use something crazy like an html
> post request and upload directly to a website.
>
> If you are trying to load the image into a different library, it will be
> easier to use the "tobuffer" or "tostring" methods on the Surface. Then
> hope the other library you are using has a fromstring, frombuffer, or
> fromdata style function.
>
>
>


-- 
Diliup Gabadamudalige

http://www.diliupg.com
http://soft.diliupg.com/

**
This e-mail is confidential. It may also be legally privileged. If you are
not the intended recipient or have received it in error, please delete it
and all copies from your system and notify the sender immediately by return
e-mail. Any unauthorized reading, reproducing, printing or further
dissemination of this e-mail or its contents is strictly prohibited and may
be unlawful. Internet communications cannot be guaranteed to be timely,
secure, error or virus-free. The sender does not accept liability for any
errors or omissions.
**


Re: [pygame] Pygame surface

2014-09-09 Thread Peter Shinners

On 09/09/2014 04:57 AM, diliup gabadamudalige wrote:


How can a Pygame surface be converted to an image file say a jpeg or a 
png WITHOUT writing the file to disk? Say after a screen grab?





It is not highly documented, but you can pass a file-like object to 
pygame.image.save. So instead of a filename you could create a StringIO 
buffer and write into that. Or you could use something crazy like an 
html post request and upload directly to a website.


If you are trying to load the image into a different library, it will be 
easier to use the "tobuffer" or "tostring" methods on the Surface. Then 
hope the other library you are using has a fromstring, frombuffer, or 
fromdata style function.