|
Hi Dave,
I guess from the thought I followed I should have named the variable "reduceFactor". Anyway changing it to 0.5 doesn't help. In the current approach, when reading UInt32s from the file I read one pixel and skip (scaleFactor^2 - 1) pixels. How many would I skip with 0.5 ? I'm pretty sure it would end in an even bigger mess. Thank you still, but maybe you see anything else in the code?
|
|
|
|
|
Hi Michael,
IMO your scaling is fundamentally flawed. Assuming you have good code for scale factor 1; now if you want to sub-sample (say scale factor 2), then:
- you should process only some of the input lines;
- of the lines you keep, you should process some of the pixels;
- of the lines you ignore, you should skip all pixels.
So you can't handle it with a skip loop that skips scalefactor^2 pixels, you really need two skip loops, a horizontal one and a vertical one. And you need to count rows and columns.
Also, I didn't like your total image size as calculated from the file length. Finally, depending on the exact pixel format of your input, the code may need adjusting; e.g. I think you may have to read the actual stride from the file.
PS: you may have put this in the wrong forum, it looked like C# code to me.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|
Hi Luc,
my God you're right - I'm in the wrong forum! C# code it's a big exception for me, so I just didn't realize... Nevertheless I'm afraid that it's the language-independent basic principle where I'm mislead in this piece of code - and I honestly have to agree to your term "fundamentally flawed".
Unfortunately I can't read the actual stride from the file - it doesn't contain such a value. From the file's format (each RGB pixel has 30 bits in 4 Bytes) I think I can assume a stride of 4 * width. Right?
First I'll try your approach of reading line by line!
|
|
|
|
|
yep, if no stride information is available, you should assume each row strictly follows the previous one (which isn't necessarily so in an in-memory .NET image, as pixels might be aligned to a higher power-of-2 multiple).
Now even with consecutive rows, you must reset your rescaling counter for each row, otherwise it would go wrong if say your scale factor is 2 and the image width is odd rather than even.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|
Hi Luc,
thanks to your hints and with a good portion of stamina I finally made it
In case you're intersted - and also for others who read the the record - here's the way how I read the raw data now (sorry... still C# )... and btw dpxStride is simply the original pictures' width * 4, assuming the best.
imagePixelFormat = PixelFormat.Format24bppRgb;
bmp = new Bitmap(imageWidth, imageHeight, imagePixelFormat);
PixelArray = new byte[(int)imageWidth * imageHeight * bmpStride];
for (int r = 0; r <= this.DPXHeight - 1; r += scaleFactor)
{
long readPosition = r * dpxStride;
fs.Position = this.DPXOffset + readPosition;
long writePosition = readPosition / scaleFactor / scaleFactor / rawStride * bmpStride;
int c = 0;
for (c = 0; c <= (this.DPXWidth * bmpStride / scaleFactor) - 1; c += 3)
{
UInt32 mybuff = SwapDWORD(br.ReadUInt32());
PixelArray[writePosition + c] = (byte)((mybuff & 0xffc) >> 4);
PixelArray[writePosition + c + 1] = (byte)((mybuff & 0x3ffffc) >> 14);
PixelArray[writePosition + c + 2] = (byte)((mybuff & 0xfffffffc) >> 24);
for (int j = 1; j <= scaleFactor - 1; j += 1)
{
br.ReadUInt32();
}
}
} If you have another good idea on it (maybe regarding better coding style) I'll appreciate. On the other hand they say 'Never change a running system'
Thanks
Michael
|
|
|
|
|
Hi Michael,
yes that looks like a valid attempt, or at least pretty close to it.
I'm a bit worried about you having three stride variables; and I'm not convinced the heavy writePosition calculation is warranted (aren't you generating all the result pixels simply in their logical order anyway?).
Here are some more ideas:
1.
your subsampling assumes an integer scale; you could also apply fractional sampling, which basically means when you want row Z with a scalefactor of T/N, you calculate Zscaled=Z*T/N, which, rounded to some integer value, tells you which row to use. Similar for horizontal scaling.
If you want to do the fast scan direction efficiently, you may want to study the Bresenham algorithm.
2.
Rather than skipping pixels one by one, as your final for loop does, I would consider this:
- read an entire row at a time, asking the stream to fill an uint array with the correct number of bytes;
- use a pointer inside the uint array to access pixels or colorcomponents.
The net result is the last for loop becomes a simple addition.
3.
Assuming you want maximum performance, I would also consider:
- smashing the byte swap logic, i.e. copying the SwapDWORD code into your current snippet (manual inlining);
- removing all multiplications from the loops; either do them once, beforehand; or use a running sum, as appropriate.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|
Hi All
I am getting run time error
Run-time error '424' Object required
I am try to find excel worksheet password through this code
Set xl = CreateObject("Excel.application")
xl.Visible = False
ExcelFile = "D:\Users\Test\Desktop" + "\test1.xls"
On Error GoTo ErrorHandler
For i = 1 To 6
ExcelNword = Conversion.CStr(i)
ExcelPassword = "ABC" + ExcelNword
Set xlBook = xlApp.Workbooks.Open(FileName:=ExcelFile, _
Password:=ExcelPassword)
ErrorHandler:
MsgBox Err.Description, , "Error"
Next i
Can any one help me
|
|
|
|
|
At the beginning of your code you have set the variable xl to point to the application, but later on you use a variable called xlApp .
It's time for a new signature.
|
|
|
|
|
Thanks for reply
i change xlApp to xl.But still i have same problem.
Please help me
|
|
|
|
|
Have you tried to declare the xlBook as a workbook object?
|
|
|
|
|
yes
Please see my full code
Dim xl As New Excel.Application
Dim xlsheet As Excel.Worksheet
Dim xlwbook As Excel.Workbook
Dim ExcelFile As String
Dim ExcelPassword As String
Dim ExcelNword As String
Dim i As Integer
Private Sub Command1_Click()
For i = 1 To 6
Set xl = CreateObject("Excel.application")
xl.Visible = False
ExcelFile = "D:\Users\Test\Desktop" + "\test1.xls"
On Error GoTo ErrorHandler
ExcelNword = Conversion.CStr(i)
ExcelPassword = "ABC" + ExcelNword
Set xlBook = xl.Workbooks.Open(FileName:=ExcelFile, _
Password:=ExcelPassword)
ErrorHandler:
MsgBox Err.Description, , "Error"
xl.Quit
Next i
End Sub
|
|
|
|
|
I am not sure if the location of your xl.quit is destroying the XLApp object.
move it to outside the For Next Loop.
I think the routine will work for the 1st loop, i.e, when i=1, but will fail on successive iterations of the loop.
|
|
|
|
|
i did it but no effect.
Still i have same problem
Please help me
|
|
|
|
|
In that case then if i were you i would stick a breakpoint in at the start and then step through the code line by line until you find exactly where the code is failing.
|
|
|
|
|
Ok i check it through break point.You are right first i check then i post question in forum.
I got where is error.
When i click on Open button then Cursor goes into step by step when cursor came into this line
Set xlBook = xl.Workbooks.Open(FileName:=ExcelFile, _
Password:=ExcelPassword)
Then Message show password is wrong.As we know i use for loop when cursor goes into second time in line
Set xlBook = xl.Workbooks.Open(FileName:=ExcelFile, _
Password:=ExcelPassword)
Then run time error message show.
Please help me
|
|
|
|
|
[Edit2: Original did work, sorry]
Sub Button1_Click()
Dim xl As New Excel.Application
Dim xlsheet As Excel.Worksheet
Dim xlwbook As Excel.Workbook
Dim ExcelFile As String
Dim ExcelPassword As String
Dim i As Integer
ExcelFile = "C:\Users\Dave Auld\Desktop\password_test.xlsx"
Set xl = CreateObject("Excel.application")
xl.Visible = False
On Error Resume Next
For i = 1 To 6
ExcelPassword = "ABC" + CStr(i)
Set xlBook = xl.Workbooks.Open(Filename:=ExcelFile, Password:=ExcelPassword)
If Err.Number > 0 Then
MsgBox "Error: " + Err.Number + ": " + Err.Description, , "Error"
Err = 0
Else
MsgBox "File Opened with Password " + ExcelPassword
Exit For
End If
Next i
xl.Quit
End Sub
Dave
Don't forget to rate messages!Find Me On: Web| Facebook| Twitter| LinkedInWaving? dave.m.auld[at]googlewave.com
modified on Monday, May 17, 2010 6:51 AM
|
|
|
|
|
Thanks you solve my problem.
Sorry for late response
Once again Thanks.
|
|
|
|
|
Your welcome, glad you got it working now.
|
|
|
|
|
What environment are you using? If VB.NET, then you should have a lot of compiler errors anyway...
- You declare a workbook named "xlwbook" and refer to it as "xlbook"
- Declare your i integer inside the procedure
- You declared xl twice (7 instances of Excel running!). If you Dim xl as New Excel.Application that's enough. You shouldn't create a new instance of the Excel object every time your loop runs.
- In .NET you wouldn't need a conversion class. ExcelNword = CStr(i) is enough.
- You should also rather use good old Try... Catch instead of OnError
I gave it a test in VB.NET with then enclosed changed code. Good luck with your further experiments
Michael
Imports Excel = Microsoft.Office.Interop.Excel
Public Class Form1
Dim xl As New Excel.Application
Dim xlwbook As Excel.Workbook
Dim ExcelFile As String
Dim ExcelPassword As String
Dim ExcelNword As String
Private Sub btnStart_Click() Handles btnStart.Click
xl.Visible = False
ExcelFile = "D:\" + "text.xls"
For i = 1 To 6
Try
ExcelNword = CStr(i)
ExcelPassword = "ABC" + ExcelNword
xlwbook = xl.Workbooks.Open(Filename:=ExcelFile, Password:=ExcelPassword)
MsgBox(String.Format("Workbook could be opened with password {0}", ExcelPassword))
Catch ex As Exception
If Err.Number = 1004 Then
MsgBox(String.Format("'{0}' is the wrong password!", ExcelPassword), , "Error")
Else
MsgBox(String.Format("Fehler {0}: {1}", Err.Number.ToString, Err.Description), , "Error")
End If
End Try
Next i
xl.Quit()
xlwbook = Nothing
xl = Nothing
End Sub
End Class
modified on Monday, May 17, 2010 7:06 AM
|
|
|
|
|
I'd say the problem in this code is that you don't increment the name of the file. You set it to "D:\Users\Test\Desktop" + "\test1.xls"
So, it would work the first time, but on the second iteration, it would be comparing the password for workbook 2 with workbook 1.
Did you mean to write:
ExcelFile = "D:\Users\Test\Desktop\test" & i &".xls"
|
|
|
|
|
I don't think he was wanting to increment the file name, but test a sequential number of passwords against the file to find the correct one.
Going by his other post in response to my code listing, the problem is now fixed, so he is a happy bunny.
Cheers,
|
|
|
|
|
Well if that's what he was trying to do, it sure wasn't clear. Why would you open it and if it didn't open, just display the error message? Why display a message at all if it didn't open? You only need to know the correct password, not the incorrect ones. That was very strange code to try to break a password.
|
|
|
|
|
agree, but he's happy!
|
|
|
|
|
Hey Guys,
to first: Sorry for my bad english !!
I have found nothing suitable, despite gegoogle. But maybe someone knows of you the problem.
I have run a VB.Net 3.5 - App with Interbase 6.1. As ADO driver do I use "Firebird ADO.NET Data provider for. NET and Mono 1.7" from
Sean Leyne. (This driver also works with Interbase.)
Now I wanted to switch to Firebird 2.1. The change in the database has
even if folded. All domains, triggers, etc. run from DB.
With my SQL-Console (IB-Expert) can also easily edit the database.
The Connection String is also true:
<Password = masterkey; Database = C: \ XYZ \ DB.FDB; Dialect = 3; User Id = SYSDBA; Data Source = localhost; charset = ISO8859_1>
<br />
...<br />
Public myDataConn As New FbConnection<br />
Public myDataConnString As New FbConnectionStringBuilder<br />
myDataConn.ConnectionString = "Password = masterkey; Database = C:\XYZ\DB.FDB; Dialect = 3; User ID = SYSDBA; Data Source = localhost; charset = ISO8859_1"<br />
myDataConn.Open()<br />
...<br />
But I get the Open() an error message that I do not
can understand .
Error message
"Offset and length of the array are out of range, or
the number is greater than the number of elements from index to end of
Source collection. "(Error Target: Void BlockCopy (System.Array, Int32,
System.Array, Int32, Int32)
With Interbase 6.1 is full working and no problems.
Does anyone know of the problem or you have a tip for the solution?
Thank you in advance for your help
Frank
|
|
|
|
|
You shouldn't post in more than one forum, it is bad form.
You will be answered quicker and better in Quick Answers as it is a specific question.
Thanks.
------------------------------------
I will never again mention that I was the poster of the One Millionth Lounge Post, nor that it was complete drivel. Dalek Dave
|
|
|
|