ogg vorbis comment (tag)

Just starting out? Need help? Post your questions and find answers here.
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3870
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: ogg vorbis comment (tag)

Post by wilbert »

You may be right that it has to do with the drawing of the alpha channel.
I would probably change the encode procedure to something like the code below and pass JPEGQuality -1 to encode for PNG.

Code: Select all

; >> EncodeVorbisPicture procedure <<

UseJPEGImageEncoder()
UsePNGImageEncoder()

Procedure.s EncodeVorbisPicture(Image, PictureType = 3, JPEGQuality = 7)
  
  Protected *Image, MIMEType.s, Offset, ImageDataSize, BufferSize
  
  If JPEGQuality >= 0
    ; JPEG
    *Image = EncodeImage(Image, #PB_ImagePlugin_JPEG, JPEGQuality)
    MIMEType = "image/jpeg"
    Offset = 42
  Else
    ; PNG
    *Image = EncodeImage(Image, #PB_ImagePlugin_PNG, 0, 32)
    MIMEType = "image/png"
    Offset = 41
  EndIf
  
  ImageDataSize = MemorySize(*Image)
  BufferSize = ImageDataSize + Offset
  
  ; Allocate Buffer array and copy the encoded image to it
  Protected Dim Buffer.a(BufferSize - 1)
  CopyMemory(*Image, @Buffer(Offset), ImageDataSize)
  FreeMemory(*Image)
  
  ; Set the additional information
  Buffer(3) = PictureType
  Buffer(7) = PokeS(@Buffer(8), MIMEType, -1, #PB_Ascii | #PB_String_NoZero)
  
  Buffer(Offset-4) = ImageDataSize >> 24
  Buffer(Offset-3) = ImageDataSize >> 16
  Buffer(Offset-2) = ImageDataSize >> 8
  Buffer(Offset-1) = ImageDataSize
  
  ; Return Base64 encoded Buffer without CRLF
  ProcedureReturn ReplaceString(Base64Encoder(@Buffer(0), BufferSize), #CRLF$, "")
  
EndProcedure
Windows (x64)
Raspberry Pi OS (Arm64)
collectordave
Addict
Addict
Posts: 1309
Joined: Fri Aug 28, 2015 6:10 pm
Location: Portugal

Re: ogg vorbis comment (tag)

Post by collectordave »

Hi wilbert

I attacked it by having two procedures one for jpg and one for png with an extra field in the imagetag for mimetype.

Each png image is encoded with its original depth and then coupled with DrawAlphaImage() it works fine.

Changed it all as I am now starting to get ready to batch tag Artist and title from the filename and to rename files based on the tags.

Maybe could offer support for other image formats such as bmp?

CD
Any intelligent fool can make things bigger and more complex. It takes a touch of genius — and a lot of courage to move in the opposite direction.
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3870
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: ogg vorbis comment (tag)

Post by wilbert »

collectordave wrote:I attacked it by having two procedures one for jpg and one for png
That will also work fine :)
collectordave wrote:Maybe could offer support for other image formats such as bmp?
Bmp isn't allowed. According to the file specification, an image has to be encoded as either jpeg or png.
So you can only load bmp files and recode as png or jpeg before embedding.
When it comes to png and jpeg images, you could also offer to embed the image as it is without recoding it.
Windows (x64)
Raspberry Pi OS (Arm64)
collectordave
Addict
Addict
Posts: 1309
Joined: Fri Aug 28, 2015 6:10 pm
Location: Portugal

Re: ogg vorbis comment (tag)

Post by collectordave »

Could load bmp then save as png etc will look into it a bit more.

Just added new li8nk to first page. Barch editing now possible for filename tags and writing filenames from tags.

More open format for the editor as well.

Regards

CD
Any intelligent fool can make things bigger and more complex. It takes a touch of genius — and a lot of courage to move in the opposite direction.
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3870
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: ogg vorbis comment (tag)

Post by wilbert »

Unfortunately the current version doesn't work on macOS.
I think it has to do with the fact that macOS uses a forward slash for directories while Windows uses a backslash.
Windows (x64)
Raspberry Pi OS (Arm64)
infratec
Always Here
Always Here
Posts: 6869
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: ogg vorbis comment (tag)

Post by infratec »

Wondows also accept / as delimiter for directories :wink:
collectordave
Addict
Addict
Posts: 1309
Joined: Fri Aug 28, 2015 6:10 pm
Location: Portugal

Re: ogg vorbis comment (tag)

Post by collectordave »

Trying on the mac and it works if everything is on the local drive except images.

Just tried openfilerequester on external drive and it fails on the mac posted a maybe bug.

CD

PS There is one bit in the select folder procedure where i use the \ changed to #PS$ and it loads.
Any intelligent fool can make things bigger and more complex. It takes a touch of genius — and a lot of courage to move in the opposite direction.
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3870
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: ogg vorbis comment (tag)

Post by wilbert »

collectordave wrote:Trying on the mac and it works if everything is on the local drive except images.

Just tried openfilerequester on external drive and it fails on the mac posted a maybe bug.

CD

PS There is one bit in the select folder procedure where i use the \ changed to #PS$ and it loads.
If I change the backslash, it does show the ogg files in a folder.
At first I assumed it would immediately show something if I would click on a filename but apparently I have to use the right-click button ?
If I do so, I can open a file and "Current song" shows the filename but the comment tags don't show anything.
Windows (x64)
Raspberry Pi OS (Arm64)
collectordave
Addict
Addict
Posts: 1309
Joined: Fri Aug 28, 2015 6:10 pm
Location: Portugal

Re: ogg vorbis comment (tag)

Post by collectordave »

Hi

After selecting a folder and the ogg files are shown in the list then right click gives the popup menu then select Load file and on my machine it shows the comments.


The popup is used to allow you to select multiple files to tag or rename.

CD
Any intelligent fool can make things bigger and more complex. It takes a touch of genius — and a lot of courage to move in the opposite direction.
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3870
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: ogg vorbis comment (tag)

Post by wilbert »

collectordave wrote:After selecting a folder and the ogg files are shown in the list then right click gives the popup menu then select Load file and on my machine it shows the comments.
It does show the tags now. Maybe I did something wrong.
There is however still a problem with showing embedded images.

ResizeImage doesn't return an image but resizes the original image.
Also when you draw an image, you need the ImageID which is not the same as the image number.
If you use DrawVectorImage, you don't need to resize the image and as far as I know, it will still work with transparent images.

Code: Select all

      If StartVectorDrawing(CanvasVectorOutput(cnvArtWork))
        MovePathCursor(0, 0)
        DrawVectorImage(ImageID(EditTags()\ImageID), 255, adjustedwidth, adjustedheight)
        StopVectorDrawing()     
      EndIf
Windows (x64)
Raspberry Pi OS (Arm64)
collectordave
Addict
Addict
Posts: 1309
Joined: Fri Aug 28, 2015 6:10 pm
Location: Portugal

Re: ogg vorbis comment (tag)

Post by collectordave »

Link on first page updated with (working code) tested on mac and win7 64bit pb 5.71

CD
Any intelligent fool can make things bigger and more complex. It takes a touch of genius — and a lot of courage to move in the opposite direction.
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3870
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: ogg vorbis comment (tag)

Post by wilbert »

collectordave wrote:Link on first page updated with (working code) tested on mac and win7 64bit pb 5.71
It works better now :)

When I open an ogg file with a front cover image in it, select one of the image types (Back Cover or Artist) that doesn't have an image and select "Front Cover" again, I get a crash.
Windows (x64)
Raspberry Pi OS (Arm64)
collectordave
Addict
Addict
Posts: 1309
Joined: Fri Aug 28, 2015 6:10 pm
Location: Portugal

Re: ogg vorbis comment (tag)

Post by collectordave »

Works ok on windows will dig out mac and try

Cd
Any intelligent fool can make things bigger and more complex. It takes a touch of genius — and a lot of courage to move in the opposite direction.
collectordave
Addict
Addict
Posts: 1309
Joined: Fri Aug 28, 2015 6:10 pm
Location: Portugal

Re: ogg vorbis comment (tag)

Post by collectordave »

Missed one

Lines 837 etc in new win main need to be changed

Code: Select all

  
                StartVectorDrawing(CanvasVectorOutput(cnvArtWork))
                    MovePathCursor(0,0)
                    DrawVectorImage(ImageID(EditTags()\ImageID),255,adjustedwidth,adjustedheight)
                  StopVectorDrawing()
Did the rest forgot this one.

Please try and tell me if this vures problem.

CD
Any intelligent fool can make things bigger and more complex. It takes a touch of genius — and a lot of courage to move in the opposite direction.
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3870
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: ogg vorbis comment (tag)

Post by wilbert »

collectordave wrote:Lines 837 etc in new win main need to be changed
That fixes the problem. :)
Windows (x64)
Raspberry Pi OS (Arm64)
Post Reply