From: John L. <jr...@us...> - 2008-01-22 04:03:39
|
Update of /cvsroot/wxlua/wxLua/samples/image In directory sc8-pr-cvs9.sourceforge.net:/tmp/cvs-serv25550/image Modified Files: image.wx.lua Log Message: Fix loading the images, use new wxBitmap constructor for XBMs Index: image.wx.lua =================================================================== RCS file: /cvsroot/wxlua/wxLua/samples/image/image.wx.lua,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** image.wx.lua 21 Jan 2008 00:47:10 -0000 1.1 --- image.wx.lua 22 Jan 2008 04:03:33 -0000 1.2 *************** *** 15,19 **** --[[ win32: ! lua5.1.exe -e "package.cpath = './?.dll'" ./image.wx.lua linux: --- 15,19 ---- --[[ win32: ! lua5.1.exe -e "package.cpath = './?.dll'" ./image.wx.lua linux: *************** *** 21,25 **** lua5.1 -e "package.cpath = './?.so'" ./image.wx.lua ! --wx = require("ds287u") --]] --- 21,25 ---- lua5.1 -e "package.cpath = './?.so'" ./image.wx.lua ! --wx = require("ds287u") --]] *************** *** 59,66 **** local C = string.char for i = 1, #smile_bits do ! smile_bits[i] = C(smile_bits[i]) -- turn into ASCII chars end ! smile_bits = table.concat(smile_bits) -- turn into a string --- 59,67 ---- local C = string.char + smile_bits_str = {} for i = 1, #smile_bits do ! smile_bits_str[i] = C(smile_bits[i]) -- turn into ASCII chars end ! smile_bits_str = table.concat(smile_bits_str) -- turn into a string *************** *** 105,109 **** " ..... ", " ", ! " "} local _T = function(s) return s end --- 106,110 ---- " ..... ", " ", ! " "} local _T = function(s) return s end *************** *** 113,117 **** local dc = wx.wxPaintDC(T) T:PrepareDC( dc ) ! dc:DrawText( _T("Loaded image"), 30, 10 ) if (T.my_square:Ok()) then --- 114,118 ---- local dc = wx.wxPaintDC(T) T:PrepareDC( dc ) ! dc:DrawText( _T("Loaded image"), 30, 10 ) if (T.my_square:Ok()) then *************** *** 173,187 **** if (T.my_horse_bmp2:Ok()) then dc:DrawBitmap( T.my_horse_bmp2, 280, 1070, false ) ! end dc:DrawText( _T("PNM handler"), 30, 1285 ) if (T.my_horse_pnm:Ok()) then dc:DrawBitmap( T.my_horse_pnm, 30, 1300, false ) ! end dc:DrawText( _T("PNM handler (ascii grey)"), 280, 1285 ) if (T.my_horse_asciigrey_pnm:Ok()) then dc:DrawBitmap( T.my_horse_asciigrey_pnm, 280, 1300, false ) ! end dc:DrawText( _T("PNM handler (raw grey)"), 530, 1285 ) --- 174,188 ---- if (T.my_horse_bmp2:Ok()) then dc:DrawBitmap( T.my_horse_bmp2, 280, 1070, false ) ! end dc:DrawText( _T("PNM handler"), 30, 1285 ) if (T.my_horse_pnm:Ok()) then dc:DrawBitmap( T.my_horse_pnm, 30, 1300, false ) ! end dc:DrawText( _T("PNM handler (ascii grey)"), 280, 1285 ) if (T.my_horse_asciigrey_pnm:Ok()) then dc:DrawBitmap( T.my_horse_asciigrey_pnm, 280, 1300, false ) ! end dc:DrawText( _T("PNM handler (raw grey)"), 530, 1285 ) *************** *** 207,211 **** --// toucans ! do local x,y,yy = 750,10,170 --- 208,212 ---- --// toucans ! if T.my_toucan:Ok() then local x,y,yy = 750,10,170 *************** *** 404,416 **** --/* This is quite slow, but safe. Use wxImage::GetData() for speed instead. */ if USE_QUITE_SLOW then ! local orig_data = original:GetData() -- get the data as a RGBRGB.. string local w = original:GetWidth() ! for y = 1, 149-1 do for x = 1, 149-1 do ! local red, green, blue = 0, 0, 0 ! if false then red = original:GetRed( x*2, y*2 ) + --- 405,417 ---- --/* This is quite slow, but safe. Use wxImage::GetData() for speed instead. */ if USE_QUITE_SLOW then ! local orig_data = original:GetData() -- get the data as a RGBRGB.. string local w = original:GetWidth() ! for y = 1, 149-1 do for x = 1, 149-1 do ! local red, green, blue = 0, 0, 0 ! if false then red = original:GetRed( x*2, y*2 ) + *************** *** 425,429 **** original:GetGreen( x*2+1, y*2+1 ) green = green/4 ! blue = original:GetBlue( x*2, y*2 ) + original:GetBlue( x*2-1, y*2 ) + --- 426,430 ---- original:GetGreen( x*2+1, y*2+1 ) green = green/4 ! blue = original:GetBlue( x*2, y*2 ) + original:GetBlue( x*2-1, y*2 ) + *************** *** 436,440 **** local i3 = ((x*2 ) + (y*2+1)*w)*3 + 1 local i4 = ((x*2+1) + (y*2+1)*w)*3 + 1 ! red = string.byte(orig_data, i1 ) + string.byte(orig_data, i2 ) + --- 437,441 ---- local i3 = ((x*2 ) + (y*2+1)*w)*3 + 1 local i4 = ((x*2+1) + (y*2+1)*w)*3 + 1 ! red = string.byte(orig_data, i1 ) + string.byte(orig_data, i2 ) + *************** *** 454,467 **** blue = blue/4 end ! anti:SetRGB( x, y, red, green, blue ) ! end ! end end T.my_anti = wx.wxBitmap(anti) ! original:delete() anti:delete() ! dc:delete() bitmap:delete() --- 455,468 ---- blue = blue/4 end ! anti:SetRGB( x, y, red, green, blue ) ! end ! end end T.my_anti = wx.wxBitmap(anti) ! original:delete() anti:delete() ! dc:delete() bitmap:delete() *************** *** 501,510 **** this.my_toucan_scaled_high = wx.wxNullBitmap this.my_toucan_blur = wx.wxNullBitmap ! this.m_bmpSmileXpm = wx.wxBitmap(smile_xpm) --this.m_iconSmileXpm = wx.wxIcon(smile_xpm) ! this.m_iconSmileXpm = wx.wxIcon() this.m_iconSmileXpm:CopyFromBitmap(this.m_bmpSmileXpm) ! this.my_horse_ani = {} this.m_ani_images = 0 --- 502,511 ---- this.my_toucan_scaled_high = wx.wxNullBitmap this.my_toucan_blur = wx.wxNullBitmap ! this.m_bmpSmileXpm = wx.wxBitmap(smile_xpm) --this.m_iconSmileXpm = wx.wxIcon(smile_xpm) ! this.m_iconSmileXpm = wx.wxIcon() this.m_iconSmileXpm:CopyFromBitmap(this.m_bmpSmileXpm) ! this.my_horse_ani = {} this.m_ani_images = 0 *************** *** 514,518 **** this.OnPaint = OnPaint this.CreateAntiAliasedBitmap = CreateAntiAliasedBitmap ! this:SetBackgroundColour(wx.wxWHITE) --- 515,519 ---- this.OnPaint = OnPaint this.CreateAntiAliasedBitmap = CreateAntiAliasedBitmap ! this:SetBackgroundColour(wx.wxWHITE) *************** *** 531,541 **** --// try to find the directory with our images local dir ! if ( wx.wxFile.Exists("./horse.png") ) then ! dir = "./" ! elseif ( wx.wxFile.Exists("../horse.png") ) then ! dir = "../" ! --hd... ! elseif ( wx.wxFile.Exists("./samples/wximage/horse.png") ) then ! dir = "./samples/wximage/" else --wx.wxLogWarning("Can't find image files in either '.' or '..'!") --- 532,545 ---- --// try to find the directory with our images local dir ! if ( wx.wxFile.Exists("horse.png") ) then ! dir = "" ! elseif ( wx.wxFile.Exists("./image/horse.png") ) then ! dir = "./image/" ! elseif ( wx.wxFile.Exists("./samples/image/horse.png") ) then ! dir = "./samples/image/" ! elseif ( wx.wxFile.Exists("../samples/image/horse.png") ) then ! dir = "../samples/image/" ! elseif ( wx.wxFile.Exists("../../samples/image/horse.png") ) then ! dir = "../../samples/image/" else --wx.wxLogWarning("Can't find image files in either '.' or '..'!") *************** *** 548,557 **** return this end ! ! if ( not wx.wxFile.Exists(dir.."./horse.png") ) then dir = nil end end ! local image = bitmap:ConvertToImage() --- 552,563 ---- return this end ! ! dir = dir.."/" ! ! if ( not wx.wxFile.Exists(dir.."horse.png") ) then dir = nil end end ! local image = bitmap:ConvertToImage() *************** *** 708,711 **** --- 714,719 ---- this:CreateAntiAliasedBitmap() + this.my_smile_xbm = wx.wxBitmap( smile_bits_str, smile_width, + smile_height, 1 ) this.my_smile_xbm = wx.wxBitmap( smile_bits, smile_width, smile_height, 1 ) *************** *** 747,752 **** else this.my_horse_cur = wx.wxBitmap( image ) ! this.xH = 30 + image:GetOptionInt(wx.wxIMAGE_OPTION_CUR_HOTSPOT_X) ! this.yH = 2420 + image:GetOptionInt(wx.wxIMAGE_OPTION_CUR_HOTSPOT_Y) end --- 755,760 ---- else this.my_horse_cur = wx.wxBitmap( image ) ! this.xH = 30 + image:GetOptionInt(wx.wxIMAGE_OPTION_CUR_HOTSPOT_X) ! this.yH = 2420 + image:GetOptionInt(wx.wxIMAGE_OPTION_CUR_HOTSPOT_Y) end *************** *** 776,780 **** local len = file:Length() local dataSize = len ! local read_count, data = file:Read(dataSize) if ( read_count ~= len ) then --- 784,788 ---- local len = file:Length() local dataSize = len ! local read_count, data = file:Read(dataSize) if ( read_count ~= len ) then *************** *** 792,796 **** this:Connect(wx.wxEVT_PAINT, function(event) this:OnPaint(event) end) ! return this end --- 800,804 ---- this:Connect(wx.wxEVT_PAINT, function(event) this:OnPaint(event) end) ! return this end *************** *** 837,841 **** local saved = false if ( extension == "bmp" ) then ! local bppvalues = { wx.wxBMP_1BPP, --- 845,849 ---- local saved = false if ( extension == "bmp" ) then ! local bppvalues = { wx.wxBMP_1BPP, *************** *** 937,947 **** this.OnPaint = OnPaint this.OnSave = OnSave ! ! this:Connect(wx.wxEVT_ERASE_BACKGROUND, function(event) --// do nothing here to be able to see how transparent images are shown end ) ! this:Connect(wx.wxEVT_PAINT, function(event) this:OnPaint(event) end) this:Connect(wx.wxEVT_LEFT_DCLICK, function(event) this:OnSave(event) end) ! this:SetClientSize(bitmap:GetWidth(), bitmap:GetHeight()) return this --- 945,955 ---- this.OnPaint = OnPaint this.OnSave = OnSave ! ! this:Connect(wx.wxEVT_ERASE_BACKGROUND, function(event) --// do nothing here to be able to see how transparent images are shown end ) ! this:Connect(wx.wxEVT_PAINT, function(event) this:OnPaint(event) end) this:Connect(wx.wxEVT_LEFT_DCLICK, function(event) this:OnSave(event) end) ! this:SetClientSize(bitmap:GetWidth(), bitmap:GetHeight()) return this *************** *** 955,959 **** --// MyRawBitmapFrame ------------------------------------------------------- ! if wx.wxHAVE_RAW_BITMAP then local wx = wx --- 963,967 ---- --// MyRawBitmapFrame ------------------------------------------------------- ! if wx.wxHAVE_RAW_BITMAP then local wx = wx *************** *** 1074,1078 **** this.OnPaint = OnPaint this:Connect(wx.wxEVT_PAINT, function(event) this:OnPaint(event) end) ! this:SetClientSize(SIZE, SIZE*2+25) this:InitAlphaBitmap() --- 1082,1086 ---- this.OnPaint = OnPaint this:Connect(wx.wxEVT_PAINT, function(event) this:OnPaint(event) end) ! this:SetClientSize(SIZE, SIZE*2+25) this:InitAlphaBitmap() *************** *** 1097,1101 **** local MyCanvas = require"MyCanvas" local MyImageFrame = require"MyImageFrame" ! if wx.wxHAVE_RAW_BITMAP then local MyRawBitmapFrame = require"MyRawBitmapFrame" end --- 1105,1109 ---- local MyCanvas = require"MyCanvas" local MyImageFrame = require"MyImageFrame" ! if wx.wxHAVE_RAW_BITMAP then local MyRawBitmapFrame = require"MyRawBitmapFrame" end *************** *** 1142,1150 **** local dobjBmp = wx.wxBitmapDataObject() dobjBmp:SetBitmap(T.m_canvas.my_horse_png) ! local clipboard = wx.wxClipboard.Get() ! if not clipboard then wx.wxLogError("Failed to open clipboard") ! return end clipboard:Open() --- 1150,1158 ---- local dobjBmp = wx.wxBitmapDataObject() dobjBmp:SetBitmap(T.m_canvas.my_horse_png) ! local clipboard = wx.wxClipboard.Get() ! if not clipboard then wx.wxLogError("Failed to open clipboard") ! return end clipboard:Open() *************** *** 1179,1183 **** local this = wx.wxFrame(wx.NULL, wx.wxID_ANY, "wxImage sample", wx.wxPoint(20, 20), wx.wxSize(950, 700)) ! this.OnAbout = OnAbout this.OnQuit = OnQuit --- 1187,1191 ---- local this = wx.wxFrame(wx.NULL, wx.wxID_ANY, "wxImage sample", wx.wxPoint(20, 20), wx.wxSize(950, 700)) ! this.OnAbout = OnAbout this.OnQuit = OnQuit *************** *** 1190,1194 **** this.OnPaste = OnPaste --end --// wx.wxUSE_CLIPBOARD ! this:Connect(ID_ABOUT, wx.wxEVT_COMMAND_MENU_SELECTED, function(event) this:OnAbout(event) end) this:Connect(ID_QUIT, wx.wxEVT_COMMAND_MENU_SELECTED, function(event) this:OnQuit(event) end) --- 1198,1202 ---- this.OnPaste = OnPaste --end --// wx.wxUSE_CLIPBOARD ! this:Connect(ID_ABOUT, wx.wxEVT_COMMAND_MENU_SELECTED, function(event) this:OnAbout(event) end) this:Connect(ID_QUIT, wx.wxEVT_COMMAND_MENU_SELECTED, function(event) this:OnQuit(event) end) *************** *** 1235,1239 **** --// 500 width * 2750 height this.m_canvas:SetScrollbars( 10, 10, 50, 275 ) ! return this end --- 1243,1247 ---- --// 500 width * 2750 height this.m_canvas:SetScrollbars( 10, 10, 50, 275 ) ! return this end |