flat assembler
Message board for the users of flat assembler.

Index > Tutorials and Examples > [help] Saving a bitmap in memory to a png on disk?

Goto page Previous  1, 2
Author
Thread Post new topic Reply to topic
nasm



Joined: 02 Nov 2021
Posts: 182
nasm 29 Sep 2024, 21:12
If there should be any point in doing PNG in assembly, it should be all assembly and therefore we need volunteers who can post their private PNG code here. Anyone?
Post 29 Sep 2024, 21:12
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4043
Location: vpcmpistri
bitRAKE 30 Sep 2024, 00:34
Do you have a github or something? Where can I see your work nasm?

_________________
¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup
Post 30 Sep 2024, 00:34
View user's profile Send private message Visit poster's website Reply with quote
nasm



Joined: 02 Nov 2021
Posts: 182
nasm 30 Sep 2024, 06:36
bitRAKE, no github for me. I've never posted my code anywhere so far.

_________________
Do you think anyone will sell their soul over a 10 cent yoghurt with a bad after taste that lasts, a decade?
Post 30 Sep 2024, 06:36
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4043
Location: vpcmpistri
bitRAKE 03 Oct 2024, 14:52
Here is the brief way to load any WIC supported image format and write out as another supported format:
Code:
        .inputPath      dq ? ; wide-string
        .outputPath     dq ? ; wide-string

; needed COM objects:
        .pFactory       IWICImagingFactory
        .pDecoder       IWICBitmapDecoder
        .pFrame         IWICBitmapFrameDecode
        .pConverter     IWICFormatConverter
        .pStream        IWICStream
        .pEncoder       IWICBitmapEncoder
        .pFrameEncode   IWICBitmapFrameEncode

        CoCreateInstance & CLSID_WICImagingFactory2, NULL, CLSCTX_INPROC_SERVER, & IID_IWICImagingFactory, & .pFactory

        IWICImagingFactory__CreateDecoderFromFilename [.pFactory], [.inputPath], NULL, GENERIC_READ, WICDecodeMetadataCacheOnDemand, & .pDecoder
        IWICBitmapDecoder__GetFrame [.pDecoder], 0, & .pFrame

; create and configuring converter for desired output format:

        IWICImagingFactory__CreateFormatConverter [.pFactory], & .pConverter
        IWICFormatConverter__Initialize [.pConverter], [.pFrame], & GUID_WICPixelFormat32bppBGRA, WICBitmapDitherTypeNone, NULL, 0.0, WICBitmapPaletteTypeCustom

        IWICImagingFactory__CreateStream [.pFactory], & .pStream
        IWICStream__InitializeFromFilename [.pStream], [.outputPath], GENERIC_WRITE

        IWICImagingFactory__CreateEncoder [.pFactory], & GUID_ContainerFormatBmp, NULL, & .pEncoder
        IWICBitmapEncoder__Initialize [.pEncoder], [.pStream], WICBitmapEncoderNoCache

        IWICBitmapEncoder__CreateNewFrame [.pEncoder], & .pFrameEncode, NULL
        IWICBitmapFrameEncode__Initialize [.pFrameEncode], NULL

        {data:16} .format ddq ? ; format need to be readwrite
        movdqa xmm0, [GUID_WICPixelFormat32bppBGRA]
        movdqa [.format], xmm0
        IWICBitmapFrameEncode__SetPixelFormat [.pFrameEncode], & .format

; write the converted pixels to the frame

        IWICBitmapFrameEncode__WriteSource [.pFrameEncode], [.pConverter], NULL
        IWICBitmapFrameEncode__Commit [.pFrameEncode]
        IWICBitmapEncoder__Commit [.pEncoder]    
Use one of the GUID_ContainerFormat* values to change the encoder, or GUID_WICPixelFormat* to change the pixel data desired.

Note: no error checking - lots of HRESULTS to examine, and IUnknown__Release all the objects when done. The important thing is to watch what data types and access restriction each parameter has. I've tested the code and it does work - this is the minimal process needed.
Post 03 Oct 2024, 14:52
View user's profile Send private message Visit poster's website Reply with quote
nasm



Joined: 02 Nov 2021
Posts: 182
nasm 07 Oct 2024, 09:36
bitRAKE, I'm going to try it soon. You're one of the legends who still care about the assembly forum.

The truth is, we DO need more PNG code, this example will get us far, but we do need to have alternatives too. It's a great world, the needs are also great.

Do we have more legends? The fact of the matter is that it can be more than just PNG, if you have a custom image format that works well for video processing, that too is welcome.
Post 07 Oct 2024, 09:36
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4336
Location: Now
edfed 07 Oct 2024, 10:58
hem. an idea like this.. why don't develop a set of binaries that can be installed in ram and be called like any bios function? libpng can be one of these.
Post 07 Oct 2024, 10:58
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20343
Location: In your JS exploiting you and your system
revolution 07 Oct 2024, 11:33
Code:
~ find /lib* -iname "libpng*"
/lib/x86_64-linux-gnu/libpng12.so.0.54.0
/lib/x86_64-linux-gnu/libpng12.so.0
/lib/i386-linux-gnu/libpng12.so.0.54.0
/lib/i386-linux-gnu/libpng12.so.0
~    
Post 07 Oct 2024, 11:33
View user's profile Send private message Visit poster's website Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4043
Location: vpcmpistri
bitRAKE 08 Oct 2024, 05:31
nasm wrote:
You're one of the legends who still care about the assembly forum.
Do we have more legends?
I appreciate your enthusiasm, but perhaps you go too far. People contribute what they can - myself included. My ability to contribute is my good fortune (and the generosity of others) and I wish for it to be yours as well.

_________________
¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup
Post 08 Oct 2024, 05:31
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page Previous  1, 2

< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.