After you make global search and replace operation in Xcode it adds xcLanguageSpecificationIdentifier and lineEnding to every manipulated file entry in *.pbxproj files in the form of e.g.:
036B04CB1B2AE8A70010F649 /* MyClass.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MyClass.m; sourceTree = "<group>"; };
to:
036B04CB1B2AE8A70010F649 /* MyClass.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; path = MyClass.m; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objc; };
What is it for?
Does it improve something like search performance?
If yes, how can I generate it for other files without making search and replace operation?
If no, how can I prevent Xcode from creating such things?
I think xcLanguageSpecificationIdentifier is just a temporary indication from Xcode 6 with Swift's comming; and you can find it in your project.pbxproj if you write mixture code with Swift and objc.
For example, you have ProfileVC.h and ProfileVC.m, then you delete ProfileVC.h and rename ProfileVC.m to ProfileVC.swift (and rewrite it in Swift), in your projectName.xcodeproject/project.pbxproj, some line change from
49E89AB31C3D4494006C95BB /* ProfileVC.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ProfileVC.m; sourceTree = "<group>";};
to
49E89AB31C3D4494006C95BB /* ProfileVC.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = ProfileVC.swift; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objc; };
However, in this situation, code in ProfileVC.swift seems not correctly colored, and code completion is broken. I delete the part xcLanguageSpecificationIdentifier = xcode.lang.objc; and everything goes quite OK.
Related
I am using the vkCmdCopyImageToBuffer function and getting a memory access violation and don't understand why.
Here is the code:
VkBufferImageCopy region = {};
region.bufferOffset = 0;
region.bufferRowLength = width;
region.bufferImageHeight = height;
region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
region.imageSubresource.mipLevel = 0;
region.imageSubresource.baseArrayLayer = 0;
region.imageSubresource.layerCount = 1;
region.imageOffset = { 0, 0, 0 };
region.imageExtent = {
width,
height,
1
};
vkCmdCopyImageToBuffer(m_drawCmdBuffers[i], m_swapChain.buffers[i].image,
VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, m_renderImage, 1, ®ion);
The swapchain images are created here in the initialization code:
// Get the swap chain images
images.resize(imageCount);
VK_CHECK_RESULT(fpGetSwapchainImagesKHR(device, swapChain, &imageCount, images.data()));
// Get the swap chain buffers containing the image and imageview
buffers.resize(imageCount);
for (uint32_t i = 0; i < imageCount; i++)
{
VkImageViewCreateInfo colorAttachmentView = {};
colorAttachmentView.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
colorAttachmentView.pNext = NULL;
colorAttachmentView.format = colorFormat;
colorAttachmentView.components = {
VK_COMPONENT_SWIZZLE_R,
VK_COMPONENT_SWIZZLE_G,
VK_COMPONENT_SWIZZLE_B,
VK_COMPONENT_SWIZZLE_A
};
colorAttachmentView.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
colorAttachmentView.subresourceRange.baseMipLevel = 0;
colorAttachmentView.subresourceRange.levelCount = 1;
colorAttachmentView.subresourceRange.baseArrayLayer = 0;
colorAttachmentView.subresourceRange.layerCount = 1;
colorAttachmentView.viewType = VK_IMAGE_VIEW_TYPE_2D;
colorAttachmentView.flags = 0;
buffers[i].image = images[i];
colorAttachmentView.image = buffers[i].image;
VK_CHECK_RESULT(vkCreateImageView(device, &colorAttachmentView, nullptr, &buffers[i].view));
}
And my buffer is similarly created here:
VkBufferCreateInfo createinfo = {};
createinfo.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
createinfo.size = width * height * 4 * sizeof(int8_t);
createinfo.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT;
createinfo.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
//create the image copy buffer
vkCreateBuffer(m_device, &createinfo, NULL, &m_renderImage);
I have tried different pixel formats and different createinfo.usage settings but none help.
VkSurfaceCapabilitiesKHR::supportedUsageFlags defines the limitations on the ways in which you can use the VkImages created by the swap chain. The only one that is guaranteed to be supported is color attachment; all of the other, including transfer src, are optional.
Therefore, you should not assume that you can copy from a presentable image. If you find yourself with a need to do that, you must first query that value. If it does not allow copies, then you must render to your own image, which you copy from. You can render from that image into the presentable one when you intend to present it.
I am new to XCode and I want to convert file references from another project into files in my project folder. I should've done the copying to folder at the time I did a drag and drop but unfortunately I didn't notice at that time.
I tried removing the references and manually copying the said files into my project folder but that is causing build errors I can't understand. Xcode is unable to recognize the classes in the newly copied files.
When I remove the references to the files I see the following diff being generated in the project.pbxproj file
- 9EA3AE481AFBE3DC006D1736 /* PasscodeLock.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9EA3AE3F1AFBE3DC006D1736 /* PasscodeLock.swift */; };
- 9EA3AE491AFBE3DC006D1736 /* PasscodeLockPresenter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9EA3AE401AFBE3DC006D1736 /* PasscodeLockPresenter.swift */; };
- 9EA3AE4A1AFBE3DC006D1736 /* ChangePasscodeState.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9EA3AE421AFBE3DC006D1736 /* ChangePasscodeState.swift */; };
- 9EA3AE4B1AFBE3DC006D1736 /* ConfirmPasscodeState.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9EA3AE431AFBE3DC006D1736 /* ConfirmPasscodeState.swift */; };
- 9EA3AE4C1AFBE3DC006D1736 /* EnterPasscodeState.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9EA3AE441AFBE3DC006D1736 /* EnterPasscodeState.swift */; };
- 9EA3AE4D1AFBE3DC006D1736 /* PasscodesMismatchState.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9EA3AE451AFBE3DC006D1736 /* PasscodesMismatchState.swift */; };
- 9EA3AE4E1AFBE3DC006D1736 /* SetPasscodeState.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9EA3AE461AFBE3DC006D1736 /* SetPasscodeState.swift */; };
Is there an easy way to convert all these references into files in my project folder?
I was able to individually copy the files and build. The mistake I was making was that I was adding a files to an extra target.
I'm playing around a bit with Core Image, CIFilter and RAW images. If I understand Apple's documentation correctly, to load a RAW image and display it in an image view, some code like this should do the trick:
NSURL *url = [NSURL URLWithString:#"file:///Users/emiel/Desktop/_MG_1087.CR2"];
// NSURL *url = [NSURL URLWithString:#"file:///Users/emiel/Desktop/_DSC0044.NEF"];
CIFilter *filter = [CIFilter filterWithImageURL:url options:nil];
NSLog(#"CIFilter: %#", filter);
CIImage *image = filter.outputImage;
NSCIImageRep *rep = [NSCIImageRep imageRepWithCIImage:image];
NSLog(#"%f - %f", rep.size.width, rep.size.height);
NSImage *nsImage = [[NSImage alloc] initWithSize:CGSizeMake(rep.size.width, rep.size.height)];
[nsImage addRepresentation:rep];
self.imageView.image = nsImage;
This code works fine for the .NEF (Nikon RAW) file, but the CR2 (Canon RAW) file gives me a totally black image. The image dimensions of the black image are correct though. What is going wrong here? Do I need to set some default to a non-default value? Preview/Aperture/iPhoto/etc all work fine with my .CR2 image, so it is possible to read them.
The only difference I can find is that apparently, for the CR2 file a version 6 of the decoder is used, and the NEF file is decoded by version 5. If I set the CR2 to be decoded by version 5 all works, but this seems to be a weird solution since I don't know if there is a version 5 or 6 or whatever for other RAW image formats.
NEF File:
{CIRAWFilterImpl {
inputBias = 3;
inputBoost = 1;
inputBoostShadowAmount = "0.9";
inputColorNoiseReductionAmount = "0.5";
inputDecoderVersion = 5;
inputDraftMode = 0;
inputEV = 0;
inputEnableNoiseTracking = 1;
inputEnableSharpening = 1;
inputEnableVendorLensCorrection = 0;
inputIgnoreOrientation = "<null>";
inputImageOrientation = 1;
inputLinearSpaceFilter = "<null>";
inputLuminanceNoiseReductionAmount = "0.1";
inputNeutralChromaticityX = "0.4212473792917087";
inputNeutralChromaticityY = "0.4060714400950335";
inputNeutralLocation = "[]";
inputNeutralTemperature = "3296.579476861167";
inputNeutralTint = "3.848452212530264";
inputNoiseReductionAmount = "<null>";
inputNoiseReductionContrastAmount = 0;
inputNoiseReductionDetailAmount = 0;
inputNoiseReductionSharpnessAmount = "0.5";
inputScaleFactor = 1;
}}
CR2 File:
{CIRAWFilterImpl {
inputBias = 3;
inputBoost = 1;
inputBoostShadowAmount = "0.9";
inputColorNoiseReductionAmount = "0.5";
inputDecoderVersion = 6;
inputDraftMode = 0;
inputEV = 0;
inputEnableNoiseTracking = 1;
inputEnableSharpening = 1;
inputEnableVendorLensCorrection = 0;
inputIgnoreOrientation = "<null>";
inputImageOrientation = 1;
inputLinearSpaceFilter = "<null>";
inputLuminanceNoiseReductionAmount = 0;
inputNeutralChromaticityX = "0.3575430840790828";
inputNeutralChromaticityY = "0.3599707869545071";
inputNeutralLocation = "[]";
inputNeutralTemperature = "4585.861752390336";
inputNeutralTint = "-11.18923977879745";
inputNoiseReductionAmount = "<null>";
inputNoiseReductionContrastAmount = 0;
inputNoiseReductionDetailAmount = 0;
inputNoiseReductionSharpnessAmount = "0.5";
inputScaleFactor = 1;
}}
Help?
This appears to be a regression in 10.10.2 and/or the latest RAW compatibility update, according to posts in Apple's Devforums. The only known workaround is to manually override inputDecoderVersion to 5.
Please also file a Radar, so that Apple takes notice.
I have this function:
void PickupFileAndSave(std::vector<unsigned char> file_data, int *error_code, char *file_mask = "All files (*.*)\0*.*\0\0")
{
OPENFILENAMEA ofn; // common dialog box structure
char szFile[MAX_PATH]; // buffer for file name
char initial_dir[MAX_PATH] = { 0 };
GetStartupPath(initial_dir);
// Initialize OPENFILENAME
ZeroMemory(&ofn, sizeof(ofn));
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = GetActiveWindow();
ofn.lpstrFile = szFile;
// Set lpstrFile[0] to '\0' so that GetOpenFileName does not
// use the contents of szFile to initialize itself.
ofn.lpstrFile[0] = '\0';
ofn.nMaxFile = sizeof(szFile);
ofn.lpstrFilter = file_mask;
ofn.nFilterIndex = 1;
ofn.lpstrFileTitle = NULL;
ofn.nMaxFileTitle = 0;
ofn.lpstrInitialDir = initial_dir;
ofn.Flags = OFN_PATHMUSTEXIST | OFN_EXPLORER;
if (!GetSaveFileNameA(&ofn))
{
*error_code = GetLastError();
return;
}
char err_msg[1024] = { 0 };
std::string file_name = ofn.lpstrFile; //this stores path to file without extension
file_name.append(".");
file_name.append(ofn.lpstrDefExt); //this is NULL and fails to copy too
WriteAllBytes(file_name.c_str(), &file_data[0], file_data.size(), &err_msg[0]);
if (strlen(err_msg) > 0)
{
*error_code = GetLastError();
return;
}
}
I call it that way:
int write_error = 0;
PickupFileAndSave(compressed, &write_error, "RLE compressed files (*.rle)\0*.rle\0\0");
When I choose file it shows in the filter needed extension, but do not add it to lpstrFile.
Any ideas why and how to fix it?
You did not assign lpstrDefExt so the system will not add the extension in case you omit it. So you simply need to initialise the field before you show the dialog:
lpstrDefExt = "rle";
The documentation explains this:
lpstrDefExt
The default extension. GetOpenFileName and GetSaveFileName append this extension to the file name if the user fails to type an extension. This string can be any length, but only the first three characters are appended. The string should not contain a period (.). If this member is NULL and the user fails to type an extension, no extension is appended.
It's not clear from the code in the question but you want to handle the case where there are multiple filters and you wish to append the extension of the selected filter.
The system won't do that for you so you will have to. Read nFilterIndex after you have shown the dialog. That tells you which filter the user selected. Then parse the filter string to obtain the chosen extension, and append it to the filename if it has no extension.
I'm using D3DXSaveSurfaceToFile to save windowed Direct3D 9 surfaces to PNG, BMP and JPG files. There are no errors returned from the D3DXSaveSurfaceToFile call and all files open fine in Windows Photo Viewer and Paint. But they will not open in a higher end image editing program such as Paint Shop Pro or Photoshop. The error messages from these programs basically say that the file is corrupted. If I open the files in Paint and then save them in the same file format with a different file name, then they'll open fine in the other programs.
This leads me to believe that D3DXSaveSurfaceToFile is writing out non-standard versions of these file formats. Is there some way I can get this function to write out files that can be opened in programs like Photoshop without the intermediate step of resaving the files in Paint? Or is there another function I should be using that does a better job of saving a Direct3D surfaces to an image?
Take a look at the file in a image meta viewer. What does it tell you?
Unfortunately D3DXSaveSurfaceToFile() isn't the most stable (it's also exceptionally slow). Personally I do something like the below code. It works even on Anti-aliased displays by doing an offscreen render to take the screenshot then getting it into a buffer. It also supports only the most common of the pixel formats. Sorry for any errors in it, pulled it out of an app I used to work on.
You can then, in your code and probably in another thread, then convert said 'bitmap' to anything you like using a variety of different code.
void HandleScreenshot(IDirect3DDevice9* device)
{
DWORD tcHandleScreenshot = GetTickCount();
LPDIRECT3DSURFACE9 pd3dsBack = NULL;
LPDIRECT3DSURFACE9 pd3dsTemp = NULL;
// Grab the back buffer into a surface
if ( SUCCEEDED ( device->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &pd3dsBack) ))
{
D3DSURFACE_DESC desc;
pd3dsBack->GetDesc(&desc);
LPDIRECT3DSURFACE9 pd3dsCopy = NULL;
if (desc.MultiSampleType != D3DMULTISAMPLE_NONE)
{
if (SUCCEEDED(device->CreateRenderTarget(desc.Width, desc.Height, desc.Format, D3DMULTISAMPLE_NONE, 0, FALSE, &pd3dsCopy, NULL)))
{
if (SUCCEEDED(device->StretchRect(pd3dsBack, NULL, pd3dsCopy, NULL, D3DTEXF_NONE)))
{
pd3dsBack->Release();
pd3dsBack = pd3dsCopy;
}
else
{
pd3dsCopy->Release();
}
}
}
if (SUCCEEDED(device->CreateOffscreenPlainSurface(desc.Width, desc.Height, desc.Format, D3DPOOL_SYSTEMMEM, &pd3dsTemp, NULL)))
{
DWORD tmpTimeGRTD = GetTickCount();
if (SUCCEEDED(device->GetRenderTargetData(pd3dsBack, pd3dsTemp)))
{
D3DLOCKED_RECT lockedSrcRect;
if (SUCCEEDED(pd3dsTemp->LockRect(&lockedSrcRect, NULL, D3DLOCK_READONLY | D3DLOCK_NOSYSLOCK | D3DLOCK_NO_DIRTY_UPDATE)))
{
int nSize = desc.Width * desc.Height * 3;
BYTE* pixels = new BYTE[nSize +1];
int iSrcPitch = lockedSrcRect.Pitch;
BYTE* pSrcRow = (BYTE*)lockedSrcRect.pBits;
LPBYTE lpDest = pixels;
LPDWORD lpSrc;
switch (desc.Format)
{
case D3DFMT_A8R8G8B8:
case D3DFMT_X8R8G8B8:
for (int y = desc.Height - 1; y >= 0; y--)
{
lpSrc = reinterpret_cast<LPDWORD>(lockedSrcRect.pBits) + y * desc.Width;
for (unsigned int x = 0; x < desc.Width; x++)
{
*reinterpret_cast<LPDWORD>(lpDest) = *lpSrc;
lpSrc++; // increment source pointer by 1 DWORD
lpDest += 3; // increment destination pointer by 3 bytes
}
}
break;
default:
ZeroMemory(pixels, nSize);
}
pd3dsTemp->UnlockRect();
BITMAPINFOHEADER header;
header.biWidth = desc.Width;
header.biHeight = desc.Height;
header.biSizeImage = nSize;
header.biSize = sizeof(BITMAPINFOHEADER);
header.biPlanes = 1;
header.biBitCount = 3 * 8; // RGB
header.biCompression = 0;
header.biXPelsPerMeter = 0;
header.biYPelsPerMeter = 0;
header.biClrUsed = 0;
header.biClrImportant = 0;
BITMAPFILEHEADER bfh = {0};
bfh.bfType = 0x4d42;
bfh.bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);
bfh.bfSize = bfh.bfOffBits + nSize;
unsigned int rough_size = sizeof(BITMAPINFOHEADER) + sizeof(BITMAPFILEHEADER) + nSize;
unsigned char* p = new unsigned char[rough_size]
memcpy(p, &bfh, sizeof(BITMAPFILEHEADER));
p += sizeof(BITMAPFILEHEADER);
memcpy(p, &header, sizeof(BITMAPINFOHEADER));
p += sizeof(BITMAPINFOHEADER);
memcpy(p, pixels, nSize);
delete [] pixels;
/**********************************************/
// p now has a full BMP file, write it out here
}
}
pd3dsTemp->Release();
}
pd3dsBack->Release();
}
}
Turns out that it was a combination of a bug in my code and Paint being more forgiving than Photoshop when it comes to reading files. The bug in my code caused the files to be saved with the wrong extension (i.e. Image.bmp was actually saved using D3DXIFF_JPG). When opening a file that contained a JPG image, but had a BMP extension, Photoshop just failed the file. I guess Paint worked since it ignored the file extension and just decoded the file contents.
Looking at a file in an image meta viewer helped me to see the problem.