Understanding Image Sizes, Before And After Display

2018-12-23 Thread Alejandro Tejada via use-livecode
Hi All,

In this moment that I could not sleep because the fever,
the mail list is a good reading to keep me awake.

There is another way to read the width and height of
a jpg image. Read the binary data for the Start of Frame
tag within the jpg image.

Please test and improve this script:

on mouseUp
local temp
answer file "Select JPEG image"
put it into temp
open file temp for binary read
read from file temp for 10
put it into temp1
close file temp

put numtobyte(255) & numtobyte(192) into tBaselineJPGFrame0
-- in Hexadecimal: FFC0 =  JPEG Start-Of-Frame (SOF) marker FFC0
put numtobyte(255) & numtobyte(194) into tProgressiveJPGFrame0
-- in Hexadecimal: FFC2 =  JPEG Start-Of-Frame (SOF) marker FFC2

set the casesensitive to true

put offset(tBaselineJPGFrame0,temp1) into tStartOFrame
if tStartOFrame is 0 then put offset(tProgressiveJPGFrame0,temp1) into
tStartOFrame

if tStartOFrame is not empty
then
put byte (tStartOFrame + 5) of temp1 & byte (tStartOFrame + 6) of temp1
into tJPGHeight
put byte (tStartOFrame + 7) of temp1 & byte (tStartOFrame + 8) of temp1
into tJPGWidth

-- put baseConvert(baseConvert(bytetonum(byte 1 of tJPGHeight),10,16) &
baseConvert(bytetonum(byte 2 of tJPGHeight),10,16),16,10) into tJPGHeight

put bytetonum(byte 1 of tJPGHeight) into q
put bytetonum(byte 2 of tJPGHeight) into w
put baseConvert(q,10,16) into r
if the number of bytes of r = 1 then put "0" & r into r
put baseConvert(w,10,16) into t
if the number of bytes of t = 1 then put "0" & t into t
put r & t into y
put baseConvert(y,16,10) into tJPGHeight

-- put baseConvert(baseConvert(bytetonum(byte 1 of tJPGWidth),10,16) &
baseConvert(bytetonum(byte 2 of tJPGWidth),10,16),16,10) into tJPGWidth

put bytetonum(byte 1 of tJPGWidth) into q
put bytetonum(byte 2 of tJPGWidth) into w
put baseConvert(q,10,16) into r
if the number of bytes of r = 1 then put "0" & r into r
put baseConvert(w,10,16) into t
if the number of bytes of t = 1 then put "0" & t into t
put r & t into y
put baseConvert(y,16,10) into tJPGWidth

answer "JPG Width" && tJPGWidth & cr & "JPG Height" && tJPGHeight & cr &
temp

else
answer "Could not find Start of Frame information in this JPEG image" & cr
& temp
end if

end mouseUp

 /*
Information from
https://stackoverflow.com/questions/35427283/get-width-and-height-from-jpeg-without-0xff-0xc0

The JPEG Start-Of-Frame (SOF) marker has 4 possible values:

FFC0 (baseline) - This is the usual mode chosen for photos and encodes
fully specified DCT blocks in groupings depending on the color/subsample
options chosen
FFC1 (extended) - This is similar to baseline, but has more than 8-bits
per color stimulus
FFC2 (progressive) - This mode is often found on web pages to allow the
image to load progressively as the data is received. Each "scan" of the
image progressively defines more coefficients of the DCT blocks until
they're fully defined. This effectively provides more and more detail as
more scans are decoded
FFC3 (lossless) - This mode uses a simple Huffman encoding to
losslessly encode the image. The only place I've seen this used is on
16-bit grayscale DICOM medical images

 */
___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Understanding Image Sizes, Before And After Display

2018-12-23 Thread Sannyasin Brahmanathaswami via use-livecode
Ha! Klaus... 
Yes! You did it again...Merry Christmas!

And thanks for the gift... 
This works, for example,  (real use case)

