Jump to content

Bitmap Lisp Reduce Calculation Time


Recommended Posts

Posted (edited)

After scratching my head for many minutes trying to figure out how to reduce load/processing time on this lisp I think I hit a dead end.

 

If you guys see anything that I could do to make this lisp more efficient that would be great. I am using a 3D 256x256x* matrix.

 

Image1 (100x78 )(7800 pixels) => ~.45sec

Image2 (382x299)(114218 pixels) => ~4.3sec

Image3 (1526x1195)(1,823,570 pixels) => ~100.7169sec (Version 1 ~220 sec)

 

Should now support files up to 32MB with no noticeable lag. (256x256x512 array) For files any larger i will have to go Create a 4D matrix. If i do it should support up to 64 gig images but would take an ungodly amout of time to finish. Quick guess would be around 471050 sec (7850 min => 130 hours => 5.5 days....... you get the drift)

 

(vl-load-com)
(defun C:imagetotxt (/)
 (setq image (vla-get-ImageFile (vlax-ename->vla-object (car (entsel "\nSelect Image:")))))
 (setq start1 (getvar "CDATE"))
 (setq stream (vlax-get-or-create-object "ADODB.stream"))
 (vlax-put-property stream 'type 1)
 (vlax-invoke stream 'open)
 (vlax-invoke stream 'loadfromfile image)
 (vlax-put-property stream 'position 0)
 (setq size (vlax-get stream 'size))
 (setq variable (cond ((< size 10000)10)
        ((< size 100000)100)
        ((< size 1000000)10000)
        ((< size 10000000)100000)
        ((< size 100000000)10000000)
        ((< size 1000000000)100000000)))
 (setq count 0)
 (setq text (vlax-variant-value (vlax-invoke-method stream 'read (vlax-get stream 'size))))
 (setq hextext nil)
 (setq hexbatch nil)
 (setq finalhextext nil)
 (setq countcol 0)
 (setq colmax 256)
 (setq countdata 0)
 (setq datamax 256)
 (while (< count size)
   (setq hextext (append hextext (list (DecToHex (vlax-safearray-get-element text count)))))
   (setq count (+ count 1))
   (setq countdata (+ countdata 1))
   (if (= countdata datamax)
     (progn
(setq hexbatch (append hexbatch (list hextext)))
(setq hextext nil)
(setq countcol (+ countcol 1))
(setq countdata 0)
)
     )
   (if (= countcol colmax)
     (progn
(setq finalhextext (append finalhextext (list hexbatch)))
(setq hexbatch nil)
(setq countcol 0)
)
     )
   (if (= (rem count (/ size variable)) 0)
     (print (strcat "ETA:" (rtos (*(/(*(- (setq finish2 (getvar "CDATE")) start1)1000000)count)(-(* 1.0 size) count)))))
     )
   )
 (setq hexbatch (append hexbatch (list hextext)))
 (setq finalhextext (append finalhextext (list hexbatch)))
 (setq finish1 (getvar "CDATE"))
 (alert (strcat "Image to hex: " (rtos (*(- finish1 start1)1000000))))
 (print (strcat "File Size: " (itoa (hexcounter (strcat(offset 2 finalhextext) " " (offset 3 finalhextext) " " (offset 4 finalhextext) " " (offset 5 finalhextext))))))
 (print (strcat "Pixel Array starts at: "  (itoa (hexcounter (strcat(offset 10 finalhextext) " " (offset 11 finalhextext) " " (offset 12 finalhextext) " " (offset 13 finalhextext))))))
(print (strcat "Width: " (itoa (hexcounter (strcat (offset 18 finalhextext) " " (offset 19 finalhextext) " " (offset 20 finalhextext) " " (offset 21 finalhextext))))))
 (print (strcat "Hight:"  (itoa (hexcounter (strcat(offset 22 finalhextext) " " (offset 23 finalhextext) " " (offset 24 finalhextext) " " (offset 25 finalhextext))))))
 (print (strcat "Number of Color Planes:"  (itoa (hexcounter (strcat(offset 26 finalhextext) " " (offset 27 finalhextext))))))
 (print (strcat "Bits Per Pixel:"  (itoa (hexcounter (strcat(offset 28 finalhextext) " " (offset 29 finalhextext))))))
 (print (strcat "Pixel Array Compression:"  (itoa (hexcounter (strcat(offset 30 finalhextext) " " (offset 31 finalhextext) " " (offset 32 finalhextext) " " (offset 33 finalhextext))))))
 (print (strcat "Size of Raw pixel Data:"  (itoa (hexcounter (strcat(offset 34 finalhextext) " " (offset 35 finalhextext) " " (offset 36 finalhextext) " " (offset 37 finalhextext))))))
 )
(defun DecToHex (int /)
 (setq int (cond ((> int 256)(rem int 256))
   ((< int 0)(+(rem int 256) 256))
   (t int))
)
 (if (= int 256)
   "00"
   (progn
     (setq b (rem int 16))
     (setq a (/ (- int b) 16))
     (strcat (if (< a 10)(itoa a)(chr (+ 55 a))) (if (< b 10)(itoa b)(chr (+ 55 b))))
     )
   )
 )
(defun HexToDec (str /)
 (setq a (substr str 1 1))
 (setq b (substr str 2 1))
 
 (if (wcmatch a "@")
   (setq a (- (vl-string-elt a 0) 55))
   (setq a (atoi a))
   )
 (if (wcmatch b "@")
   (setq b (- (vl-string-elt b 0) 55))
   (setq b (atoi b))
   )
 (princ (+(* a 16) b))
 )
(defun 3Ddata (row col data source)
 (nth data (nth col (nth row source)))
)
(defun offset (digit source)
 (setq row (/ (- digit (rem digit 65536)) 65536))
 (setq digit (- digit (* row 65536)))
 (setq col (/ (- digit (rem digit 256)) 256))
 (setq digit (- digit (* col 256)))
 (setq data digit)
 (3ddata row col data source)
 )
(defun hexcounter (string)
 (while (wcmatch string "* *")(setq string (vl-string-subst "" " " string)))
 (setq len (strlen string))
 (setq strcount 0)
 (setq hexarray nil)
 (setq value 0)
 (setq arraypower 0)
 (while (< strcount len)
   (setq hexarray (append hexarray (list (substr string (+ strcount 1) 2))))
   (setq strcount (+ strcount 2))
   )
 (foreach hexbyte hexarray
   (setq value (+ value (* (hextodec hexbyte) (expt 256 arraypower))))
   (setq arraypower (+ arraypower 1))
   )
 value
 )

Edited by CADWarrior
New Stuff
Posted

Added some new stuff and started decoding the bitmap. I now know where the Pixel array starts\. Pixel bit size for extraction 1, 2, 4, 8, 16, 24, vs 32 bit colors. Width and Height of photo so on......

 

New Stuff includes HexToDec, 3Ddata, offset, Hexcounter, Coverted from 2Dmatrix X,Y to a 3Dmatrix X,Y,Z

 

After i finish translating BMP files I will try my hand at compressed JPEGs PNGs so on

Posted

Probably going to a .NET c# program may speed up the process a dedicated .exe or dll. Did you try code as a FAS. Lisps is line by line interpretive where as dll are at machine code level.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...