Page 1 of 1

Simple Stegano Watermarker

Posted: Sat Jul 09, 2022 9:56 am
by ar-s
Simple STEGANO WATERMARKER Is a program that will insert a signature of your choice in the alpha layer of the last pixels of your photos.
The result is saved in PNG to keep the alpha layer.

You are free to improve it (encryption key etc...)

EnJoY

Code: Select all

; =====================================================
;
; Simple STEGANO WATERMARKER
; by Ar-S // PB 6.00 x64
; https://ldvmultimedia.com
; 2022/07/09
; Free to use
;
; Only ASCII Chars avalaible
; ======================================================


Structure Car
    min.c
    maj.c
EndStructure

UsePNGImageDecoder()
UseJPEGImageDecoder()
UsePNGImageEncoder()

Declare.l pixel_3car(pixel)

Global NewList mot.car()
Global Fichier$
Global LONG
Global C
Global COUL.q


Procedure.l CatchPixel(pixel)
    
    R=Red(pixel)
    g=Green(pixel)
    b=Blue(pixel)
    a=Alpha(pixel)

    If a - mot()\min > a -mot()\maj
        a = mot()\maj
    Else
        a = mot()\min
    EndIf
    
    pixel=RGBA(R,G,B,a)

    ProcedureReturn pixel
EndProcedure




Word$ = InputRequester("Watermark","Enter your signature","")
LONG = Len(Word$)

If LONG > 0
    position = 1    
    For i = 1 To LONG
        Lettre$ = Mid(Word$,position,1)
        AddElement(mot())
        mot()\min = Asc(LCase(Lettre$))
        Mot()\maj = Asc(UCase(Lettre$))
        position +1
    Next
    
Else
    MessageRequester("Error","You have to enter a word.. This program will end",#PB_MessageRequester_Error)
    End
    
EndIf


IMAGE$ = ""
Filtre$ = "Image PNG/JPG/TIFF/TGA|*.tga;*.tiff;*.png;*.jpg"
Filtre  = 0
Fichier$ = OpenFileRequester("Choose a picture", FichierParDefaut$, Filtre$, Filtre)
If Fichier$ = ""
   End
EndIf 

If LoadImage(0,Fichier$)
     L = ImageWidth(0) - LONG
     H = ImageHeight(0)-1
    
    CreateImage(1, ImageWidth(0), ImageHeight(0), 32, $FFFFFF)
    
    StartDrawing(ImageOutput(1))
    DrawingMode(#PB_2DDrawing_AllChannels )
    DrawAlphaImage(ImageID(0),0,0,255)
    FreeImage(0)

    POS = L
    
    ;-1st Pixel where we indicate the length of the watermark
    LNGPIX = Point(0,0)
    ; We write the length
    Plot(0,0,RGBA(Red(LNGPIX),Green(LNGPIX),Blue(LNGPIX),LONG))
    
    ForEach mot()      
        COUL = Point(POS,H)
        Debug "RGBA = " + Str(Red(COUL))+","+ Str(Green(COUL))+","+ Str(Blue(COUL))+","+ Str(Alpha(COUL))
        Plot (POS,H, CatchPixel(COUL))
        POS+1
    Next   
    StopDrawing()
    
    DS$ = GetPathPart(Fichier$)
    FS$ = GetFilePart(Fichier$,#PB_FileSystem_NoExtension)
    Debug DS$+FS$+".png"
    SaveImage(1,DS$+FS$+"_signed.png",#PB_ImagePlugin_PNG,0,32 )
    FreeImage(1)
    
    
    
    
    ;-// CHECKING RESULT //////////////////////////////////////
    If LoadImage(0,DS$+FS$+"_signed.png")
        StartDrawing(ImageOutput(0))
        DrawingMode(#PB_2DDrawing_AlphaChannel)
        LONG = Alpha(Point(0,0))
        L = ImageWidth(0) - LONG
        H = ImageHeight(0)-1
        
        POS = L
        For i = 1 To LONG      
            Debug Chr(Alpha(Point(POS,H)))
            POS+1
        Next   
        StopDrawing()
        
    EndIf
    
EndIf

Re: Simple Stegano Watermarker

Posted: Sat Jul 09, 2022 10:57 am
by Caronte3D
Nice! :D
Thanks!

Re: Simple Stegano Watermarker

Posted: Sat Jul 09, 2022 11:02 am
by Thorsten1867
I have developed a complete module for this, if you are interested.
  • Embed files, XML, JSON and strings as (encrypted) data in images with lossless compression.
  • Encryption for the use of images as a licence code.
https://www.purebasic.fr/english/viewto ... 27&t=73582

Re: Simple Stegano Watermarker

Posted: Sat Jul 09, 2022 11:26 am
by ar-s
@Thorsten1867
Another crazy module. Great one.
note : you should add the others UseXXXDecoderImage() to the bottom exemple

Re: Simple Stegano Watermarker

Posted: Sat Jul 09, 2022 9:40 pm
by jacdelad
Ah come on Thorsten, you cannot refer to one of your modules whenever someone posts something. That's just not fair, keep some of the work for the rest of us! :mrgreen: