Adobe Flash Project Creation Error
Whenever I try and create a New Project in Adobe Flash CS6 (Freshly
installed) I get this error. I read in this question: Flash CS6 project
panel error Error #2032: Stream Error that I need to manually copy over
two files from the Adobe Flex 4.5.1 package (which I did). I'm still
getting this error and it's incredibly frustrating, especially off of my
third fresh reinstallation. Has anyone experienced this issue on a Mac,
and figured out how to fix it?
Thanks!
Error #2032: Stream
file:////Volumes/HD/Users/[User]/Library/Application%20Support/Adobe/Flash%20CS6/en%5FUS/Configuration/WindowSWF/framework_4.5.1.21328.swz
Monday, 19 August 2013
Sunday, 18 August 2013
Spring REST not creating _method hidden element
Spring REST not creating _method hidden element
I used to have it working fine, somehow after some development I realized
the HTML element _method is not created automatically on the page thus
REST does not work.
Below is my web.xml which contains the HiddenHttpMethodFilter.
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/spring/root-context.xml,
/WEB-INF/spring/appServlet/*-context.xml
</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.security.web.session.HttpSessionEventPublisher</listener-class>
</listener>
<servlet>
<servlet-name>mvc-dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>trimSpaces</param-name>
<param-value>true</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>mvc-dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter>
<filter-name>HttpMethodFilter</filter-name>
<filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>HttpMethodFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<session-config>
<session-timeout>30</session-timeout>
</session-config>
<error-page>
<error-code>403</error-code>
<location>/errors/403.html</location>
</error-page>
<error-page>
<error-code>404</error-code>
<location>/errors/404.html</location>
</error-page>
<error-page>
<error-code>405</error-code>
<location>/errors/405.html</location>
</error-page>
<error-page>
<error-code>500</error-code>
<location>/errors/500.html</location>
</error-page>
</web-app>
what I have tried
Maven Update Project
Maven Clean > Maven Install
Clear the working directory
I used to have it working fine, somehow after some development I realized
the HTML element _method is not created automatically on the page thus
REST does not work.
Below is my web.xml which contains the HiddenHttpMethodFilter.
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/spring/root-context.xml,
/WEB-INF/spring/appServlet/*-context.xml
</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.security.web.session.HttpSessionEventPublisher</listener-class>
</listener>
<servlet>
<servlet-name>mvc-dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>trimSpaces</param-name>
<param-value>true</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>mvc-dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter>
<filter-name>HttpMethodFilter</filter-name>
<filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>HttpMethodFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<session-config>
<session-timeout>30</session-timeout>
</session-config>
<error-page>
<error-code>403</error-code>
<location>/errors/403.html</location>
</error-page>
<error-page>
<error-code>404</error-code>
<location>/errors/404.html</location>
</error-page>
<error-page>
<error-code>405</error-code>
<location>/errors/405.html</location>
</error-page>
<error-page>
<error-code>500</error-code>
<location>/errors/500.html</location>
</error-page>
</web-app>
what I have tried
Maven Update Project
Maven Clean > Maven Install
Clear the working directory
json, listadapters and multiple on click activity for listviews
json, listadapters and multiple on click activity for listviews
I am using api calls to pull out a json entry and fill in my list view.
The problem I am having is implementing different listeners inside of my
list view. The list view looks like this:
The listView is to implement an onItemClick listener and a checkBox
listener. Till now I was able to populate the listView and generate the
onItemClick listener, but I failed to implement the checkBox listener.
From my tries I am only able to invoke this checkBox listener after the
listView item is clicked and only for one of the checkBoxes(out of
several).
The code looks like this for now:
public class Allprojects extends SherlockListActivity{
ArrayList<HashMap<String, String>> all_list;
ProgressDialog progressDialog;
ActionMode mMode;
ListView list;
private List<Random> randomList = new ArrayList<Random>();
ArrayAdapter<Random> adapterNew;
private SparseBooleanArray mCheckStates;
Layout layoutList;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.projectlist);
ActionBar bar = getSupportActionBar();
bar.setDisplayShowTitleEnabled(false);
bar.setDisplayHomeAsUpEnabled(false);
bar.setNavigationMode(com.actionbarsherlock.app.ActionBar.NAVIGATION_MODE_LIST);
SpinnerAdapter mSpinnerAdapter =
ArrayAdapter.createFromResource(getApplicationContext(),
R.array.actionbarnavlist,
android.R.layout.simple_dropdown_item_1line);
OnNavigationListener mNavigationlistner = new OnNavigationListener() {
@Override
public boolean onNavigationItemSelected(int itemPosition, long itemId) {
switch (itemPosition) {
case 0:
// Toast.makeText(getApplicationContext(), "You are already viewing all
projects", Toast.LENGTH_LONG).show();
break;
case 1:
Intent intent = new Intent(Allprojects.this, Myproject.class);
startActivity(intent);
finish();
break;
default:
break;
}
return false;
}
};
bar.setListNavigationCallbacks(mSpinnerAdapter, mNavigationlistner);
bar.setSelectedNavigationItem(0);
all_list = new ArrayList<HashMap<String, String>>();
Asyncprojectlist connection = new Asyncprojectlist();
connection.execute();
}
private ActionMode.Callback mActionCallBack = new ActionMode.Callback() {
@Override
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
// TODO Auto-generated method stub
return false;
}
@Override
public void onDestroyActionMode(ActionMode mode) {
// TODO Auto-generated method stub
}
@Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
// TODO Auto-generated method stub
MenuInflater inflater = mode.getMenuInflater();
inflater.inflate(R.menu.contextual_menu_add_project, menu);
return true;
}
@Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
// TODO Auto-generated method stub
switch(item.getItemId()){
case R.id.cancelActionMenu:
break;
case R.id.addToProjectsMenu:
break;
default:
break;
}
return false;
}
};
@Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
getSupportActionBar().setSubtitle("press to start selection");
}
private class Asyncprojectlist extends AsyncTask<Void, Void, Void>{
JSONArray JSar;
JSONObject JSob;
String project_title, project_sector;
@Override
protected void onPreExecute() {
progressDialog = new ProgressDialog(Allprojects.this);
progressDialog.setCancelable(false);
progressDialog.setMessage("Loading...");
progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
progressDialog.setProgress(0);
progressDialog.show();
}
@Override
protected Void doInBackground(Void... params) {
UserFunctions user = new UserFunctions();
JSob = user.allprojects();
try {
JSar = JSob.getJSONArray("data");
} catch (JSONException e1) {
e1.printStackTrace();
}
for(int i=0; i<JSar.length(); i++){
try {
JSONObject newobj = JSar.getJSONObject(i);
project_title = newobj.getString("title");
project_sector = newobj.getString("sector");
HashMap<String, String> single = new HashMap<String, String>();
single.put("title", project_title);
single.put("sector", project_sector);
all_list.add(single);
} catch (JSONException e) {
e.printStackTrace();
}
}
// Log.i("json object", JSar.toString());
return null;
}
@Override
protected void onPostExecute(Void result) {
ListAdapter adapter = new SimpleAdapter(getApplicationContext(),
all_list, R.layout.projectlist_frame,
new String[]{"title","sector"}, new int[]{R.id.projecttitle,
R.id.projectsector});
setListAdapter(adapter);
progressDialog.dismiss();
list = getListView();
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View viewClicked,
int position, long id) {
Intent toindividual = new Intent(Allprojects.this,
Individual_project.class);
try {
toindividual.putExtra("nid",
JSar.getJSONObject(position).getString("id"));
startActivity(toindividual);
} catch (JSONException e) {
e.printStackTrace();
}
projectCheckBox.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
if(projectCheckBox.isChecked()){
Log.i("CHECKED", "CHECKED");
startActionMode(mActionCallBack);
}else{
Log.i("UNCHECKED","UNCHECKED");
startActionMode(mActionCallBack).finish();
}
}
});
}
});
}
}
}
I am using api calls to pull out a json entry and fill in my list view.
The problem I am having is implementing different listeners inside of my
list view. The list view looks like this:
The listView is to implement an onItemClick listener and a checkBox
listener. Till now I was able to populate the listView and generate the
onItemClick listener, but I failed to implement the checkBox listener.
From my tries I am only able to invoke this checkBox listener after the
listView item is clicked and only for one of the checkBoxes(out of
several).
The code looks like this for now:
public class Allprojects extends SherlockListActivity{
ArrayList<HashMap<String, String>> all_list;
ProgressDialog progressDialog;
ActionMode mMode;
ListView list;
private List<Random> randomList = new ArrayList<Random>();
ArrayAdapter<Random> adapterNew;
private SparseBooleanArray mCheckStates;
Layout layoutList;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.projectlist);
ActionBar bar = getSupportActionBar();
bar.setDisplayShowTitleEnabled(false);
bar.setDisplayHomeAsUpEnabled(false);
bar.setNavigationMode(com.actionbarsherlock.app.ActionBar.NAVIGATION_MODE_LIST);
SpinnerAdapter mSpinnerAdapter =
ArrayAdapter.createFromResource(getApplicationContext(),
R.array.actionbarnavlist,
android.R.layout.simple_dropdown_item_1line);
OnNavigationListener mNavigationlistner = new OnNavigationListener() {
@Override
public boolean onNavigationItemSelected(int itemPosition, long itemId) {
switch (itemPosition) {
case 0:
// Toast.makeText(getApplicationContext(), "You are already viewing all
projects", Toast.LENGTH_LONG).show();
break;
case 1:
Intent intent = new Intent(Allprojects.this, Myproject.class);
startActivity(intent);
finish();
break;
default:
break;
}
return false;
}
};
bar.setListNavigationCallbacks(mSpinnerAdapter, mNavigationlistner);
bar.setSelectedNavigationItem(0);
all_list = new ArrayList<HashMap<String, String>>();
Asyncprojectlist connection = new Asyncprojectlist();
connection.execute();
}
private ActionMode.Callback mActionCallBack = new ActionMode.Callback() {
@Override
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
// TODO Auto-generated method stub
return false;
}
@Override
public void onDestroyActionMode(ActionMode mode) {
// TODO Auto-generated method stub
}
@Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
// TODO Auto-generated method stub
MenuInflater inflater = mode.getMenuInflater();
inflater.inflate(R.menu.contextual_menu_add_project, menu);
return true;
}
@Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
// TODO Auto-generated method stub
switch(item.getItemId()){
case R.id.cancelActionMenu:
break;
case R.id.addToProjectsMenu:
break;
default:
break;
}
return false;
}
};
@Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
getSupportActionBar().setSubtitle("press to start selection");
}
private class Asyncprojectlist extends AsyncTask<Void, Void, Void>{
JSONArray JSar;
JSONObject JSob;
String project_title, project_sector;
@Override
protected void onPreExecute() {
progressDialog = new ProgressDialog(Allprojects.this);
progressDialog.setCancelable(false);
progressDialog.setMessage("Loading...");
progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
progressDialog.setProgress(0);
progressDialog.show();
}
@Override
protected Void doInBackground(Void... params) {
UserFunctions user = new UserFunctions();
JSob = user.allprojects();
try {
JSar = JSob.getJSONArray("data");
} catch (JSONException e1) {
e1.printStackTrace();
}
for(int i=0; i<JSar.length(); i++){
try {
JSONObject newobj = JSar.getJSONObject(i);
project_title = newobj.getString("title");
project_sector = newobj.getString("sector");
HashMap<String, String> single = new HashMap<String, String>();
single.put("title", project_title);
single.put("sector", project_sector);
all_list.add(single);
} catch (JSONException e) {
e.printStackTrace();
}
}
// Log.i("json object", JSar.toString());
return null;
}
@Override
protected void onPostExecute(Void result) {
ListAdapter adapter = new SimpleAdapter(getApplicationContext(),
all_list, R.layout.projectlist_frame,
new String[]{"title","sector"}, new int[]{R.id.projecttitle,
R.id.projectsector});
setListAdapter(adapter);
progressDialog.dismiss();
list = getListView();
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View viewClicked,
int position, long id) {
Intent toindividual = new Intent(Allprojects.this,
Individual_project.class);
try {
toindividual.putExtra("nid",
JSar.getJSONObject(position).getString("id"));
startActivity(toindividual);
} catch (JSONException e) {
e.printStackTrace();
}
projectCheckBox.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
if(projectCheckBox.isChecked()){
Log.i("CHECKED", "CHECKED");
startActionMode(mActionCallBack);
}else{
Log.i("UNCHECKED","UNCHECKED");
startActionMode(mActionCallBack).finish();
}
}
});
}
});
}
}
}
Android Volley - Cancel NetworkImageView request in Base Adapter
Android Volley - Cancel NetworkImageView request in Base Adapter
As the title says, I'm using a BaseAdapter to display items in a ListView.
Obviously a ListView will reuse views, including TextViews and
NetworkImageViews.
Assuming 3 items can be displayed at once, the NetworkImageView will be
reused for items at index: 1, 4, 7, ....
Depending on what's being displayed, the NetworkImageView will either:
request the image from the Network and display it,
display a cached Bitmap,
or display a local drawable resource.
Items 2 and 3 work fine, however in Scenario 1, let's say we're displaying
item at index 4 from the network, and the user scrolls to item 7 before 4
is loaded and it's a local resource, we display the local resource.
However our network image request may just be finishing now, so we end up
displaying an incorrect image.
How can I enforce the proper (expected)behavior?
As the title says, I'm using a BaseAdapter to display items in a ListView.
Obviously a ListView will reuse views, including TextViews and
NetworkImageViews.
Assuming 3 items can be displayed at once, the NetworkImageView will be
reused for items at index: 1, 4, 7, ....
Depending on what's being displayed, the NetworkImageView will either:
request the image from the Network and display it,
display a cached Bitmap,
or display a local drawable resource.
Items 2 and 3 work fine, however in Scenario 1, let's say we're displaying
item at index 4 from the network, and the user scrolls to item 7 before 4
is loaded and it's a local resource, we display the local resource.
However our network image request may just be finishing now, so we end up
displaying an incorrect image.
How can I enforce the proper (expected)behavior?
HoloEverywhere+ Sherlock error
HoloEverywhere+ Sherlock error
I've installed HoloEverywhere and Action Bar Sherlock, and I've added ABS
as library to holoeverywhere. But Holoeverywhere have a bullet on it, and
when installing as library for my project, it's a red X on it.
I've installed HoloEverywhere and Action Bar Sherlock, and I've added ABS
as library to holoeverywhere. But Holoeverywhere have a bullet on it, and
when installing as library for my project, it's a red X on it.
Error in my Image COMPRESSION code USING DCT2D in matlab
Error in my Image COMPRESSION code USING DCT2D in matlab
I'm trying to fix a program already exists, but there is always this error
"Error in ==> DCT1 at 254 decm_eq BIN2DEC = ([I_runcode (a, b) code (1 + m
* (c_indx-1). M * c_indx) DEC2BIN (0 bpp_diff)]). "I do not know what to
do. Please help me
%% LOSSY COMPRESSION-DECOMPRESSION USNIG DISCRETE COSINE TRANSFORM TECHNIQUE.
function[]=dct1(filename,n,m)
% "filename" is the string of characters including Image name and its
% extension.
% "n" denotes the number of bits per pixel.
% "m" denotes the number of most significant bits (MSB) of DCT Coefficients.
% Matrix Intializations.
N=8; % Block size for which DCT is Computed.
M=8;
I=imread(filename); % Reading the input image file and storing
intensity values in 2-D matrix I.
I_dim=size(I); % Finding the dimensions of the image file.
I_Trsfrm.block=zeros(N,M); % Initialising the DCT Coefficients Structure
Matrix "I_Trsfrm" with the required dimensions.
Norm_Mat=[16 11 10 16 24 40 51 61 % Normalization matrix (8 X 8)
used to Normalize the DCT Matrix.
12 12 14 19 26 58 60 55
14 13 16 24 40 57 69 56
14 17 22 29 51 87 80 62
18 22 37 56 68 109 103 77
24 35 55 64 81 104 113 92
49 64 78 87 103 121 120 101
72 92 95 98 112 100 103 99];
save('LenaInitial.txt','I');
%% PART-1: COMPRESSION TECHNIQUE.
% Computing the Quantized & Normalized Discrete Cosine Transform.
%
Y(k,l)=(2/root(NM))*c(k)*c(l)*sigma(i=0:N-1)sigma(j=0:M-1)y(i,j)cos(pi(2i+1)k/(2N))cos(pi(2j+1)l/(2M))
% where c(u)=1/root(2) if u=0
% = 1 if u>0
for a=1:I_dim(1)/N
for b=1:I_dim(2)/M
for k=1:N
for l=1:M
prod=0;
for i=1:N
for j=1:M
prod=prod+double(I(N*(a-1)+i,M*(b-1)+j))*cos(pi*(k-1)*(2*i-1)/(2*N))*cos(pi*(l-1)*(2*j-1)/(2*M));
end
end
if k==1
prod=prod*sqrt(1/N);
else
prod=prod*sqrt(2/N);
end
if l==1
prod=prod*sqrt(1/M);
else
prod=prod*sqrt(2/M);
end
I_Trsfrm(a,b).block(k,l)=prod;
end
end
% Normalizing the DCT Matrix and Quantizing the resulting values.
I_Trsfrm(a,b).block=round(I_Trsfrm(a,b).block./Norm_Mat);
end
end
% zig-zag coding of the each 8 X 8 Block.
for a=1:I_dim(1)/N
for b=1:I_dim(2)/M
I_zigzag(a,b).block=zeros(1,0);
freq_sum=2:(N+M);
counter=1;
for i=1:length(freq_sum)
if i<=((length(freq_sum)+1)/2)
if rem(i,2)~=0
x_indices=counter:freq_sum(i)-counter;
else
x_indices=freq_sum(i)-counter:-1:counter;
end
index_len=length(x_indices);
y_indices=x_indices(index_len:-1:1); % Creating
reverse of the array as "y_indices".
for p=1:index_len
if I_Trsfrm(a,b).block(x_indices(p),y_indices(p))<0
bin_eq=dec2bin(bitxor(2^n-1,abs(I_Trsfrm(a,b).block(x_indices(p),y_indices(p)))),n);
else
bin_eq=dec2bin(I_Trsfrm(a,b).block(x_indices(p),y_indices(p)),n);
end
I_zigzag(a,b).block=[I_zigzag(a,b).block,bin_eq(1:m)];
end
else
counter=counter+1;
if rem(i,2)~=0
x_indices=counter:freq_sum(i)-counter;
else
x_indices=freq_sum(i)-counter:-1:counter;
end
index_len=length(x_indices);
y_indices=x_indices(index_len:-1:1); % Creating
reverse of the array as "y_indices".
for p=1:index_len
if I_Trsfrm(a,b).block(x_indices(p),y_indices(p))<0
bin_eq=dec2bin(bitxor(2^n-1,abs(I_Trsfrm(a,b).block(x_indices(p),y_indices(p)))),n);
else
bin_eq=dec2bin(I_Trsfrm(a,b).block(x_indices(p),y_indices(p)),n);
end
I_zigzag(a,b).block=[I_zigzag(a,b).block,bin_eq(1:m)];
end
end
end
end
end
% Clearing unused variables from Memory space
clear I_Trsfrm prod;
clear x_indices y_indices counter;
% Run-Length Encoding the resulting code.
for a=1:I_dim(1)/N
for b=1:I_dim(2)/M
% Computing the Count values for the corresponding symbols and
% savin them in "I_run" structure.
count=0;
run=zeros(1,0);
sym=I_zigzag(a,b).block(1);
j=1;
block_len=length(I_zigzag(a,b).block);
for i=1:block_len
if I_zigzag(a,b).block(i)==sym
count=count+1;
else
run.count(j)=count;
run.sym(j)=sym;
j=j+1;
sym=I_zigzag(a,b).block(i);
count=1;
end
if i==block_len
run.count(j)=count;
run.sym(j)=sym;
end
end
% Computing the codelength needed for the count values.
dim=length(run.count); % calculates number of symbols being encoded.
maxvalue=max(run.count); % finds the maximum count value in the
count array of run structure.
codelength=log2(maxvalue)+1;
codelength=floor(codelength);
% Encoding the count values along with their symbols.
I_runcode(a,b).code=zeros(1,0);
for i=1:dim
I_runcode(a,b).code=[I_runcode(a,b).code,dec2bin(run.count(i),codelength),run.sym(i)];
end
end
end
% Saving the Compressed Code to Disk.
save ('LenaCompressed.txt','I_runcode');
% Clearing unused variables from Memory Space.
clear I_zigzag run;
%% PART-2: DECOMPRESSION TECHNIQUE.
% Run-Length Decoding of the compressed image.
for a=1:I_dim(1)/N
for b=1:I_dim(2)/M
enc_str=I_runcode(a,b).code;
% Computing the length of the encoded string.
enc_len=length(enc_str);
% Since Max. Count is unknown at the receiver, Number of bits used
for each
% count value is unknown and hence cannot be decoded directly.
Number of bits
% used for each count can be found out by trial and error method
for all
% the possible lengths => factors of encoded string length.
% Computing the non-trivial factors of the "enc_len" (length of
encoded
% string) i.e., factors other than 1 & itself.
factors_mat=zeros(1,0);
if enc_len<=(n+1)
realfact=enc_len;
else
for i=2:enc_len-2 % "enc_len-1" is always not a divisor
of "enc_len".
if(rem(enc_len,i)==0)
factors_mat=[factors_mat,i];
end
end
% Trial and Error Method to Find the Exact count value.
for i=1:length(factors_mat)
flagcntr=0;
temp_dim=enc_len/factors_mat(i);
for j=1:temp_dim
if
strcmp(enc_str(1+(j-1)*factors_mat(i):j*factors_mat(i)),dec2bin(0,factors_mat(i)))==0
if j==1
flagcntr=flagcntr+1;
else
if
enc_str((j-1)*factors_mat(i))~=enc_str(j*factors_mat(i))
flagcntr=flagcntr+1;
else
break;
end
end
else
break;
end
end
if flagcntr==temp_dim
realfact=factors_mat(i);
break;
end
end
end
% Clearing unused variables from Memory space
clear factors_mat flagcntr j
% Finding out the count values of corresponding symbols in the
encoded
% string and then decoding it accordingly.
dec_str=zeros(1,0);
temp_dim=enc_len/realfact;
for i=1:temp_dim
count_str=enc_str(1+(i-1)*realfact:(i*realfact)-1);
countval=bin2dec(count_str);
for j=1:countval
dec_str=[dec_str,enc_str(i*realfact)];
end
end
I_runcode(a,b).code=dec_str;
end
end
% Clearing unused variables from Memory space
clear enc_str dec_str temp_dim realfact enc_len
clear countval count_str
% Reconstructing the 8 X 8 blocks in Zig-Zag fashion.
I_rec_Trnsfm.block=zeros(N,M);
for a=1:I_dim(1)/N
for b=1:I_dim(2)/M
bpp=length(I_runcode(a,b).code)/(N*M); % "bpp" is the
bits-per-pixel in reconstruction of image.
bpp_diff=n-bpp;
freq_sum=2:(N+M);
counter=1;
c_indx=1;
for i=1:length(freq_sum)
if i<=((length(freq_sum)+1)/2)
if rem(i,2)~=0
x_indices=counter:freq_sum(i)-counter;
else
x_indices=freq_sum(i)-counter:-1:counter;
end
index_len=length(x_indices);
y_indices=x_indices(index_len:-1:1); % Creating
reverse of the array as "y_indices".
for p=1:index_len
decm_eq=bin2dec([I_runcode(a,b).code(1+m*(c_indx-1):m*c_indx),dec2bin(0,bpp_diff)]);
if decm_eq>(2^(n-1))-1
decm_eq=decm_eq-(2^n-1);
end
I_rec_Trnsfm(a,b).block(x_indices(p),y_indices(p))=decm_eq;
c_indx=c_indx+1;
end
else
counter=counter+1;
if rem(i,2)~=0
x_indices=counter:freq_sum(i)-counter;
else
x_indices=freq_sum(i)-counter:-1:counter;
end
index_len=length(x_indices);
y_indices=x_indices(index_len:-1:1); % Creating
reverse of the array as "y_indices".
for p=1:index_len
decm_eq=bin2dec([I_runcode(a,b).code(1+m*(c_indx-1):m*c_indx),dec2bin(0,bpp_diff)]);
if decm_eq>(2^(n-1))-1
decm_eq=decm_eq-(2^n-1);
end
I_rec_Trnsfm(a,b).block(x_indices(p),y_indices(p))=decm_eq;
c_indx=c_indx+1;
end
end
end
end
end
% Clearing unused variables from Memory space
clear I_runcode x_indices y_indices
clear c_indx freq_sum
% Denormalizing the Reconstructed Tranform matrix using the same
% Normalization matrix.
for a=1:I_dim(1)/N
for b=1:I_dim(2)/M
I_rec_Trnsfm(a,b).block=(I_rec_Trnsfm(a,b).block).*Norm_Mat;
end
end
% Inverse-Discrete Cosine Transform on the reconstructed Matrix.
% y(i,j)=(2/root(NM))*sigma(i=0:N-1)sigma(j=0:M-1)
Y(k,l)c(k)*c(l)*cos(pi(2i+1)k/(2N))cos(pi(2j+1)l/(2M))
% where c(u)=1/root(2) if u=0
% = 1 if u>0
for a=1:I_dim(1)/N
for b=1:I_dim(2)/M
for i=1:N
for j=1:M
prod=0;
for k=1:N
for l=1:M
if k==1
temp=double(sqrt(1/2)*I_rec_Trnsfm(a,b).block(k,l))*cos(pi*(k-1)*(2*i-1)/(2*N))*cos(pi*(l-1)*(2*j-1)/(2*M));
else
temp=double(I_rec_Trnsfm(a,b).block(k,l))*cos(pi*(k-1)*(2*i-1)/(2*N))*cos(pi*(l-1)*(2*j-1)/(2*M));
end
if l==1
temp=temp*sqrt(1/2);
end
prod=prod+temp;
end
end
prod=prod*(2/sqrt(M*N));
I_rec((a-1)*N+i,(b-1)*M+j)=prod;
end
end
end
end
% Clearing unused variables from Memory Space.
clear I_rec_Trnsfm
% Displaying the Reconstructed Image.
diff=im2double(I)*255-I_rec;
diff=diff/max(max(diff));
diff=im2uint8(diff);
I_rec=I_rec/max(max(I_rec));
I_rec=im2uint8(I_rec);
% figure,imshow(I_rec,[0,2^n-1]);
% figure,imshow(diff,[0 2^n-1])
figure, imhist(I_rec);
figure, imhist(diff);
I'm trying to fix a program already exists, but there is always this error
"Error in ==> DCT1 at 254 decm_eq BIN2DEC = ([I_runcode (a, b) code (1 + m
* (c_indx-1). M * c_indx) DEC2BIN (0 bpp_diff)]). "I do not know what to
do. Please help me
%% LOSSY COMPRESSION-DECOMPRESSION USNIG DISCRETE COSINE TRANSFORM TECHNIQUE.
function[]=dct1(filename,n,m)
% "filename" is the string of characters including Image name and its
% extension.
% "n" denotes the number of bits per pixel.
% "m" denotes the number of most significant bits (MSB) of DCT Coefficients.
% Matrix Intializations.
N=8; % Block size for which DCT is Computed.
M=8;
I=imread(filename); % Reading the input image file and storing
intensity values in 2-D matrix I.
I_dim=size(I); % Finding the dimensions of the image file.
I_Trsfrm.block=zeros(N,M); % Initialising the DCT Coefficients Structure
Matrix "I_Trsfrm" with the required dimensions.
Norm_Mat=[16 11 10 16 24 40 51 61 % Normalization matrix (8 X 8)
used to Normalize the DCT Matrix.
12 12 14 19 26 58 60 55
14 13 16 24 40 57 69 56
14 17 22 29 51 87 80 62
18 22 37 56 68 109 103 77
24 35 55 64 81 104 113 92
49 64 78 87 103 121 120 101
72 92 95 98 112 100 103 99];
save('LenaInitial.txt','I');
%% PART-1: COMPRESSION TECHNIQUE.
% Computing the Quantized & Normalized Discrete Cosine Transform.
%
Y(k,l)=(2/root(NM))*c(k)*c(l)*sigma(i=0:N-1)sigma(j=0:M-1)y(i,j)cos(pi(2i+1)k/(2N))cos(pi(2j+1)l/(2M))
% where c(u)=1/root(2) if u=0
% = 1 if u>0
for a=1:I_dim(1)/N
for b=1:I_dim(2)/M
for k=1:N
for l=1:M
prod=0;
for i=1:N
for j=1:M
prod=prod+double(I(N*(a-1)+i,M*(b-1)+j))*cos(pi*(k-1)*(2*i-1)/(2*N))*cos(pi*(l-1)*(2*j-1)/(2*M));
end
end
if k==1
prod=prod*sqrt(1/N);
else
prod=prod*sqrt(2/N);
end
if l==1
prod=prod*sqrt(1/M);
else
prod=prod*sqrt(2/M);
end
I_Trsfrm(a,b).block(k,l)=prod;
end
end
% Normalizing the DCT Matrix and Quantizing the resulting values.
I_Trsfrm(a,b).block=round(I_Trsfrm(a,b).block./Norm_Mat);
end
end
% zig-zag coding of the each 8 X 8 Block.
for a=1:I_dim(1)/N
for b=1:I_dim(2)/M
I_zigzag(a,b).block=zeros(1,0);
freq_sum=2:(N+M);
counter=1;
for i=1:length(freq_sum)
if i<=((length(freq_sum)+1)/2)
if rem(i,2)~=0
x_indices=counter:freq_sum(i)-counter;
else
x_indices=freq_sum(i)-counter:-1:counter;
end
index_len=length(x_indices);
y_indices=x_indices(index_len:-1:1); % Creating
reverse of the array as "y_indices".
for p=1:index_len
if I_Trsfrm(a,b).block(x_indices(p),y_indices(p))<0
bin_eq=dec2bin(bitxor(2^n-1,abs(I_Trsfrm(a,b).block(x_indices(p),y_indices(p)))),n);
else
bin_eq=dec2bin(I_Trsfrm(a,b).block(x_indices(p),y_indices(p)),n);
end
I_zigzag(a,b).block=[I_zigzag(a,b).block,bin_eq(1:m)];
end
else
counter=counter+1;
if rem(i,2)~=0
x_indices=counter:freq_sum(i)-counter;
else
x_indices=freq_sum(i)-counter:-1:counter;
end
index_len=length(x_indices);
y_indices=x_indices(index_len:-1:1); % Creating
reverse of the array as "y_indices".
for p=1:index_len
if I_Trsfrm(a,b).block(x_indices(p),y_indices(p))<0
bin_eq=dec2bin(bitxor(2^n-1,abs(I_Trsfrm(a,b).block(x_indices(p),y_indices(p)))),n);
else
bin_eq=dec2bin(I_Trsfrm(a,b).block(x_indices(p),y_indices(p)),n);
end
I_zigzag(a,b).block=[I_zigzag(a,b).block,bin_eq(1:m)];
end
end
end
end
end
% Clearing unused variables from Memory space
clear I_Trsfrm prod;
clear x_indices y_indices counter;
% Run-Length Encoding the resulting code.
for a=1:I_dim(1)/N
for b=1:I_dim(2)/M
% Computing the Count values for the corresponding symbols and
% savin them in "I_run" structure.
count=0;
run=zeros(1,0);
sym=I_zigzag(a,b).block(1);
j=1;
block_len=length(I_zigzag(a,b).block);
for i=1:block_len
if I_zigzag(a,b).block(i)==sym
count=count+1;
else
run.count(j)=count;
run.sym(j)=sym;
j=j+1;
sym=I_zigzag(a,b).block(i);
count=1;
end
if i==block_len
run.count(j)=count;
run.sym(j)=sym;
end
end
% Computing the codelength needed for the count values.
dim=length(run.count); % calculates number of symbols being encoded.
maxvalue=max(run.count); % finds the maximum count value in the
count array of run structure.
codelength=log2(maxvalue)+1;
codelength=floor(codelength);
% Encoding the count values along with their symbols.
I_runcode(a,b).code=zeros(1,0);
for i=1:dim
I_runcode(a,b).code=[I_runcode(a,b).code,dec2bin(run.count(i),codelength),run.sym(i)];
end
end
end
% Saving the Compressed Code to Disk.
save ('LenaCompressed.txt','I_runcode');
% Clearing unused variables from Memory Space.
clear I_zigzag run;
%% PART-2: DECOMPRESSION TECHNIQUE.
% Run-Length Decoding of the compressed image.
for a=1:I_dim(1)/N
for b=1:I_dim(2)/M
enc_str=I_runcode(a,b).code;
% Computing the length of the encoded string.
enc_len=length(enc_str);
% Since Max. Count is unknown at the receiver, Number of bits used
for each
% count value is unknown and hence cannot be decoded directly.
Number of bits
% used for each count can be found out by trial and error method
for all
% the possible lengths => factors of encoded string length.
% Computing the non-trivial factors of the "enc_len" (length of
encoded
% string) i.e., factors other than 1 & itself.
factors_mat=zeros(1,0);
if enc_len<=(n+1)
realfact=enc_len;
else
for i=2:enc_len-2 % "enc_len-1" is always not a divisor
of "enc_len".
if(rem(enc_len,i)==0)
factors_mat=[factors_mat,i];
end
end
% Trial and Error Method to Find the Exact count value.
for i=1:length(factors_mat)
flagcntr=0;
temp_dim=enc_len/factors_mat(i);
for j=1:temp_dim
if
strcmp(enc_str(1+(j-1)*factors_mat(i):j*factors_mat(i)),dec2bin(0,factors_mat(i)))==0
if j==1
flagcntr=flagcntr+1;
else
if
enc_str((j-1)*factors_mat(i))~=enc_str(j*factors_mat(i))
flagcntr=flagcntr+1;
else
break;
end
end
else
break;
end
end
if flagcntr==temp_dim
realfact=factors_mat(i);
break;
end
end
end
% Clearing unused variables from Memory space
clear factors_mat flagcntr j
% Finding out the count values of corresponding symbols in the
encoded
% string and then decoding it accordingly.
dec_str=zeros(1,0);
temp_dim=enc_len/realfact;
for i=1:temp_dim
count_str=enc_str(1+(i-1)*realfact:(i*realfact)-1);
countval=bin2dec(count_str);
for j=1:countval
dec_str=[dec_str,enc_str(i*realfact)];
end
end
I_runcode(a,b).code=dec_str;
end
end
% Clearing unused variables from Memory space
clear enc_str dec_str temp_dim realfact enc_len
clear countval count_str
% Reconstructing the 8 X 8 blocks in Zig-Zag fashion.
I_rec_Trnsfm.block=zeros(N,M);
for a=1:I_dim(1)/N
for b=1:I_dim(2)/M
bpp=length(I_runcode(a,b).code)/(N*M); % "bpp" is the
bits-per-pixel in reconstruction of image.
bpp_diff=n-bpp;
freq_sum=2:(N+M);
counter=1;
c_indx=1;
for i=1:length(freq_sum)
if i<=((length(freq_sum)+1)/2)
if rem(i,2)~=0
x_indices=counter:freq_sum(i)-counter;
else
x_indices=freq_sum(i)-counter:-1:counter;
end
index_len=length(x_indices);
y_indices=x_indices(index_len:-1:1); % Creating
reverse of the array as "y_indices".
for p=1:index_len
decm_eq=bin2dec([I_runcode(a,b).code(1+m*(c_indx-1):m*c_indx),dec2bin(0,bpp_diff)]);
if decm_eq>(2^(n-1))-1
decm_eq=decm_eq-(2^n-1);
end
I_rec_Trnsfm(a,b).block(x_indices(p),y_indices(p))=decm_eq;
c_indx=c_indx+1;
end
else
counter=counter+1;
if rem(i,2)~=0
x_indices=counter:freq_sum(i)-counter;
else
x_indices=freq_sum(i)-counter:-1:counter;
end
index_len=length(x_indices);
y_indices=x_indices(index_len:-1:1); % Creating
reverse of the array as "y_indices".
for p=1:index_len
decm_eq=bin2dec([I_runcode(a,b).code(1+m*(c_indx-1):m*c_indx),dec2bin(0,bpp_diff)]);
if decm_eq>(2^(n-1))-1
decm_eq=decm_eq-(2^n-1);
end
I_rec_Trnsfm(a,b).block(x_indices(p),y_indices(p))=decm_eq;
c_indx=c_indx+1;
end
end
end
end
end
% Clearing unused variables from Memory space
clear I_runcode x_indices y_indices
clear c_indx freq_sum
% Denormalizing the Reconstructed Tranform matrix using the same
% Normalization matrix.
for a=1:I_dim(1)/N
for b=1:I_dim(2)/M
I_rec_Trnsfm(a,b).block=(I_rec_Trnsfm(a,b).block).*Norm_Mat;
end
end
% Inverse-Discrete Cosine Transform on the reconstructed Matrix.
% y(i,j)=(2/root(NM))*sigma(i=0:N-1)sigma(j=0:M-1)
Y(k,l)c(k)*c(l)*cos(pi(2i+1)k/(2N))cos(pi(2j+1)l/(2M))
% where c(u)=1/root(2) if u=0
% = 1 if u>0
for a=1:I_dim(1)/N
for b=1:I_dim(2)/M
for i=1:N
for j=1:M
prod=0;
for k=1:N
for l=1:M
if k==1
temp=double(sqrt(1/2)*I_rec_Trnsfm(a,b).block(k,l))*cos(pi*(k-1)*(2*i-1)/(2*N))*cos(pi*(l-1)*(2*j-1)/(2*M));
else
temp=double(I_rec_Trnsfm(a,b).block(k,l))*cos(pi*(k-1)*(2*i-1)/(2*N))*cos(pi*(l-1)*(2*j-1)/(2*M));
end
if l==1
temp=temp*sqrt(1/2);
end
prod=prod+temp;
end
end
prod=prod*(2/sqrt(M*N));
I_rec((a-1)*N+i,(b-1)*M+j)=prod;
end
end
end
end
% Clearing unused variables from Memory Space.
clear I_rec_Trnsfm
% Displaying the Reconstructed Image.
diff=im2double(I)*255-I_rec;
diff=diff/max(max(diff));
diff=im2uint8(diff);
I_rec=I_rec/max(max(I_rec));
I_rec=im2uint8(I_rec);
% figure,imshow(I_rec,[0,2^n-1]);
% figure,imshow(diff,[0 2^n-1])
figure, imhist(I_rec);
figure, imhist(diff);
Controlling The Massive Spacing Between TH Elements
Controlling The Massive Spacing Between TH Elements
I've checked about 50 links in the past 20 minutes and tried every
combination of stuff I can think of but there is still this massive
automatic gap between my th elements, as seen in the picture below.
The test column will eventually be removed so that item has a colspan of
2, but in the mean time I cannot figure out how to remove this gap.
Picture: http://imgur.com/Herr27e
Markup & CSS: Both generated from HAML and SCSS respectively.
<div class="ticker">
<h2>NEW LISTINGS</h2>
<div class="ticker-body">
<table id="new-listings">
<thead>
<tr>
<th>Item</th>
<th>test</th>
<th>Seller</th>
<th>Seller Wants</th>
</tr>
</thead>
<tbody>
<tr>
<td class="item-image">
<div class="item-image-container">
<a href="#"></a>
</div>
</td>
<td>Item Name</td>
<td>tsujp</td>
<td>Something Else Here</td>
</tr>
<tr>
<td class="item-image">
<div class="item-image-container">
<a href="#"></a>
</div>
</td>
<td>Item Name</td>
<td>tsujpdsds</td>
<td>Something Else Here</td>
</tr>
</tbody>
</table>
</div>
</div>
.ticker
{
.ticker-body
{
margin-top: 10px;
border: 1px solid $type25Border;
@include transition( border 0.2s ease-in-out );
&:hover
{
border: 1px solid $greenText;
}
}
}
table#new-listings
{
width: 645px;
color: $whiteText;
thead
{
font-family: "opensans-SB";
font-size: 14px;
th
{
padding-top: 15px;
padding-bottom: 8px;
}
}
th, td
{
text-align: left;
vertical-align: middle;
padding: 5px 10px 5px 10px;
}
tbody
{
tr
{
font-family: "opensans-R";
font-size: 12px;
//border-top: 1px solid $type35Border;
&:nth-child(odd) { background-color: $type60Background; }
&:nth-child(even) { background-color: $type70Background; }
.item-image
{
width: 45px;
height: 32px;
.item-image-container
{
width: 100%;
height: 100%;
background-size: contain;
background-repeat: no-repeat;
background-position: center;
background-image: url( "src/hornmask.png" );
border: 1px solid $type35Border;
box-shadow: $softShadow;
}
}
}
}
}
I've checked about 50 links in the past 20 minutes and tried every
combination of stuff I can think of but there is still this massive
automatic gap between my th elements, as seen in the picture below.
The test column will eventually be removed so that item has a colspan of
2, but in the mean time I cannot figure out how to remove this gap.
Picture: http://imgur.com/Herr27e
Markup & CSS: Both generated from HAML and SCSS respectively.
<div class="ticker">
<h2>NEW LISTINGS</h2>
<div class="ticker-body">
<table id="new-listings">
<thead>
<tr>
<th>Item</th>
<th>test</th>
<th>Seller</th>
<th>Seller Wants</th>
</tr>
</thead>
<tbody>
<tr>
<td class="item-image">
<div class="item-image-container">
<a href="#"></a>
</div>
</td>
<td>Item Name</td>
<td>tsujp</td>
<td>Something Else Here</td>
</tr>
<tr>
<td class="item-image">
<div class="item-image-container">
<a href="#"></a>
</div>
</td>
<td>Item Name</td>
<td>tsujpdsds</td>
<td>Something Else Here</td>
</tr>
</tbody>
</table>
</div>
</div>
.ticker
{
.ticker-body
{
margin-top: 10px;
border: 1px solid $type25Border;
@include transition( border 0.2s ease-in-out );
&:hover
{
border: 1px solid $greenText;
}
}
}
table#new-listings
{
width: 645px;
color: $whiteText;
thead
{
font-family: "opensans-SB";
font-size: 14px;
th
{
padding-top: 15px;
padding-bottom: 8px;
}
}
th, td
{
text-align: left;
vertical-align: middle;
padding: 5px 10px 5px 10px;
}
tbody
{
tr
{
font-family: "opensans-R";
font-size: 12px;
//border-top: 1px solid $type35Border;
&:nth-child(odd) { background-color: $type60Background; }
&:nth-child(even) { background-color: $type70Background; }
.item-image
{
width: 45px;
height: 32px;
.item-image-container
{
width: 100%;
height: 100%;
background-size: contain;
background-repeat: no-repeat;
background-position: center;
background-image: url( "src/hornmask.png" );
border: 1px solid $type35Border;
box-shadow: $softShadow;
}
}
}
}
}
Subscribe to:
Posts (Atom)