Avi Thumbnails Maker

Share your advanced PureBasic knowledge/code with the community.
peterb
User
User
Posts: 60
Joined: Sun Oct 02, 2005 8:55 am
Location: Czech Republic
Contact:

Avi Thumbnails Maker

Post by peterb »

Code updated for 5.20+

you may use drag and drop for insert input AVI file

Code: Select all

;- Author   : Petr Vavrin (peterb)
;- Location : Czech Republic
;- Email    : pb.pb@centrum.cz

#streamtypeVIDEO = $73646976
#AVIGETFRAMEF_BESTDISPLAYFMT = 1
#AVI_ERR_OK = 0

Enumeration
  #Lib
  #File
EndEnumeration

Enumeration
  #Window
  #InputFile
  #OutputFile
  #BrowseInput
  #BrowseOutput
  #show_out_border
  #show_frame_border
  #output_width
  #output_columns
  #output_rows
  #frame_distance
  #show_top_info
  #show_frame_time
  #show_frame_shadow
  #box_bg_color_img
  #box_bg_color
  #box_top_color_img
  #box_top_color
  #box_ob_color_img
  #box_ob_color
  #box_fr_color_img
  #box_fr_color
  #box_t_color_img
  #box_t_color
  #box_to_color_img
  #box_to_color
  #output_type
  #StartButton
  #progress
  #status
EndEnumeration

Structure msvc
  a.b
  b.b
  c.b
  d.b
EndStructure

Structure AVISTREAMINFO
  fccType.l
  fccHandler.msvc
  dwFlags.l
  dwCaps.l
  wPriority.w
  wLanguage.w
  dwScale.l
  dwRate.l
  dwStart.l
  dwLength.l
  dwInitialFrames.l
  dwSuggestedBufferSize.l
  dwQuality.l
  dwSampleSize.l
  rcFrame.RECT 
  dwEditCount.l
  dwFormatChangeCount.l
  szName.b[64]
EndStructure

Global pAVIFile.l
Global pAVIStream.l
Global ErrorString.s

; ---------------------------------------------------------------
; for GUI

Global output_image_width.l  = 800
Global output_bg_color.l     = RGB (255, 255, 255)
Global thumbnails_rows.l     = 4
Global thumbnails_cols.l     = 3
Global thumbnails_distance.l = 20
Global thumbnails_images.l   = thumbnails_rows * thumbnails_cols

Global show_frame_border     = 1
Global frame_border_color    = RGB (0, 0, 0)

Global show_output_border    = 1
Global output_border_color   = RGB (0, 0, 0)

Global show_top_info         = 1
Global top_gradient_color    = RGB (255, 180, 0)

Global show_frame_shadow     = 1

Global show_frame_time       = 1
Global frame_time_color      = RGB (230, 230, 230)
Global frame_time_out_color  = RGB (0, 0, 0)

Global output_type.s         = "JPG"
Global top_offset.l
Global output_image_width.l
Global output_image_height.l
Global original_image_width.f
Global original_image_height.f

Global avifile.s

#Output_Image = 1111
#BS_FLAT  = $8000


Macro IIf (expr, truepart, falsepart)

  If expr : truepart : Else : falsepart : EndIf

EndMacro

Procedure.l DropFiles()

  ProcedureReturn EventwParam()

EndProcedure

Procedure GetNumDropFiles(*dropFiles)

  ProcedureReturn DragQueryFile_(*dropFiles, $FFFFFFFF, temp$, 0)

EndProcedure

Procedure.s GetDropFile(*dropFiles, index)
 
  bufferNeeded = DragQueryFile_(*dropFiles, index, 0, 0)
  For a = 1 To bufferNeeded: buffer$ + " ": Next ; Short by one character!
  DragQueryFile_(*dropFiles, index, buffer$, bufferNeeded+1)
  ProcedureReturn buffer$

EndProcedure

Procedure FreeDropFiles(*dropFiles)

   DragFinish_(*dropFiles)

EndProcedure

Procedure AVI_LOAD ( avifile.s)

  If CallFunction( #Lib, "AVIFileOpen", @pAVIFile, @avifile.s, #OF_SHARE_DENY_WRITE, 0 ) = #AVI_ERR_OK
    If CallFunction( #Lib, "AVIFileGetStream", pAVIFile, @pAVIStream, #streamtypeVIDEO, 0 )  = #AVI_ERR_OK
      ProcedureReturn #True
    EndIf
  EndIf
  ProcedureReturn #False

EndProcedure

Procedure AVI_UNLOAD ()

  If CallFunction( #Lib, "AVIFileRelease", pAVIFile ) = #AVI_ERR_OK
    ProcedureReturn #True
  EndIf
  ProcedureReturn #False
 
EndProcedure

Procedure AVI_GET_IMAGE ( image_number.l, frame_number.l )

  *ptr.BITMAPINFOHEADER
  bfh.BITMAPFILEHEADER
  _return = #False

  firstFrame = CallFunction( #Lib, "AVIStreamStart", pAVIStream )
  numFrames  = CallFunction( #Lib, "AVIStreamLength", pAVIStream )

  If frame_number < firstFrame Or frame_number > numFrames
    ProcedureReturn #False
  EndIf

  pGetFrameObj.l = CallFunction( #Lib, "AVIStreamGetFrameOpen", pAVIStream, #AVIGETFRAMEF_BESTDISPLAYFMT )
  If pGetFrameObj = 0
    ProcedureReturn #False
  EndIf
 
  *ptr = CallFunction( #Lib, "AVIStreamGetFrame", pGetFrameObj, frame_number )
       
  If *ptr
    bfh\bfType = $4d42
    bfh\bfSize = SizeOf(BITMAPFILEHEADER) + *ptr\biSize + *ptr\biSizeImage
    bfh\bfReserved1 = 0
    bfh\bfReserved2 = 0
    bfh\bfOffBits = SizeOf(BITMAPFILEHEADER) + *ptr\biSize
       
    *ImageMemory = AllocateMemory(SizeOf(BITMAPFILEHEADER) + SizeOf(BITMAPINFOHEADER) + *ptr\biSizeImage)
         
    If *ImageMemory
      CopyMemory(@bfh, *ImageMemory, SizeOf(BITMAPFILEHEADER))
      CopyMemory(*ptr, *ImageMemory + SizeOf(BITMAPFILEHEADER), SizeOf(BITMAPINFOHEADER) + *ptr\biSizeImage)
      CatchImage (image_number, *ImageMemory)
      FreeMemory (*ImageMemory)
      _return = #True
    EndIf

  EndIf
 
  CallFunction( #Lib, "AVIStreamGetFrameClose", pGetFrameObj )
  ProcedureReturn _return

EndProcedure

Procedure AVI_FIRST_FRAME ()
 
  firstFrame = CallFunction( #Lib, "AVIStreamStart", pAVIStream )
  ProcedureReturn firstFrame

EndProcedure

Procedure AVI_LENGTH ()

  length = CallFunction( #Lib, "AVIStreamLength", pAVIStream )
  ProcedureReturn length

EndProcedure

Procedure AVI_NUM_FRAMES ()

  numFrames  = CallFunction( #Lib, "AVIStreamLength", pAVIStream )
  ProcedureReturn numFrames

EndProcedure

Procedure AVI_FPS ()

  result = CallFunction( #Lib, "AVIStreamInfo", pAVIStream, @pfi.AVISTREAMINFO, SizeOf(AVISTREAMINFO) )
 
  IIf ( result = #AVI_ERR_OK, ProcedureReturn (pfi\dwRate / pfi\dwScale), ProcedureReturn 0 )

EndProcedure

Procedure DRAW_TOP (image.l)

  If StartDrawing ( ImageOutput(image) )
    Box(0, top_offset, output_image_width, output_image_height , output_bg_color)

    bg_red   = Red   (output_bg_color)
    bg_green = Green (output_bg_color)
    bg_blue  = Blue  (output_bg_color)
         
    gr_red   = Red   (top_gradient_color)
    gr_green = Green (top_gradient_color)
    gr_blue  = Blue  (top_gradient_color)
           
    If bg_red > gr_red
      step_red.f =      ( bg_red     - gr_red   ) / top_offset
    Else
      step_red.f = 0 - (( gr_red     - bg_red   ) / top_offset )
    EndIf
   
    If bg_green > gr_green
      step_green.f =      ( bg_green - gr_green ) / top_offset
    Else
      step_green.f = 0 - (( gr_green - bg_green ) / top_offset )
    EndIf
           
    If bg_blue > gr_blue
      step_blue.f =      ( bg_blue   - gr_blue  ) / top_offset
    Else
      step_blue.f = 0 - (( gr_blue   - bg_blue  ) / top_offset )
    EndIf
 
    For i=0 To top_offset
      actual_red.l   = gr_red   + ( step_red   * i )
      actual_green.l = gr_green + ( step_green * i )
      actual_blue.l  = gr_blue  + ( step_blue  * i )
      Box(0, i, output_image_width, 1, RGB(actual_red, actual_green, actual_blue))   
    Next
         
    file_size.l         = FileSize(avifile)
    avi_length.l        = AVI_LENGTH()
    avi_fps.l           = AVI_FPS()
           
    avi_duration_min.s  = RSet( Str((( avi_length / avi_fps ) / 60 ) % 60), 2, "0")
    avi_duration_hour.s = RSet( Str((( avi_length / avi_fps ) / 60 ) / 60), 2, "0")
    avi_duration_sec.s  = RSet( Str((  avi_length / avi_fps ) % 60),        2, "0")
           
    FrontColor(RGB(20, 20, 20))
             
    If FontID(1)
      DrawingFont(FontID(1))
    EndIf
           
    DrawingMode( #PB_2DDrawing_Transparent )
    DrawText(10,  10, "File Name:")
    DrawText(100, 10, GetFilePart(avifile))
           
    DrawText(10,  30, "File Size:")
    DrawText(100, 30, Str (file_size >> 20) + " MB (" + Str(file_size) + " bytes)")       
   
    DrawText(10,  50, "Resolution:")
    DrawText(100, 50, Str(original_image_width) + " x " + Str(original_image_height))
           
    DrawText(10,  70, "Duration:")
    DrawText(100, 70, avi_duration_hour + ":" + avi_duration_min + ":" + avi_duration_sec + " (" + Str(avi_fps) + " fps)")

    StopDrawing()
  EndIf

EndProcedure

Procedure DRAW_BORDER (image.l, border_color.l)

  width  = ImageWidth  ( image )
  height = ImageHeight ( image )

  If StartDrawing ( ImageOutput ( image ) )
    LineXY(        0,          0, width - 1,          0, border_color)
    LineXY(width - 1,          0, width - 1, height - 1, border_color)
    LineXY(width - 1, height - 1,         0, height - 1, border_color)
    LineXY(        0, height - 1,         0,          0, border_color)

    StopDrawing()
  EndIf

EndProcedure

Procedure DRAW_TIME_INFO (image.l, frame_number.l )

  width  = ImageWidth(image)
  height = ImageHeight(image)
 
  avi_fps = AVI_FPS ()
 
  avi_frame_min.s  = RSet( Str((( frame_number / avi_fps ) / 60 ) % 60), 2, "0")
  avi_frame_hour.s = RSet( Str((( frame_number / avi_fps ) / 60 ) / 60), 2, "0")
  avi_frame_sec.s  = RSet( Str((  frame_number / avi_fps ) % 60),        2, "0")
  avi_frame_time.s = avi_frame_hour + ":" + avi_frame_min + ":" + avi_frame_sec

  If StartDrawing(ImageOutput(image))

    If FontID(1)
      DrawingFont(FontID(2))
    EndIf

    DrawingMode( #PB_2DDrawing_Transparent )
             
    text_width.l  = TextWidth(avi_frame_time)
    text_height.l = TextHeight(avi_frame_time)
    text_x.l      = width  - text_width  - 4
    text_y.l      = height - text_height - 4
             
    FrontColor(frame_time_out_color)
    DrawText(text_x + 1, text_y + 1, avi_frame_time)
    DrawText(text_x - 1, text_y + 1, avi_frame_time)
    DrawText(text_x - 1, text_y - 1, avi_frame_time)
    DrawText(text_x + 1, text_y - 1, avi_frame_time)
           
    DrawText(text_x + 0, text_y + 1, avi_frame_time)
    DrawText(text_x + 0, text_y - 1, avi_frame_time)
    DrawText(text_x - 1, text_y + 0, avi_frame_time)
    DrawText(text_x + 1, text_y + 0, avi_frame_time)
 
    FrontColor(frame_time_color)
    DrawText(text_x, text_y, avi_frame_time)
 
    StopDrawing()
             
  EndIf

EndProcedure

Procedure MAKE_AVI_THUMBNAILS ( avifile.s )

  If AVI_LOAD( avifile )
           
    avi_fps         = AVI_FPS()
    avi_first_frame = AVI_FIRST_FRAME()
    avi_num_frame   = AVI_NUM_FRAMES()
 
    frame_step.l = ( avi_num_frame - avi_first_frame ) / ( thumbnails_images + 1 )
   
    If AVI_GET_IMAGE (9999, avi_first_frame)
   
      original_image_width.f  = ImageWidth  (9999)
      original_image_height.f = ImageHeight (9999)
     
      image_width    = ( (output_image_width - 1) / thumbnails_cols ) - thumbnails_distance
      image_height   = original_image_height * ( image_width / original_image_width )
      image_distance = ( output_image_width - ( image_width * thumbnails_cols ) ) / ( thumbnails_cols + 1 )
 
      If show_top_info = 1 : top_offset = 90 : Else : top_offset = 0 : EndIf
 
      output_image_height = top_offset + ( ( image_height + image_distance ) * thumbnails_rows ) + image_distance
   
      If CreateImage ( #Output_Image, output_image_width, output_image_height )
        If show_top_info = 1
          DRAW_TOP(#Output_Image)
        EndIf
       
        If show_output_border = 1
          DRAW_BORDER (#Output_Image, output_border_color)
        EndIf
       
      EndIf
   
      image_number = 0
      avi_frame    = ( avi_first_frame + frame_step )
      While ( avi_frame <= ( avi_num_frame - frame_step ))
   
        x = image_distance + ((image_number % thumbnails_cols) * (image_width  + image_distance))
        y = image_distance + ((image_number / thumbnails_cols) * (image_height + image_distance))
         
        If AVI_GET_IMAGE (image_number, avi_frame)
       
          ResizeImage(image_number, image_width , image_height)

          If show_frame_time = 1
            DRAW_TIME_INFO (image_number, avi_frame )
          EndIf
           
          If show_frame_border = 1
            DRAW_BORDER (image_number, frame_border_color)
          EndIf
           
          If StartDrawing(ImageOutput(#Output_Image))
            If show_frame_shadow = 1
              shadow_red_color   = Red   ( output_bg_color ) - ( Red   (output_bg_color) / 3)
              shadow_green_color = Green ( output_bg_color ) - ( Green (output_bg_color) / 3)
              shadow_blue_color  = Blue  ( output_bg_color ) - ( Blue  (output_bg_color) / 3)
              shadow_color       = RGB   (shadow_red_color, shadow_green_color, shadow_blue_color)
             
              Box(x + 3, y + top_offset + 3, image_width, image_height, shadow_color)
            EndIf
             
            DrawImage(ImageID(image_number), x, y + top_offset, 0, 0)
            StopDrawing()
          Else
            ProcedureReturn #False
          EndIf
        EndIf
       
        progress_value.f = (100 / thumbnails_images) * (image_number + 1)
        SetGadgetState(#progress, progress_value)

        image_number + 1
        avi_frame + frame_step
      Wend
     
    EndIf
 
    If AVI_UNLOAD () = #AVI_ERR_OK
      ProcedureReturn #True

    EndIf
  Else
    ProcedureReturn #False
  EndIf
 
EndProcedure

Procedure change_color (gadget.l, image.l, color.l)

  box_h.l = 16
  box_w.l = 50 - 4

  If color > -1
    If StartDrawing ( ImageOutput(image) )
      Box(0, 0, box_w, box_h , RGB(0, 0, 0))
      Box(1, 1, box_w - 2, box_h - 2 , color)
      StopDrawing()
    EndIf
    SetGadgetState(gadget, ImageID(image))
    ProcedureReturn #True
  Else
    ProcedureReturn #False
  EndIf

EndProcedure     

Procedure Set_Numeric_Style (gadget.l, numbers.l)

  SendMessage_    (GadgetID(gadget), #EM_SETLIMITTEXT, numbers, 0)
  currentStyle  = GetWindowLong_(GadgetID(gadget), #GWL_STYLE)
  SetWindowLong_  (GadgetID(gadget), #GWL_STYLE, currentStyle | #PB_String_Numeric)

EndProcedure

Procedure Make_Color_Button (gadget.l, x.l, y.l, box_w.l, box_h.l, image.l, color.l)

  If CreateImage ( image, box_w - 4, box_h - 4 )
    If StartDrawing ( ImageOutput(image) )
      Box(0, 0, box_w - 4, box_h - 4, RGB(0, 0, 0))
      Box(1, 1, box_w - 6, box_h - 6 , color)
      StopDrawing()
    EndIf
    ButtonImageGadget(gadget, x, y, box_w, box_h , ImageID(image))
  EndIf

EndProcedure

; ------------------------------------------------------------------------------------------------------------

If OpenLibrary  ( #Lib, "AVIFIL32.DLL" )
  If CallFunction ( #Lib,  "AVIFileInit" ) = #AVI_ERR_OK
 
    If OpenWindow(#Window, 0, 0, 600, 300, "Avi Thumbnails Maker", #PB_Window_MinimizeGadget | #PB_Window_ScreenCentered)
      DragAcceptFiles_(WindowID(#Window), 1)
 
      FrameGadget(#PB_Any, 5, 5, WindowWidth(#Window) - 10, WindowHeight(#Window) - 10, "", #PB_Frame_Flat)
       
      TextGadget        (#PB_Any,            10, 15, 60, 20, "Source File:")
      TextGadget        (#PB_Any,            10, 40, 60, 20, "Output File:")
       
      StringGadget      (#InputFile,         70, 10, 435, 20, "", #WS_EX_STATICEDGE | #WS_BORDER)
      StringGadget      (#OutputFile,        70, 35, 435, 20, "", #WS_EX_STATICEDGE | #WS_BORDER)
       
      ButtonGadget      (#BrowseInput,       510, 10, 80, 20, "Browse", #BS_FLAT )
      ButtonGadget      (#BrowseOutput,      510, 35, 80, 20, "Browse", #BS_FLAT )
 
      TextGadget        (#PB_Any,            70, 70, 100, 20, "Output type:")
      TextGadget        (#PB_Any,            70, 95, 100, 20, "Output width:")
      TextGadget        (#PB_Any,            70, 120, 60, 20, "Cols:")
      TextGadget        (#PB_Any,            70, 145, 60, 20, "Rows:")
      TextGadget        (#PB_Any,            70, 170, 80, 20, "Frame Distance:")
       
      ComboBoxGadget    (#output_type,       160, 65, 50, 100)
      AddGadgetItem     (#output_type,       0, "JPG")
      AddGadgetItem     (#output_type,       1, "BMP")
      SetGadgetState    (#output_type,       0)
       
       
      StringGadget      (#output_width,      160, 90, 50, 20, Str(output_image_width))
      Set_Numeric_Style (#output_width,   4)

      StringGadget      (#output_columns,    160, 115, 50, 20, Str(thumbnails_cols))
      Set_Numeric_Style (#output_columns, 2)

      StringGadget      (#output_rows,       160, 140, 50, 20, Str(thumbnails_rows))
      Set_Numeric_Style (#output_rows,    2)

      StringGadget      (#frame_distance,    160, 165, 50, 20, Str(thumbnails_distance))
      Set_Numeric_Style (#frame_distance, 3)

      CheckBoxGadget    (#show_top_info,     240,  65, 150, 20, "Show top info")
      SetGadgetState    (#show_top_info,     show_output_border)
       
      CheckBoxGadget    (#show_out_border,   240,  90, 150, 20, "Show output border")
      SetGadgetState    (#show_out_border,   show_output_border)
       
      CheckBoxGadget    (#show_frame_border, 240, 115, 150, 20, "Show frame border")
      SetGadgetState    (#show_frame_border, show_top_info)
       
      CheckBoxGadget    (#show_frame_time,   240, 140, 150, 20, "Show frame time")
      SetGadgetState    (#show_frame_time,   show_frame_time)
 
      CheckBoxGadget    (#show_frame_shadow, 240, 165, 150, 20, "Show frame shadow")
      SetGadgetState    (#show_frame_shadow, show_frame_shadow)
       
      TextGadget        (#PB_Any, 460,  70, 90, 20, "Top")
      TextGadget        (#PB_Any, 460,  95, 90, 20, "Background")
      TextGadget        (#PB_Any, 460, 120, 90, 20, "Output Border")
      TextGadget        (#PB_Any, 460, 145, 90, 20, "Frame Border")
      TextGadget        (#PB_Any, 460, 170, 90, 20, "Time")
      TextGadget        (#PB_Any, 460, 195, 90, 20, "Time Outline")
       
      Make_Color_Button (#box_top_color, 400,  65, 50, 20, #box_top_color_img, top_gradient_color)
      Make_Color_Button (#box_bg_color,  400,  90, 50, 20, #box_bg_color_img,  output_bg_color)
      Make_Color_Button (#box_ob_color,  400, 115, 50, 20, #box_ob_color_img,  output_border_color)
      Make_Color_Button (#box_fr_color,  400, 140, 50, 20, #box_fr_color_img,  frame_border_color)
      Make_Color_Button (#box_t_color,   400, 165, 50, 20, #box_t_color_img,   frame_time_color)
      Make_Color_Button (#box_to_color,  400, 190, 50, 20, #box_to_color_img,  frame_time_out_color)

 
      TextGadget        (#PB_Any,   15, 210, 60, 20, "Progress:")
      TextGadget        (#status,   80, 210, 60, 20, "")
     
      ProgressBarGadget (#progress, 15, 230, 485, 15, 0, 100)
 
      ButtonGadget      (#StartButton,       510, 230, 80, 60, "Start", #BS_FLAT )
 
      TextGadget     (#PB_Any,   15, 270, 250, 20, "Author: Petr Vavrin [ pb.pb@centrum.cz ]")
      TextGadget        (#PB_Any,   320, 270, 120, 20, "Version: 1.0")
       
      LoadFont(1, "Arial", 10, #PB_Font_HighQuality)
      LoadFont(2, "Arial", 10, #PB_Font_HighQuality | #PB_Font_Bold )
 
      Repeat
        Event = WaitWindowEvent()
         
        If Event = #WM_DROPFILES
           *dropped = DropFiles()
           SetGadgetText(#InputFile, GetDropFile(*dropped, 0))
             
           If GetGadgetText(#OutputFile) = ""
             input$ =  GetGadgetText(#InputFile)
             out$ = ReplaceString(input$, "." + GetExtensionPart(input$), "." + LCase(GetGadgetText(#output_type)))
             SetGadgetText(#OutputFile, out$)
           EndIf
             
           FreeDropFiles(*dropped)
        EndIf
         
        If Event = #PB_Event_Gadget
         
          Select EventGadget()
             
            Case #output_width
              output_image_width  = Val(GetGadgetText(#output_width))
               
            Case #output_columns
              thumbnails_cols     = Val(GetGadgetText(#output_columns))
             
            Case #output_rows
              thumbnails_rows     = Val(GetGadgetText(#output_rows))
               
            Case #frame_distance
              thumbnails_distance = Val(GetGadgetText(#frame_distance))
               
            Case #show_frame_border
              show_frame_border   = Val(GetGadgetText(#show_frame_border))
               
            Case #show_out_border
              show_output_border  = GetGadgetState(#show_out_border)
             
            Case #show_top_info
              show_top_info       = GetGadgetState(#show_top_info)
               
            Case #show_frame_shadow
              show_frame_shadow   = GetGadgetState(#show_frame_shadow)
               
            Case #show_frame_time
              show_frame_time     = GetGadgetState(#show_frame_time)
 
            Case #box_top_color
              color.l = ColorRequester()
              If change_color (#box_top_color, #box_top_color_img, color) : top_gradient_color = color    : EndIf

            Case #box_bg_color
              color.l = ColorRequester()
              If change_color (#box_bg_color,  #box_bg_color_img, color)  : output_bg_color = color       : EndIf
               
            Case #box_fr_color
              color.l = ColorRequester()
              If change_color (#box_fr_color,  #box_fr_color_img, color)  : frame_border_color = color    : EndIf
               
            Case #box_ob_color
              color.l = ColorRequester()
              If change_color (#box_ob_color,  #box_ob_color_img, color)  : output_border_color = color   : EndIf

            Case #box_t_color
              color.l = ColorRequester()
              If change_color (#box_t_color,   #box_t_color_img, color)   : frame_time_color = color      : EndIf

            Case #box_to_color
              color.l = ColorRequester()
              If change_color (#box_to_color,  #box_to_color_img, color)   : frame_time_out_color = color : EndIf
         
          EndSelect

          If EventGadget() = #StartButton
 
            input_filename$  = GetGadgetText(#InputFile)
            output_filename$ = GetGadgetText(#OutputFile)
            avifile = input_filename$
            SetGadgetText ( #status, "" )
 
            If FileSize(input_filename$) > -1 And output_filename$ <> input_filename$
 
              If output_filename$ <> "" And CreateFile(#File, output_filename$)
                CloseFile (#File)
                If MAKE_AVI_THUMBNAILS( input_filename$ )
                  SetGadgetState(#progress, 0)
                  If #Output_Image
 
                    If GetGadgetText(#output_type) = "JPG"
                      UseJPEGImageEncoder()
                      SaveImage(#Output_Image, output_filename$,  #PB_ImagePlugin_JPEG, 10)
                    EndIf
 
                    If GetGadgetText(#output_type) = "BMP"
                      SaveImage(#Output_Image, output_filename$,  #PB_ImagePlugin_BMP)
                    EndIf
                   
                    SetGadgetText ( #status, "Finished" )
                   
                  Else
                    MessageRequester("Error", "Image not created")
                  EndIf
                EndIf
              Else
                MessageRequester("Error", "Output filename is blank or invalid")
              EndIf
            Else
              MessageRequester("Error", "Input file not exist")
            EndIf
             
          EndIf
           
          If EventGadget() = #BrowseInput
            last_path.s = GetPathPart(GetGadgetText(#InputFile))
             
            IIf ( last_path <> "", StandardFile$ = last_path, StandardFile$ = "C:\" )
             
            File$ = OpenFileRequester("Please choose file to load", StandardFile$, "Avi (*.avi)", 0)

            If File$
              avifile = File$
              SetGadgetText(#InputFile, File$)
            EndIf
             
            If GetGadgetText(#OutputFile) = ""
              input$ =  GetGadgetText(#InputFile)
              out$   = ReplaceString(input$, "." + GetExtensionPart(input$), "." + LCase(GetGadgetText(#output_type)))
              SetGadgetText(#OutputFile, out$)
            EndIf
 
            EndIf
           
          If EventGadget() = #BrowseOutput
            last_path.s = GetPathPart(GetGadgetText(#OutputFile))
            If last_path <> ""
              StandardFile$ = last_path
            Else
              StandardFile$ = "C:\"
            EndIf
            Pattern$ = "BMP (*.bmp)|*.bmp|JPG (*.jpg)|*.jpg"
             
            If GetGadgetText(#output_type) = "JPG"
              Pattern = 1
            Else
              Pattern = 0
            EndIf
             
            File$ = SaveFileRequester("Please choose file to save", StandardFile$, Pattern$, Pattern)
             
            Index = SelectedFilePattern()
            If Index > -1
              If Index = 0
                File$ + ".bmp"
                SetGadgetText(#output_type, "BMP")
              ElseIf Index = 1
                File$ + ".jpg"
                SetGadgetText(#output_type, "JPG")
              EndIf
            EndIf
                 
            If File$
              SetGadgetText(#OutputFile, File$)
            EndIf
 
          EndIf 
           
          If EventGadget() = #output_type
            old_file$ = GetGadgetText(#OutputFile)
            If old_file$ <> ""
               
              new_file$ = ReplaceString(old_file$, "." + GetExtensionPart(old_file$), "." + LCase(GetGadgetText(#output_type)))
              SetGadgetText(#OutputFile, new_file$)
               
            EndIf     
          EndIf
        EndIf
         
      Until Event = #PB_Event_CloseWindow
 
        CloseWindow(#Window)
      EndIf

    CallFunction( #Lib, "AVIFileExit" )
  EndIf
   
  CloseLibrary( #Lib )
EndIf

End
Tommeh
Enthusiast
Enthusiast
Posts: 149
Joined: Sun Aug 29, 2004 2:25 pm
Location: United Kingdom

Post by Tommeh »

Gives peterb a gold star! Good work with this and your ISO maker, thanks for the handy code! :)
Tranquil
Addict
Addict
Posts: 952
Joined: Mon Apr 28, 2003 2:22 pm
Location: Europe

Post by Tranquil »

damn, a new user and so great codes!! Thanks a lot and keep up your realy ass kicking work!!
Tranquil
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

Thanks for these great contributions!

One tiny thing, with this:

Code: Select all

StringGadget (#InputFile, 70, 10, 435, 20, "", #WS_EX_STATICEDGE | #WS_BORDER) 
GWL_STYLE bits and GWL_EXSTYLE bits can't be mixed in this way. By coincidence WS_EX_STATICEDGE is the same value as #PB_String_Borderless, which is why you're getting the result you're looking for. To see what the actual #WS_EX_STATICEDGE style looks like, you could do this:

Code: Select all

      SetWindowLong_(GadgetID(#inputfile), #GWL_EXSTYLE, GetWindowLong_(GadgetID(#inputfile), #GWL_EXSTYLE) &~ #WS_EX_CLIENTEDGE)
      SetWindowLong_(GadgetID(#inputfile), #GWL_EXSTYLE, GetWindowLong_(GadgetID(#inputfile), #GWL_EXSTYLE) | #WS_EX_STATICEDGE)
      SetWindowPos_(GadgetID(#inputfile),0,0,0,0,0,#SWP_NOZORDER|#SWP_NOSIZE|#SWP_NOMOVE|#SWP_FRAMECHANGED)
Welcome to the forums and keep the great codes coming :D
BERESHEIT
Derek
Addict
Addict
Posts: 2354
Joined: Wed Apr 07, 2004 12:51 am
Location: England

Post by Derek »

Very nice, will come in handy, would say welcome to the forums but I notice you joined in 2005 so that makes you an old timer. :lol:
Post Reply