Simple Stegano Watermarker

Applications, Games, Tools, User libs and useful stuff coded in PureBasic
User avatar
ar-s
Enthusiast
Enthusiast
Posts: 344
Joined: Sat Oct 06, 2007 11:20 pm
Location: France

Simple Stegano Watermarker

Post 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
~Ar-S~
My Image Hoster for PB users
My webSite (french) with PB apps : LDVMULTIMEDIA
PB - 3.x / 5.7x / 6 - W11 x64 - Ryzen 7 3700x / #Rpi4

Code: Select all

r3p347 : 7ry : un71l d0n3 = 1
User avatar
Caronte3D
Addict
Addict
Posts: 1355
Joined: Fri Jan 22, 2016 5:33 pm
Location: Some Universe

Re: Simple Stegano Watermarker

Post by Caronte3D »

Nice! :D
Thanks!
User avatar
Thorsten1867
Addict
Addict
Posts: 1372
Joined: Wed Aug 24, 2005 4:02 pm
Location: Germany

Re: Simple Stegano Watermarker

Post 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
Translated with http://www.DeepL.com/Translator

Download of PureBasic - Modules
Download of PureBasic - Programs

[Windows 11 x64] [PB V5.7x]
User avatar
ar-s
Enthusiast
Enthusiast
Posts: 344
Joined: Sat Oct 06, 2007 11:20 pm
Location: France

Re: Simple Stegano Watermarker

Post by ar-s »

@Thorsten1867
Another crazy module. Great one.
note : you should add the others UseXXXDecoderImage() to the bottom exemple
~Ar-S~
My Image Hoster for PB users
My webSite (french) with PB apps : LDVMULTIMEDIA
PB - 3.x / 5.7x / 6 - W11 x64 - Ryzen 7 3700x / #Rpi4

Code: Select all

r3p347 : 7ry : un71l d0n3 = 1
User avatar
jacdelad
Addict
Addict
Posts: 1991
Joined: Wed Feb 03, 2021 12:46 pm
Location: Riesa

Re: Simple Stegano Watermarker

Post 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:
Good morning, that's a nice tnetennba!

PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
Post Reply