# I want to get to the original size for a button icon named img "gems"
# are re-crop it...(actual a whole layout of buttons the same size)

 on Mouseup
# find the  original "diamond-sparkle-small.jpg"
   answer file "Select the image you wish to view:" with type "JPEG 
Images|jpg|JPEG" 
  put it into tFilename
  set the filename of image tempImage to tFilename
 createEmbedAndCrop
end mouseUp

command createEmbedAndCrop
   Create image "gems"
   set the loc of grc "newCrop" to the loc of img "tempImage" 
   put url("binfile:" & the filename of img "tempImage") into img "gems"
   set the loc of img "gems" to the loc of img "tempImage"
   crop image "gems" to the rect of grc "newCrop"
end createEmbedAndCrop

# Fantastic, I can put this on a repeat loop for a design change for a whole 
group of buttons and simple change the grc "newCrop"

BR

 Klaus major-k wrote:

## what about:
put url("binfile:" & the filename of img "theImage") into img "gems"



___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

Re: Understanding Image Sizes, Before And After Display

2018-12-23 Thread Klaus major-k via use-livecode
Hi Swami,

> Am 23.12.2018 um 17:19 schrieb Sannyasin Brahmanathaswami via use-livecode 
> :
> 
> From the dictionary and confirmed here:
> 
> *Important:* The crop command cannot be used on a
>  referenced image. Doing so will cause an 
>  execution error. 
> -
> 
> Also, today, I can't copy a referenced image?
> 
> Again missing something simple...
> 
> command createEmbedAndCrop
Create image "gems"

## what about:
put url("binfile:" & the filename of img "theImage") into img "gems"

## Or:
## Create image "gems"
import paint from file (the filename of img "theImage")
set the name of last img to "gems"

> #  set the loc of img "gems" to the loc of img "theImage"
> #  img "theImage" is referenced, now displayed in original format/rect
>   -- set the imagedata of img "gems" to  the imagedata of image "theImage"  
> # doesn’t work
> #  -- set the text of img "gems" to  the imagedata of image "theImage"  
> # also doesn't work
> # from the dictionary. Also doesn’t work:
> # put image "theImage" into image "gems"
> # this works, but have no data in the image "gems" :
>   crop image "gems" to rect of grc "newCrop"
> end createEmbedAndCrop

Best

Klaus

--
Klaus Major
http://www.major-k.de
kl...@major-k.de


___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

Re: Understanding Image Sizes, Before And After Display

2018-12-23 Thread Sannyasin Brahmanathaswami via use-livecode
From the dictionary and confirmed here:

*Important:* The crop command cannot be used on a
  referenced image. Doing so will cause an 
  execution error. 
-

Also, today, I can't copy a referenced image?

Again missing something simple...

command createEmbedAndCrop
   
   Create image "gems"
   set the loc of img "gems" to the loc of img "theImage"
 #  img "theImage" is referenced, now displayed in original format/rect

   -- set the imagedata of img "gems" to  the imagedata of image "theImage"  
# doesn’t work

   -- set the text of img "gems" to  the imagedata of image "theImage"  
# also doesn't work

# from the dictionary. Also doesn’t work:
put image "theImage" into image "gems"

# this works, but have no data in the image "gems" :
   crop image "gems" to rect of grc "newCrop"
   
end createEmbedAndCrop

Hmm why does this fail:

put image "theImage" into image "gems" 

Dictionary. 
-
Imagedata:

*Tip:*  To copy the information in an image at full resolution,
  regardless of whether its height and width have been changed, use
  a statement like the following:

put image "Full Resolution" into image "Copied Image"

Well I discovered it's because image "fullResolution" is referenced?

I scanned thru the IDE stacks in project Browser, looking for the 

"Import as Control --> image file"

Which should have the method for imported an embedded image But I could not 
find it






 J. Landman Gay wrote:

There's a crop command to allow you to do it in a script.



___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode