Announcement

Collapse
No announcement yet.

Flickbook

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Flickbook

    This little app (PBWin10, easily converted to PBCC6) takes a bitmap off the clipboard which is assumed to be in the form of a tabulated flickbook. You click on the first and last frames and it attempts to play the flickbook back.

    BUT most of the flickbook images on the web have been photocopied a million times and are dimensionally dodgy, so the results are a bit rough.

    Any ideas on improvements?

    Code:
    #compile exe
    #dim all
    #debug display
    
    #include once "WIN32API.INC"
    
    global ghw, ghbk   as dword
    
    '--------------------------------------------------------------------------------------------------------------------------------------------------------------
    function pbmain as long
        local i, j, n, lclick, ncols, nrows as long
        local rstart, rend, rsize, rframes() as rect
        local lwidth, lheight  as long
        '
    
        clipboard get bitmap to ghbk
        if ghbk = 0 then
            ? "failed to find bitmap on clipboard!"
            goto 99
        end if
        graphic attach ghbk, 0
        graphic get canvas to lwidth, lheight
        if lwidth = 0 then
            ? "bitmap has zero size"
            goto 99
        end if
        graphic detach
    
        graphic window new "flickbook", _
                    0, 0, lwidth, lheight to gHW
        graphic attach gHW, 0, redraw
        graphic copy ghbk, 0
        graphic redraw
        graphic set caption "click on top left corner of first frame"
        while lclick = 0
            graphic window click to lclick, rstart.left, rstart.top
        wend
        lclick = 0
        graphic set caption "click on bottom right corner of first frame"
        while lclick = 0
            graphic window click to lclick, rstart.right, rstart.bottom
        wend
        lclick = 0
        graphic set caption "click on top left corner of last frame"
        while lclick = 0
            graphic window click to lclick, rend.left, rend.top
        wend
        lclick = 0
        graphic set caption "click on bottom right corner of last frame"
        while lclick = 0
            graphic window click to lclick, rend.right, rend.bottom
        wend
        ' calculate sizing rect for frame
        setrect rsize, 0, 0, _
                       ((rstart.right - rstart.left) + _
                        (rend.right - rend.left))/2, _
                       ((rstart.bottom - rstart.top) + _
                        (rend.bottom - rend.top))/2
        ' calculate number of columns
        ncols = (rend.right-rstart.left)/(rsize.right)
        ' calculate number of rows
        nrows = (rend.bottom - rstart.top)/rsize.bottom
        ? "ncols = " + str$(ncols) + ": nrows = " + str$(nrows)
        dim rframes(1 to nrows*ncols)
        for i = 1 to nrows
          for j = 1 to ncols
              n = j + ((i-1)*ncols)
              setrect rframes( n), _
                      (j-1) * rsize.right, _
                      (i-1) * rsize.bottom, _
                       j * rsize.right, _
                       i * rsize.bottom
          next
        next
        '  play the flickbook!
        graphic clear %blue
        for i = 1 to nrows
            for j = 1 to ncols
                n = j + ((i-1)*ncols)
                graphic stretch ghbk, 0, _
                    (rframes(n).left, rframes(n).top) - _
                    (rframes(n).right, rframes(n).bottom) _
                    to _
                    (lwidth/3, lheight/3)-(lwidth*2/3, lheight*2/3)
                graphic redraw
                dialog doevents 200
            next
        next
        graphic waitkey$
        graphic attach ghBK, 0
        graphic bitmap end
    99:
    end function

  • #2
    Clearly my current obsession is a minority interest!

    But I've started, so I shall finish... eventually.

    This version allows the user to move horisontal and vertical lines to improve the framing for the flick images.

    This one is a fair place to start: http://theuppahand.weebly.com/upload...97498_orig.jpg

    Code:
    ' flickbook app.
    ' - A bitmap is copied from the clipboard. It may be of low quality
    ' and suffer distortion from photocopying, etc.
    ' - It is assumed that it is a table of flickbook "frames",
    ' each being the image of a page of the flickbook. IOW
    ' it is a number of bitmaps in an XY format where we don't
    ' know what X or Y is.
    ' - So in response to prompts in the caption, the TL and BR
    ' of the topleftmost and bottomrightmost frames are identified by
    ' left-clicking. Then a grid of lines is drawn, cutting up the
    ' bitmap into its X*Y frames.
    ' - Some of those lines may not be in the best place due to the
    ' necessary crudeness of the line calculation algo. So it is
    ' possible to drag them into position with the cursor.
    ' - Following which a keypress starts the display of the flickbook.
    
    
    #compile exe
    #dim all
    #debug display
    
    #include once "WIN32API.INC"
    %zonewidth = 5 ' width of hot zone around lines in pixels
                   ' also threshold cursor movement for displacing a line.
                   ' maybe these should be different things... we'll see.
    global ghw, ghwork, ghbk   as dword
    
    '--------------------------------------------------------------------------------------------------------------------------------------------------------------
    function pbmain as long
        local h, w, i, ii, j, n, lclick, lresult, ncols, nrows as long
        local rstart, rend, rsize, rframes() as rect
        local lwidth, lheight  as long
        '
    
        clipboard get bitmap to ghwork
        if ghwork = 0 then
            ? "failed to find bitmap on clipboard!"
            goto 99
        end if
        graphic attach ghwork, 0
        graphic get canvas to lwidth, lheight
        if lwidth = 0 then
            ? "bitmap has zero size"
            goto 99
        end if
        graphic detach
        '
        desktop get client to lwidth, lheight
        lwidth *= 0.9!: lheight *= 0.9!
        graphic bitmap new lwidth, lheight to ghbk
        graphic attach ghbk, 0
        graphic stretch page ghwork, 0
        '
        graphic window new "flickbook", _
                    0, 0, lwidth, lheight to gHW
        graphic attach gHW, 0, redraw
        graphic copy ghbk, 0
        graphic redraw
        graphic set caption "click on top left corner of first frame"
        while lclick = 0
            graphic window click to lclick, rstart.left, rstart.top
        wend
        lclick = 0
        graphic set caption "click on bottom right corner of first frame"
        while lclick = 0
            graphic window click to lclick, rstart.right, rstart.bottom
        wend
        lclick = 0
        graphic set caption "click on top left corner of last frame"
        while lclick = 0
            graphic window click to lclick, rend.left, rend.top
        wend
        lclick = 0
        graphic set caption "click on bottom right corner of last frame"
        while lclick = 0
            graphic window click to lclick, rend.right, rend.bottom
        wend
        ' calculate sizing rect for frame
        setrect rsize, 0, 0, _
                       ((rstart.right - rstart.left) + _
                        (rend.right - rend.left))/2, _
                       ((rstart.bottom - rstart.top) + _
                        (rend.bottom - rend.top))/2
        ' calculate number of columns
        ncols = (rend.right-rstart.left)/(rsize.right)
        ' calculate number of rows
        nrows = (rend.bottom - rstart.top)/rsize.bottom
        '? "ncols = " + str$(ncols) + ": nrows = " + str$(nrows)
    drag:
        graphic set caption "drag column and row borders, press a key when done"
        graphic width %zonewidth
        local rhlines() as rect: dim rhlines(1 to nrows+1)
        for i = 1 to nrows + 1
            h = rstart.bottom - rstart.top
            setrect rhlines(i), 0, rstart.top + (i-1)*h - %zonewidth, _
                               lwidth, rstart.top + (i-1)*h + %zonewidth
        next
        gosub drawhlines
        '
        local rvlines() as rect: dim rvlines(1 to ncols+1)
        for i = 1 to ncols + 1
            w = (rstart.right - rstart.left)*(i-1)+rstart.left
            setrect rvlines(i), w-%zonewidth, 0 ,w + %zonewidth, lheight
            '
        next
        gosub drawvlines
        '
        graphic redraw
        lresult = 0
        local pt as point
        local touched as long
        while %true
            dialog doevents
            graphic instat to lresult
            if lresult then exit loop
            graphic window click to lclick, pt.X, pt.Y
            if lclick = 0 then iterate loop
            touched = %false
            for i = 1 to nrows + 1
                if ptinrect (rhlines(i), pt) then
                    while GetAsyncKeyState(%VK_LBUTTON) and &H8000
                        ' while cursor is being dragged
                        getcursorpos(pt)
                        screentoclient(ghW, pt)
                        if ptinrect(rhlines(i), pt) = %false then
                            rhlines(i).top = pt.Y - %zonewidth
                            rhlines(i).bottom = pt.Y + %zonewidth
                            graphic copy ghbk, 0
                            gosub drawhlines
                            gosub drawvlines
                            graphic redraw
                            touched = %true
                        end if
                    wend
                    if touched then iterate loop ' don't move vert & horiz at same time!
                end if
            next
            for i = 1 to ncols + 1
                if ptinrect (rvlines(i), pt) then
                    while GetAsyncKeyState(%VK_LBUTTON) and &H8000
                        ' while cursor is being dragged
                        getcursorpos(pt)
                        screentoclient(ghW, pt)
                        if ptinrect(rvlines(i), pt) = %false then
                            rvlines(i).left = pt.X  - %zonewidth
                            rvlines(i).right = pt.X + %zonewidth
                            graphic copy ghbk, 0
                            gosub drawhlines
                            gosub drawvlines
                            graphic redraw
                        end if
                    wend
                end if
            next
        wend
    flick:
        '  play the flickbook!
        graphic set caption "Playing the flickbook"
        graphic clear %blue
        for i = 1 to nrows
            for j = 1 to ncols
                graphic stretch ghbk, 0, _
                    (rvlines(j).left, rhlines(i).bottom) - _
                    (rvlines(j+1).right, rhlines(i+1).bottom) _
                    to _
                    (lwidth/3, lheight/3)-(lwidth*2/3, lheight*2/3)
                graphic redraw
                dialog doevents 200
            next
        next
    cleanup:
        graphic input flush
        graphic waitkey$
        graphic attach ghBK, 0
        graphic attach ghwork, 0
        graphic bitmap end
    
    ''''''''''''''''''''''
    99: exit function
    ''''''''''''''''''''''
    drawhlines:
        for ii = 1 to nrows + 1
            graphic line (rhlines(ii).left, rhlines(ii).top+ %zonewidth) - _
                         (rhlines(ii).right, rhlines(ii).top + %zonewidth), %cyan
        next
        return
    ''''''''''''''''''''''
    drawvlines:
        for ii = 1 to ncols + 1
            graphic line (rvlines(ii).left + %zonewidth, rvlines(ii).top)- _
                         (rvlines(ii).left+ %zonewidth, rvlines(ii).bottom), %red
        next
        return
    
    
    end function

    Comment


    • #3
      It is hard to know to either of us whether I have interest in it or not. I don't even know what a flickbook is.
      But when I try this code. I may learn how to accomplish some other project goals I have wanted to do. One might be to copy images or parts of an image to the clipboard and build a PDF file out of images. It is not on top of my list of things to do but on there never the less.
      So you never know the value of your shared code to another. Cheis, I am glad you put it up.
      p purvis

      Comment


      • #4
        Paul, thanks for your potential interest!

        Regarding PDFs and bitmaps, do you use a PDF library or alternatively XPRINT to a PDF device?

        Comment


        • #5
          Hi Chris.
          It has be crazy around here or at least I seem to be going crazy.
          We are moving off windows XP.
          I have been using a combination of things to produce PDF files. Software packages with scanners, Apple's built in software, a console program to convert text to pdf using libharu.
          I had broken off scanning a lot of documents due to many different reasons. A lot of testing goes into this kind of stuff.
          I am using ghostscript very successful on many documents that are produced from electronically by printing by which I set up a different printer to convert the printout to a pdf that is saved to a certain location for depending on which printer you select but much will come from scanning to an image.
          The printer method uses batch files to catch the documents and convert them or name the documents and saved multiple places to keep a user from accidentally deleting them then the document is displayed to a pdf reader as the final processes.
          But what will be needed is collecting images and grouping them to go into a pdf file and cropping the images and/or previewing the images them will be important before the images are placed in pdf files.
          Even thought i have not even been able to try your software. I do believe coping an image by either drag n drop or clipboard, then cropping it or even disguarding the image would be useful but it all has to get named properly so it is best to have all that working together. But it has been slow here business wise for far too many months.
          I just use all kinds of tools to get whatever needs to be done and i have my eye pealed open for anything that might make its way.
          p purvis

          Comment


          • #6
            Hi Chris!
            I just played with this tonight. The 2nd version was definitely a step up in terms of getting the alignment.

            Another thing to consider would be to let the user capture each image, creating temporary images of each frame, then putting those images into an animated GIF.

            I recall having posted an app called gbAniGIF that would take the individual frames and make the animated GIF. But I could image just keeping the individual frames in memory and merging that with the animated GIF code I posted.

            For that matter, I seem to recall a few free aniGIF maker apps floating around too.

            That would make your animations permanent, if desired.

            Thanks for posting your code. I'll be showing it to my grandkids this weekend!

            Comment


            • #7
              Originally posted by Gary Beene View Post
              Another thing to consider would be to let the user capture each image, creating temporary images of each frame, then putting those images into an animated GIF.
              It's hard to know where to draw the line between the enjoyment of flick books per se and the fun of writing the code. In either case, I suppose that the animated GIF would be a record of the journey... but I travel light.

              I was surprised to learn from Jimmy Wales that evidence of flick books post-dates photography. I'm old enough to remember mutascopes, photographic flick books sometimes called "'What the Butler Saw' machines" in seaside amusement arcades. However, their saucy content did not interest me at that time of my life! Later at school, l developed a knack for flick books of knots which tied themselves and sailing boats going about, while my peers concentrated on Caesar's Gallic Wars, etc etc. So my interest is of long standing, and cost me all hope of a paper qualification in Latin. Somehow I have scraped by without it.

              Thanks for posting your code. I'll be showing it to my grandkids this weekend!
              My pleasure! Hope they enjoy it. Even better, teach 'em how to make real flick books, drawing is a major life skill which will outlast all our technology.

              Comment


              • #8
                The 3 and 5-year old grandkids and I have drawn animation pictures on pages of a paper and just manually thumbed through the pages. But, I can't say as they were mesmerized! Drawing takes a long time and thumbing just seconds.

                We'll see how they like your computer-screen version!

                Comment

                Working...
                X